[lnst] lnst-ctl: Adding match_setup action

Jiří Pírko jirka at fedoraproject.org
Sat May 4 17:01:35 UTC 2013


commit c9d4256ebdee45f60b9f63361f3e4bb074a6d940
Author: Radek Pazdera <rpazdera at redhat.com>
Date:   Sat May 4 00:00:15 2013 +0200

    lnst-ctl: Adding match_setup action
    
    This commit adds a new action called 'match_setup'. With this action,
    the controller will only read the pool and try to match the recipe
    setup to the pool. In case the match was successfull, it will print
    the details of the match.
    
    I didn't really pay that much attention to the format of the report.
    That might change in the future. The important thing here are the
    backend options for this functionality.

 lnst-ctl                             |    2 +-
 lnst/Controller/NetTestController.py |   26 ++++++++++++++++++++++++++
 lnst/Controller/RecipeParse.py       |   10 ++++++----
 3 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/lnst-ctl b/lnst-ctl
index de74c65..68e9bec 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -28,7 +28,7 @@ def usage():
     """
     print "Usage: %s [OPTION...] [RECIPE...] ACTION" % sys.argv[0]
     print ""
-    print "ACTION = [run | dump | config_only]"
+    print "ACTION = [run | dump | config_only | match_setup]"
     print ""
     print "OPTIONS"
     print "  -d, --debug                     emit debugging messages"
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index c446119..9f1c9fa 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -228,6 +228,32 @@ class NetTestController:
         self._cleanup_slaves()
         return True
 
+    def match_setup(self):
+        try:
+            self._parser.first_pass()
+        except Exception as exc:
+            logging.error("Exception raised during recipe parsing. "\
+                          "Deconfiguring machines.")
+            self._cleanup_slaves()
+            raise
+
+        machines = self._recipe["machines"]
+        if len(machines) <= 0:
+            return
+
+        sp = self._slave_pool
+        machines = sp.provision_machines(machines)
+        if machines == None:
+            msg = "This setup cannot be provisioned with the current pool."
+            raise NetTestError(msg)
+
+        logging.info("Provisioning initialized")
+        for m_id in machines.keys():
+            provisioner = sp.get_provisioner_id(m_id)
+            logging.info("  machine %s matched to %s" % (m_id, provisioner))
+
+        return True
+
     def config_only_recipe(self):
         self._prepare()
         self._cleanup_slaves(deconfigure=False)
diff --git a/lnst/Controller/RecipeParse.py b/lnst/Controller/RecipeParse.py
index 8445a0e..9a91a7c 100644
--- a/lnst/Controller/RecipeParse.py
+++ b/lnst/Controller/RecipeParse.py
@@ -28,18 +28,20 @@ class RecipeParse(LnstParser):
         self._rp = RecipePath(None, self._filepath)
         self._include_root = self._rp.get_root()
 
-    def parse_recipe(self):
+    def first_pass(self):
         dom_init = XmlDomTreeInit()
         rp = self._rp
-        xml_dom = dom_init.parse_string(rp.to_str(), rp.abs_path())
+        self._xml_dom = dom_init.parse_string(rp.to_str(), rp.abs_path())
 
         first_pass = FirstPass(self)
-        first_pass.parse(xml_dom)
+        first_pass.parse(self._xml_dom)
 
+    def parse_recipe(self):
+        self.first_pass()
         self._trigger_event("provisioning_requirements_ready", {})
 
         second_pass = SecondPass(self)
-        second_pass.parse(xml_dom)
+        second_pass.parse(self._xml_dom)
 
 
 class FirstPass(LnstParser):


More information about the LNST-developers mailing list