From: Ondrej Lichtner <olichtne(a)redhat.com>
Instances of the RecipeRun class represent a single test run of a
recipe. They store information about Results (executed Jobs or tester
defined) and about the matchine match that was used.
A recipe instance stores a list of these RecipeRun objects and all of
them can be accessed after testing for optional post-processing.
The Recipe class now also has an interface method for the tester which
can be used to add Result objects to the current run, this is intended
to be used from within the tester defined "test" method.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Controller.py | 3 ++-
lnst/Controller/Recipe.py | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/Controller.py b/lnst/Controller/Controller.py
index 9a5d2dd..d044870 100644
--- a/lnst/Controller/Controller.py
+++ b/lnst/Controller/Controller.py
@@ -29,7 +29,7 @@ from lnst.Controller.SlavePoolManager import SlavePoolManager
from lnst.Controller.MachineMapper import MachineMapper
from lnst.Controller.MachineMapper import format_match_description
from lnst.Controller.Host import Hosts, Host
-from lnst.Controller.Recipe import BaseRecipe
+from lnst.Controller.Recipe import BaseRecipe, RecipeRun
class Controller(object):
"""The LNST Controller class
@@ -123,6 +123,7 @@ class Controller(object):
logging.info(line)
try:
self._map_match(match, req)
+ recipe._init_run(RecipeRun(match))
recipe.test()
except Exception as exc:
logging.error("Recipe execution terminated by unexpected
exception")
diff --git a/lnst/Controller/Recipe.py b/lnst/Controller/Recipe.py
index 9380a35..a10f081 100644
--- a/lnst/Controller/Recipe.py
+++ b/lnst/Controller/Recipe.py
@@ -14,6 +14,7 @@ import copy
from lnst.Common.Parameters import Parameters, Param
from lnst.Controller.Requirements import _Requirements, HostReq
from lnst.Controller.Common import ControllerError
+from lnst.Controller.RecipeResults import BaseResult, Result
class RecipeError(ControllerError):
"""Exception thrown by the BaseRecipe class"""
@@ -81,6 +82,7 @@ class BaseRecipe(object):
and checked if mandatory Parameters have values.
"""
self._ctl = None
+ self.runs = []
self.req = _Requirements()
self.params = Parameters()
for attr in dir(self):
@@ -121,3 +123,40 @@ class BaseRecipe(object):
def test(self):
"""Method to be implemented by the Tester"""
raise NotImplementedError("Method test must be defined by a child
class.")
+
+ def _init_run(self, run):
+ self.runs.append(run)
+
+ @property
+ def current_run(self):
+ if len(self.runs) > 0:
+ return self.runs[-1]
+ else:
+ return None
+
+ def add_result(self, success, description="", data=None):
+ self.current_run.add_result(Result(success, description, data))
+
+class RecipeRun(object):
+ def __init__(self, match, desc=None):
+ self._match = match
+ self._desc = desc
+ self._results = []
+
+ def add_result(self, result):
+ if not isinstance(result, BaseResult):
+ raise RecipeError("result must be a BaseActionResult instance.")
+
+ self._results.append(result)
+
+ @property
+ def match(self):
+ return self._match
+
+ @property
+ def description(self):
+ return self._desc
+
+ @property
+ def results(self):
+ return self._results
--
2.16.1