Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.core
Commits
ed597075
Commit
ed597075
authored
Feb 09, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve defaultTest method
parent
63a9e08a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
12 deletions
+30
-12
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+30
-12
No files found.
slapos/grid/promise/__init__.py
View file @
ed597075
...
...
@@ -286,30 +286,44 @@ class GenericPromise(object):
line_list.reverse()
return line_list
def defaultTest(self, latest_minute=3):
def defaultTest(self, latest_minute=3, failure_amount=2, exact_match=False,
is_anomaly=False):
"""
Fail if the latest 2 messages has failed.
If only there is only one result, fail if that result has error
Fail if the latest `failure_amount` messages contain failure.
@param latest_minute: test the result from now to the latest X minutes in
the past.
@param failure_amount: fail is this amount of failure is found in result
@param exact_match: bool (True|False). If True, only fail if the number
of failure found is equal to `failure_amount`. Else, fail if at least
one failure was found.
@param is_anomaly: Say if the result is an AnomalyResult of TestResult
"""
problem = False
message = ""
module = TestResult if not is_anomaly else AnomalyResult
latest_result_list = self.getLastPromiseResultList(
latest_minute=latest_minute,
only_failure=False
)
result_size = len(latest_result_list)
if result_size == 0:
return
TestResult
(problem=False, message="
No
result
!
")
return
module
(problem=False, message="
No
result
!
")
i = 0
failure_found = 0
latest_result_list.reverse()
# we test at most the
2
latest results
while i < result_size and i <
2
:
# we test at most the
`failure_amount`
latest results
while i < result_size and i <
failure_amount
:
if latest_result_list[i][1] == 'ERROR':
failure_found += 1
problem = True
i += 1
return TestResult(problem=problem, message=latest_result_list[0][2])
if exact_match and failure_found != failure_amount:
return module(problem=False, message=latest_result_list[0][2])
return module(problem=problem, message=latest_result_list[0][2])
@abstractmethod
def sense(self):
...
...
@@ -317,9 +331,11 @@ class GenericPromise(object):
def anomaly(self):
"""Called to detect if there is an anomaly which require to bang."""
raise NotImplementedError("'anomaly'
method
is
not
implemented
yet
!
")
def test(self):
"""Test promise and say if problem is detected or not"""
raise NotImplementedError("'test'
method
is
not
implemented
yet
!
")
def run(self, can_bang=True):
"""
...
...
@@ -395,7 +411,7 @@ class PromiseWrapper(GenericPromise):
self.logger.info(message.strip())
def test(self):
return self.defaultTest(latest_minute=3)
return self.defaultTest(latest_minute=3
, failure_amount=2, is_anomaly=False
)
class PromiseRunner(Process):
...
...
@@ -531,9 +547,10 @@ class PromiseLauncher(object):
if re.match(r'[a-zA-Z_]', promise_name) is None:
self.logger.error("
Promise
plugin
name
%
r
is
not
valid
" % promise_name)
promise_module = importlib.import_module(
promise_name
)
promise_module = importlib.import_module(
os.path.splitext(promise_name)[0]
)
if not hasattr(promise_module, "
RunPromise
"):
raise AttributeError("
Class
RunPromise
not
found
in
%
s
" % promise_name)
raise AttributeError("
Class
RunPromise
not
found
in
promise
"
\
"
%
s
" % promise_name)
if not interface.IPromise.implementedBy(promise_module.RunPromise):
raise RuntimeError("
RunPromise
class
in
%
s
must
implements
'IPromise'"
\
"
interface
.
zope_interface
.
implements
(
interface
.
IPromise
)
is
"
\
...
...
@@ -690,7 +707,8 @@ class PromiseLauncher(object):
promise_list = []
# load all promises so we can catch import errors before launch them
for promise_name in os.listdir(self.promise_dir):
if promise_name.startswith('__init__'):
if promise_name.startswith('__init__') or
\
not promise_name.endswith('.py'):
continue
promise_list.append((promise_name,
self._loadPromiseModule(promise_name)))
...
...
@@ -701,7 +719,7 @@ class PromiseLauncher(object):
'name': promise[0]
}
config.update(base_config)
self._launchPromise(promise_name, config, promise)
self._launchPromise(promise_name, config, promise
[1]
)
if os.path.exists(self.old_promise_dir) and os.path.isdir(self.old_promise_dir):
# run old promise styles
...
...
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