From: Ondrej Lichtner <olichtne(a)redhat.com>
When a recipe is succesfully matched and the Controller starts setting
up the Machine objects we should pass the Recipe instance. This is
important since the Machine object needs to be able to generate
JobResult objects.
Another minor improvement is that a correct recipe name will be used
(the name of the Recipe class) instead of the filename of the currently
running executable which was incorrectly used until now.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Controller.py | 11 +++++------
lnst/Controller/Machine.py | 6 +++++-
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/lnst/Controller/Controller.py b/lnst/Controller/Controller.py
index d044870..f306319 100644
--- a/lnst/Controller/Controller.py
+++ b/lnst/Controller/Controller.py
@@ -122,7 +122,7 @@ class Controller(object):
for line in format_match_description(match).split('\n'):
logging.info(line)
try:
- self._map_match(match, req)
+ self._map_match(match, req, recipe)
recipe._init_run(RecipeRun(match))
recipe.test()
except Exception as exc:
@@ -143,7 +143,7 @@ class Controller(object):
self._msg_dispatcher.wait_for_condition(condition)
- def _map_match(self, match, requested):
+ def _map_match(self, match, requested, recipe):
self._machines = {}
self._hosts = Hosts()
pool = self._pools.get_machine_pool(match["pool_name"])
@@ -154,7 +154,7 @@ class Controller(object):
host = getattr(self._hosts, m_id)
machine.set_id(m_id)
- self._prepare_machine(machine)
+ self._prepare_machine(machine, recipe)
for if_id, i in m["interfaces"].items():
host._map_device(if_id, i)
@@ -168,13 +168,12 @@ class Controller(object):
setattr(host, name, new_virt_dev)
new_virt_dev._enable()
- def _prepare_machine(self, machine):
+ def _prepare_machine(self, machine, recipe):
self._log_ctl.add_slave(machine.get_id())
machine.set_mac_pool(self._mac_pool)
machine.set_network_bridges(self._network_bridges)
- recipe_name = os.path.basename(sys.argv[0])
- machine.set_recipe(recipe_name)
+ machine.set_recipe(recipe)
def _cleanup_slaves(self):
if self._machines == None:
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index cd14f78..b429721 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -70,6 +70,8 @@ class Machine(object):
self._port = ctl_config.get_option('environment', 'rpcport')
self._msg_dispatcher = msg_dispatcher
+
+ self._recipe = None
self._mac_pool = None
self._interfaces = []
@@ -231,12 +233,14 @@ class Machine(object):
self._slave_desc = slave_desc
- def set_recipe(self, recipe_name):
+ def set_recipe(self, recipe):
""" Reserves the machine for the specified recipe
Also sends Device classes from the controller and initializes the
InterfaceManager on the Slave and builds the device database.
"""
+ self._recipe = recipe
+ recipe_name = recipe.__class__.__name__
self.rpc_call("set_recipe", recipe_name)
self._send_device_classes()
self.rpc_call("init_if_manager")
--
2.16.1