Commit d75813e0 authored by Alain Takoudjou's avatar Alain Takoudjou

grid.promise: send EmptyResult if promise is test less or anomaly less

There is now `EmptyResult` object which is an empty promise result. This result is send if the promise test or anomaly was skiped (if disabled).
To prevent raise because `EmptyResult` is unknonwn on old slapos-node with `slapos.core < 1.4.17` we will send an empty TestResult instead.
parent 3a9b84c1
...@@ -49,6 +49,7 @@ from slapos.grid.promise.generic import (GenericPromise, PromiseQueueResult, ...@@ -49,6 +49,7 @@ from slapos.grid.promise.generic import (GenericPromise, PromiseQueueResult,
PROMISE_PARAMETER_NAME, PROMISE_PARAMETER_NAME,
PROMISE_PERIOD_FILE_NAME) PROMISE_PERIOD_FILE_NAME)
from slapos.grid.promise.wrapper import WrapPromise from slapos.grid.promise.wrapper import WrapPromise
from slapos.version import version
class PromiseError(Exception): class PromiseError(Exception):
pass pass
...@@ -492,7 +493,7 @@ class PromiseLauncher(object): ...@@ -492,7 +493,7 @@ class PromiseLauncher(object):
message="Error: No output returned by the promise", message="Error: No output returned by the promise",
execution_time=execution_time execution_time=execution_time
) )
elif queue_item.item is None: elif queue_item.item.type() == "Empty Result":
# no result collected (sense skipped) # no result collected (sense skipped)
skipped_method = "Anomaly" if self.check_anomaly else "Test" skipped_method = "Anomaly" if self.check_anomaly else "Test"
self.logger.debug("Skipped, %s is disabled in promise %r." % ( self.logger.debug("Skipped, %s is disabled in promise %r." % (
...@@ -530,6 +531,7 @@ class PromiseLauncher(object): ...@@ -530,6 +531,7 @@ class PromiseLauncher(object):
'partition-id': self.partition_id, 'partition-id': self.partition_id,
'computer-id': self.computer_id, 'computer-id': self.computer_id,
'queue': self.queue_result, 'queue': self.queue_result,
'slapgrid-version': version,
} }
if os.path.exists(self.promise_folder) and os.path.isdir(self.promise_folder): if os.path.exists(self.promise_folder) and os.path.isdir(self.promise_folder):
......
...@@ -92,6 +92,15 @@ class AnomalyResult(BaseResult): ...@@ -92,6 +92,15 @@ class AnomalyResult(BaseResult):
def type(): def type():
return "Anomaly Result" return "Anomaly Result"
class EmptyResult(BaseResult):
def __init__(self):
BaseResult.__init__(self, False, None, None)
@staticmethod
def type():
return "Empty Result"
class PromiseQueueResult(object): class PromiseQueueResult(object):
def __init__(self, path=None, name=None, title=None, def __init__(self, path=None, name=None, title=None,
...@@ -101,6 +110,9 @@ class PromiseQueueResult(object): ...@@ -101,6 +110,9 @@ class PromiseQueueResult(object):
self.item = item self.item = item
self.title = title self.title = title
self.execution_time = execution_time self.execution_time = execution_time
if self.item is None:
# if no result set, then set EmptyResult
self.item = EmptyResult()
def serialize(self): def serialize(self):
return { return {
...@@ -245,7 +257,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -245,7 +257,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
""" """
self.__is_anomaly_detected = False self.__is_anomaly_detected = False
def isAnomalyLess(self): def isAnomalyDetected(self):
return self.__is_anomaly_detected return self.__is_anomaly_detected
def __bang(self, message): def __bang(self, message):
...@@ -487,6 +499,10 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -487,6 +499,10 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
elif (not self.__is_tested and not check_anomaly) or \ elif (not self.__is_tested and not check_anomaly) or \
(not self.__is_anomaly_detected and check_anomaly): (not self.__is_anomaly_detected and check_anomaly):
# Anomaly or Test is disabled on this promise, send empty result # Anomaly or Test is disabled on this promise, send empty result
if self.getConfig('slapgrid-version', '') <= '1.4.17':
# old version cannot send EmptyResult
self.__sendResult(PromiseQueueResult(item=TestResult()))
else:
self.__sendResult(PromiseQueueResult()) self.__sendResult(PromiseQueueResult())
else: else:
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment