From: Ondrej Lichtner <olichtne(a)redhat.com>
Instead of just adding the list of hosts to be accessed from the recipe
we add the controller so that we can also call some generic methods,
e.g. waiting for a condition.
This also changes the .matched attribute to a property that accesses the
appropriate attribute of the Controller object.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Controller.py | 4 ++--
lnst/Controller/Recipe.py | 16 +++++++++++++---
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/lnst/Controller/Controller.py b/lnst/Controller/Controller.py
index 13e7fd8..3415f63 100644
--- a/lnst/Controller/Controller.py
+++ b/lnst/Controller/Controller.py
@@ -104,6 +104,8 @@ class Controller(object):
if not isinstance(recipe, BaseRecipe):
raise ControllerError("recipe argument must be a BaseRecipe
instance.")
+ recipe._set_ctl(self)
+
req = recipe.req
self._mapper.set_pools(self._pools.get_pools())
@@ -118,14 +120,12 @@ class Controller(object):
self._print_match_description(match)
try:
self._map_match(match, req)
- recipe._set_hosts(self._hosts)
recipe.test()
except Exception as exc:
logging.error("Recipe execution terminated by unexpected
exception")
log_exc_traceback()
raise
finally:
- recipe._set_hosts(None)
self._cleanup_slaves()
def _map_match(self, match, requested):
diff --git a/lnst/Controller/Recipe.py b/lnst/Controller/Recipe.py
index 39917b3..9380a35 100644
--- a/lnst/Controller/Recipe.py
+++ b/lnst/Controller/Recipe.py
@@ -80,7 +80,7 @@ class BaseRecipe(object):
Next, the copied objects are loaded with values from kwargs
and checked if mandatory Parameters have values.
"""
- self.matched = None
+ self._ctl = None
self.req = _Requirements()
self.params = Parameters()
for attr in dir(self):
@@ -105,8 +105,18 @@ class BaseRecipe(object):
for key in kwargs.keys():
raise RecipeError("Unknown parameter {}".format(key))
- def _set_hosts(self, hosts):
- self.matched = hosts
+ @property
+ def ctl(self):
+ return self._ctl
+
+ @property
+ def matched(self):
+ if self.ctl is None:
+ return None
+ return self.ctl._hosts
+
+ def _set_ctl(self, ctl):
+ self._ctl = ctl
def test(self):
"""Method to be implemented by the Tester"""
--
2.15.1