Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin
chksrv
Commits
b84e9c56
Commit
b84e9c56
authored
Oct 29, 2018
by
Martin
Browse files
fixed bugs regarding retry and timeout
parent
da8a0f21
Changes
2
Hide whitespace changes
Inline
Side-by-side
chksrv/cli.py
View file @
b84e9c56
...
...
@@ -177,7 +177,7 @@ def run():
log
.
error
(
f
"Not implemented check type
{
chk_type
}
"
)
sys
.
exit
(
2
)
runner
=
CheckRunner
(
chk
,
args
[
'--expects'
],
options
)
runner
=
CheckRunner
(
chk
,
args
[
'--expects'
],
options
,
args
[
'--retry'
],
args
[
'--timeout'
]
)
runner
.
run
()
if
runner
and
runner
.
results
:
...
...
chksrv/runner.py
View file @
b84e9c56
...
...
@@ -37,12 +37,13 @@ class CheckRunner(object):
log
=
logging
.
getLogger
(
'RUNNER'
)
def
__init__
(
self
,
check
:
BaseCheck
,
expects
:
typing
.
List
[
str
],
options
:
typing
.
Dict
[
str
,
typing
.
Any
],
repeats
:
int
=
1
,
timeout
:
int
=
None
):
def
__init__
(
self
,
check
:
BaseCheck
,
expects
:
typing
.
List
[
str
],
options
:
typing
.
Dict
[
str
,
typing
.
Any
],
retries
:
int
=
1
,
timeout
:
int
=
None
):
self
.
_expects
=
None
# property
self
.
check
=
check
self
.
expects
=
expects
self
.
options
=
options
self
.
re
peat
s
=
m
in
(
1
,
repeat
s
)
self
.
timeout
=
m
in
(
0
,
timeout
)
if
timeout
else
None
self
.
re
trie
s
=
m
ax
(
1
,
int
(
retrie
s
)
)
self
.
timeout
=
m
ax
(
0
,
int
(
timeout
)
)
if
timeout
else
None
self
.
_compiled_expects
=
None
self
.
expect_results
=
None
...
...
@@ -53,12 +54,21 @@ class CheckRunner(object):
def
results
(
self
)
->
typing
.
Dict
[
str
,
typing
.
Any
]:
return
self
.
check
.
results
@
property
def
expects
(
self
)
->
typing
.
List
[
str
]:
return
self
.
_expects
if
hasattr
(
self
,
'_expects'
)
else
None
@
expects
.
setter
def
expects
(
self
,
expects
):
self
.
_expects
=
expects
def
run
(
self
):
self
.
compile
()
self
.
expect_success
=
self
.
success
=
False
for
attempt
in
range
(
self
.
repeats
):
for
attempt
in
range
(
1
,
self
.
retries
+
1
):
self
.
log
.
info
(
f
"Attempt
{
attempt
}
/
{
self
.
retries
}
"
)
self
.
run_check
()
self
.
evaluate_expects
()
...
...
@@ -68,14 +78,19 @@ class CheckRunner(object):
if
self
.
success
:
break
self
.
log
.
warn
(
f
"Attempt
{
attempt
}
failed."
,
"Retrying..."
if
attempt
<
self
.
re
peat
s
else
"Stop
retrying
."
)
self
.
log
.
warn
(
' '
.
join
([
f
"Attempt
{
attempt
}
failed."
,
"Retrying..."
if
attempt
<
self
.
re
trie
s
else
"Stop."
])
)
return
self
.
success
def
compile
(
self
):
"""compiles the expect handlers."""
if
self
.
_compiled_expects
or
not
self
.
expects
:
if
not
self
.
expects
:
# no expects available
self
.
_compiled_expects
=
[]
return
if
self
.
_compiled_expects
:
# expects already compiled or no expects available
return
...
...
@@ -97,8 +112,8 @@ class CheckRunner(object):
try
:
self
.
check
.
run
()
except
exceptions
.
ChksrvTimeoutError
:
self
.
log
.
error
(
"Check timed out."
,
exc_info
=
False
)
self
.
check
.
results
[
'results'
]
=
False
#
required for later signalling
self
.
log
.
error
(
f
"Check timed out
after
{
self
.
timeout
}
seconds
."
,
exc_info
=
False
)
self
.
check
.
results
[
'results'
]
=
False
#
set check fail state
finally
:
if
self
.
timeout
:
signal
.
alarm
(
0
)
...
...
@@ -106,7 +121,7 @@ class CheckRunner(object):
def
evaluate_expects
(
self
):
if
not
self
.
results
:
self
.
log
.
error
(
"There are no
t
results from the check. Did it run?"
)
self
.
log
.
error
(
"There are no results from the check. Did it run?"
)
raise
exceptions
.
ChksrvNotReadyError
(
"There are not results from the check."
)
if
not
self
.
_compiled_expects
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment