[lnst] NetTestController: Partial cleanup support

Jiří Pírko jirka at fedoraproject.org
Thu Aug 16 11:43:03 UTC 2012


commit 7ae86ea82a09515da4497a691dbe6b852914cd7c
Author: Ondrej Lichtner <olichtne at redhat.com>
Date:   Wed Aug 15 13:07:44 2012 +0200

    NetTestController: Partial cleanup support
    
    Currently cleanup expects that all the machines were configured without
    problems. However, this isn't true when an error occured during recipe
    parsing.
    
    This commit fixes that by skipping parts that were not configured yet.
    It skips machines that don't yet have an rpc connection initialized
    because these couldn't have been configured previously.
    It also introduces a new list info["created_devices"] which contains all
    properly created dynamic devices that need to be removed.
    
    Both of these were added because recipe parsing can fail after creating
    data structures for the machine/devices but before actually storing data
    in them. This can result in exceptions during cleanup which is again
    unwanted behaviour.
    I don't know if this is the best solution so if you have a better idea I
    am open for discussion.
    
    Signed-off-by: Ondrej Lichtner <olichtne at redhat.com>

 NetTest/NetTestController.py |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index 839d51c..72233c5 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -136,6 +136,10 @@ class NetTestController:
                                 % (dev_id, dev["hwaddr"], machine_id)
                 raise NetTestError(msg)
 
+            if 'created_devices' not in info:
+                info['created_devices'] = []
+            info['created_devices'].append((dev_id, dev))
+
         phys_devs = rpc.get_devices_by_hwaddr(dev["hwaddr"])
         if len(phys_devs) == 1:
             pass
@@ -247,18 +251,20 @@ class NetTestController:
     def _deconfigure_slaves(self):
         for machine_id in self._recipe["machines"]:
             info = self._get_machineinfo(machine_id)
+            if "rpc" not in info:
+                continue
             rpc = self._get_machinerpc(machine_id)
             for if_id in reversed(info["configured_interfaces"]):
                 rpc.deconfigure_interface(if_id)
 
             # detach dynamically created devices
-            machine = self._recipe["machines"][machine_id]
-            for dev_id, dev in machine["netdevices"].iteritems():
-                if dev["create"] == "libvirt":
-                    logging.info("Removing netdevice %d (%s) from machine %d",
-                                    dev_id, dev["hwaddr"], machine_id)
-                    domain_ctl = info["virt_domain_ctl"]
-                    domain_ctl.detach_interface(dev["hwaddr"])
+            if "created_devices" not in info:
+                continue
+            for dev_id, dev in reversed(info["created_devices"]):
+                logging.info("Removing netdevice %d (%s) from machine %d",
+                                dev_id, dev["hwaddr"], machine_id)
+                domain_ctl = info["virt_domain_ctl"]
+                domain_ctl.detach_interface(dev["hwaddr"])
 
         # remove dynamically created bridges
         networks = self._recipe["networks"]


More information about the LNST-developers mailing list