[lnst] lnst-ctl: Adding disable_pool_checks option

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


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

    lnst-ctl: Adding disable_pool_checks option
    
    This commit adds a new option to the controller. Using this option will
    disable the checks that are performed by LNST during startup on pool
    machines.
    
    Option:
    
        -o
        --disable-pool-checks
    
    Some minor cleanup has been done on a few places nearby.

 lnst-ctl                             |   29 ++++++++++++-------
 lnst/Controller/NetTestController.py |    4 +-
 lnst/Controller/SlavePool.py         |   50 +++++++++++++++++++---------------
 3 files changed, 48 insertions(+), 35 deletions(-)
---
diff --git a/lnst-ctl b/lnst-ctl
index 26b15e1..de74c65 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -36,21 +36,26 @@ def usage():
           "                                  network communication during\n" \
           "                                  the test"
     print "  -h, --help                      print this message"
+    print "  -o, --disable-pool-checks       don't check the availability of\n"\
+          "                                  machines in the pool"
     print "  -c, --cleanup                   perform config cleanup\n" \
           "                                  machines"
     print "  -x, --result=FILE               file to write xml_result"
     sys.exit()
 
 def process_recipe(action, file_path, cleanup, res_serializer,
-                   packet_capture, config, log_ctl):
+                   packet_capture, config, log_ctl, pool_checks):
     nettestctl = NetTestController(file_path, log_ctl, cleanup=cleanup,
-                                   res_serializer=res_serializer, config=config)
+                                   res_serializer=res_serializer,
+                                   config=config, pool_checks=pool_checks)
     if action == "run":
         return nettestctl.run_recipe(packet_capture)
     elif action == "dump":
         return nettestctl.dump_recipe()
     elif action == "config_only":
         return nettestctl.config_only_recipe()
+    elif action == "match_setup":
+        return nettestctl.match_setup()
     else:
         logging.error("Unknown action \"%s\"" % action)
         usage();
@@ -65,15 +70,15 @@ def print_summary(summary):
         logging.info("*%s* %s" % (res, recipe_file))
     logging.info("=====================================================")
 
-def get_recipe_result(args, file_path, cleanup,
-                      res_serializer, packet_capture, config, log_ctl):
+def get_recipe_result(args, file_path, cleanup, res_serializer, packet_capture,
+                      config, log_ctl, pool_checks):
     res_serializer.add_recipe(file_path)
     log_ctl.set_recipe(file_path)
 
     res = None
     try:
         res = process_recipe(args, file_path, cleanup, res_serializer,
-                             packet_capture, config, log_ctl)
+                             packet_capture, config, log_ctl, pool_checks)
     except Exception as err:
         log_exc_traceback()
         logging.error(err)
@@ -87,9 +92,9 @@ def main():
     try:
         opts, args = getopt.getopt(
             sys.argv[1:],
-            "dhr:cx:p",
+            "dhr:cx:po",
             ["debug", "help", "recipe=", "cleanup", "result=",
-             "packet_capture"]
+             "packet_capture", "disable-pool-checks"]
         )
     except getopt.GetoptError as err:
         print str(err)
@@ -113,12 +118,12 @@ def main():
         with open(usr_cfg, 'w') as f:
             f.write(config.dump_config())
 
-
     debug = 0
     recipe_path = None
     cleanup = False
     result_path = None
     packet_capture = False
+    pool_checks = True
     for opt, arg in opts:
         if opt in ("-d", "--debug"):
             debug += 1
@@ -130,7 +135,8 @@ def main():
             result_path = arg
         elif opt in ("-p", "--packet_capture"):
             packet_capture = True
-
+        elif opt in ("-o", "--disable-pool-checks"):
+            pool_checks = False
 
     date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
     log_ctl = LoggingCtl(debug,
@@ -162,12 +168,13 @@ def main():
                                                      cleanup,
                                                      res_serializer,
                                                      packet_capture,
-                                                     config, log_ctl))
+                                                     config, log_ctl,
+                                                     pool_checks))
         else:
             summary.append(get_recipe_result(action, recipe_path,
                                              cleanup, res_serializer,
                                              packet_capture,
-                                             config, log_ctl))
+                                             config, log_ctl, pool_checks))
 
     log_ctl.set_recipe("", clean=False)
 
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 169f0af..c446119 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -41,7 +41,7 @@ def ignore_event(**kwarg):
 
 class NetTestController:
     def __init__(self, recipe_path, log_ctl, cleanup=False,
-                 res_serializer=None, config=None):
+                 res_serializer=None, config=None, pool_checks=True):
         self._docleanup = cleanup
         self._res_serializer = res_serializer
         self._remote_capture_files = {}
@@ -51,7 +51,7 @@ class NetTestController:
         self._msg_dispatcher = MessageDispatcher(log_ctl)
 
         sp = SlavePool(config.get_option('environment', 'pool_dirs'),
-                       check_process_running("libvirtd"), config)
+                       check_process_running("libvirtd"), config, pool_checks)
         self._slave_pool = sp
 
         self._machines = {}
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index 80a357c..b875d59 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -35,11 +35,14 @@ class SlavePool:
     _machine_matches = []
     _network_matches = []
 
-    _allow_virtual = False
+    _allow_virt = False
+    _pool_checks = True
 
-    def __init__(self, pool_dirs, allow_virtual=False, config=None):
+    def __init__(self, pool_dirs, allow_virtual=False, config=None,
+                 pool_checks=True):
         self._config = config
-        self._allow_virtual = allow_virtual
+        self._allow_virt = allow_virtual
+        self._pool_checks = pool_checks
         for pool_dir in pool_dirs:
             self.add_dir(pool_dir)
 
@@ -61,30 +64,33 @@ class SlavePool:
             parser.disable_events()
 
             machine = {"params": {}, "interfaces": {}}
-            machine_id = re.sub("\.[xX][mM][lL]$", "", basename)
-            parser.set_machine(machine_id, machine)
+            m_id = re.sub("\.[xX][mM][lL]$", "", basename)
+            parser.set_machine(m_id, machine)
 
             slavemachine = dom.getElementsByTagName("slavemachine")[0]
 
             parser.parse(slavemachine)
 
-            hostname = machine["params"]["hostname"]
-            if "rpcport" in machine:
-                port = machine["params"]["rpcport"]
-            else:
-                port = self._config.get_option('environment', 'rpcport')
-            logging.info("Querying slave machine %s." % machine_id)
-            if not test_tcp_connection(hostname, port):
-                return
-
-            if 'libvirt_domain' not in machine['params'] \
-                                   or self._allow_virtual:
-                logging.info("Adding slave machine %s to slave pool."
-                             % machine_id)
-                self._pool[machine_id] = machine
-            else:
-                logging.warning("libvirtd not found- Machine Pool skipping "\
-                                "machine %s" % machine_id)
+            if self._pool_checks:
+                hostname = machine["params"]["hostname"]
+                if "rpcport" in machine:
+                    port = machine["params"]["rpcport"]
+                else:
+                    port = self._config.get_option('environment', 'rpcport')
+
+                logging.info("Querying slave machine %s." % m_id)
+                if not test_tcp_connection(hostname, port):
+                    msg = "Machine '%s' not responding. Skipping." % m_id
+                    logging.warning(msg)
+                    return
+
+                if 'libvirt_domain' in machine['params'] and \
+                   not self._allow_virt:
+                    msg = "libvird not running. Skipping machine '%s'." % m_id
+                    logging.warning(msg)
+
+            logging.info("Adding slave machine %s to slave pool." % m_id)
+            self._pool[m_id] = machine
 
     def provision_machines(self, mreqs):
         """


More information about the LNST-developers mailing list