[Libvirt-cim] [PATCH] [TEST] #3 Add try / except to VSMS 15

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu Oct 1 17:36:18 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1252002019 25200
# Node ID 34e7c36ffd8acbb3d5ae5b60653e646f40a1793d
# Parent  215cbc24f8f95f95543a24ecc7e3b1d80594ecdd
[TEST] #3 Add try / except to VSMS 15

Tested on Fedora 11 with KVM

This will catch any unexpected exceptions.  Otherwise, the exception isn't
caught and the guest may not be properly undefined

Updates from 2 to 3:
  -Replace cxml.start() with cxml.cim_start()
  -Don't attempt to undefine the guest after calling cim_destroy(), since
   DestroySystem() also does an undefine

Updates from 1 to 2:
  -Fix Exception() calls to use % instead of a , when specifying arguments
  -Remove import of default_network_name
  -Replace destroy() with cim_destroy()

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 215cbc24f8f9 -r 34e7c36ffd8a suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py
--- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py	Tue Sep 22 14:32:25 2009 -0700
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py	Thu Sep 03 11:20:19 2009 -0700
@@ -26,11 +26,12 @@
 from XenKvmLib import vxml
 from CimTest.Globals import logger
 from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
-from XenKvmLib.const import do_main, default_network_name
+from XenKvmLib.const import do_main, CIM_DISABLE
 from XenKvmLib.classes import get_typed_class, inst_to_mof
 from XenKvmLib.enumclass import GetInstance 
 from XenKvmLib.common_util import poll_for_state_change 
 from XenKvmLib.const import get_provider_version
+from XenKvmLib.xm_virt_util import domain_list, active_domain_list
 
 sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
 default_dom = 'rstest_domain'
@@ -42,10 +43,6 @@
 libvirt_f9_revision=613
 libvirt_modify_setting_changes = 694
 
-def cleanup_env(ip, cxml):
-    cxml.cim_destroy(ip)
-    cxml.undefine(ip)
-
 def get_vssd(ip, virt, get_cim_inst):
     cn = get_typed_class(virt, "VirtualSystemSettingData") 
     inst = None
@@ -74,72 +71,75 @@
     cxml = vxml.get_class(options.virt)(default_dom, vcpus=cpu)
     service = vsms.get_vsms_class(options.virt)(options.ip)
 
-    for case in test_cases:
-        #Each time through, define guest using a default XML
-        cxml.undefine(options.ip)
-        cxml = vxml.get_class(options.virt)(default_dom, vcpus=cpu)
-        ret = cxml.cim_define(options.ip)
-        if not ret:
-            logger.error("Failed to define the dom: %s", default_dom)
-            cleanup_env(options.ip, cxml)
-            return FAIL
+    try:
 
-        if case == "start":
-            ret = cxml.start(options.ip)
+        for case in test_cases:
+            #Each time through, define guest using a default XML
+            cxml.undefine(options.ip)
+            cxml = vxml.get_class(options.virt)(default_dom, vcpus=cpu)
+            ret = cxml.cim_define(options.ip)
             if not ret:
-                logger.error("Failed to start %s", default_dom)
-                cleanup_env(options.ip, cxml)
-                return FAIL
+                raise Exception("Failed to define the dom: %s" % default_dom)
 
-        status, inst = get_vssd(options.ip, options.virt, True)
-        if status != PASS:
-            logger.error("Failed to get the VSSD instance for %s", default_dom)
-            cleanup_env(options.ip, cxml)
-            return FAIL
+            if case == "start":
+                ret = cxml.cim_start(options.ip)
+                if ret:
+                    raise Exception("Failed to start %s" % default_dom)
 
-        inst['AutomaticRecoveryAction'] = pywbem.cim_types.Uint16(RECOVERY_VAL)
-        vssd = inst_to_mof(inst)
+            status, inst = get_vssd(options.ip, options.virt, True)
+            if status != PASS:
+                raise Expcetion("Failed to get the VSSD instance for %s" % \
+                                default_dom)
 
-        ret = service.ModifySystemSettings(SystemSettings=vssd) 
-        curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
-        if curr_cim_rev >= libvirt_modify_setting_changes:
-            if ret[0] != 0:
-                logger.error("Failed to modify dom: %s", default_dom)
-                cleanup_env(options.ip, cxml)
-                return FAIL
+            val = pywbem.cim_types.Uint16(RECOVERY_VAL)
+            inst['AutomaticRecoveryAction'] = val
+            vssd = inst_to_mof(inst)
 
-        if case == "start":
-            #This should be replaced with a RSC to shutdownt he guest
-            cxml.destroy(options.ip)
-            status, cs = poll_for_state_change(options.ip, options.virt, 
-                                               default_dom, DEFINED_STATE)
+            ret = service.ModifySystemSettings(SystemSettings=vssd) 
+            curr_cim_rev, changeset = get_provider_version(options.virt, 
+                                                           options.ip)
+            if curr_cim_rev >= libvirt_modify_setting_changes:
+                if ret[0] != 0:
+                    raise Exception("Failed to modify dom: %s" % default_dom)
+
+            if case == "start":
+                status = cxml.cim_disable(options.ip)
+                if status != PASS:
+                    raise Exception("Failed to disable %s" % default_dom)
+
+                status, cs = poll_for_state_change(options.ip, options.virt, 
+                                                   default_dom, CIM_DISABLE)
+                if status != PASS:
+                    raise Exception("Failed to destroy %s" % default_dom)
+
+            status, inst = get_vssd(options.ip, options.virt, False)
             if status != PASS:
-                logger.error("Failed to destroy %s", default_dom)
-                cleanup_env(options.ip, cxml)
-                return FAIL
+                raise Exception("Failed to get the VSSD instance for %s" % \
+                                default_dom)
 
-        status, inst = get_vssd(options.ip, options.virt, False)
-        if status != PASS:
-            logger.error("Failed to get the VSSD instance for %s", default_dom)
-            cleanup_env(options.ip, cxml)
-            return FAIL
+            if inst.AutomaticRecoveryAction != RECOVERY_VAL:
+                logger.error("Exp AutomaticRecoveryAction=%d, got %d", 
+                             RECOVERY_VAL, inst.AutomaticRecoveryAction)
+                raise Exception("%s not updated properly" % default_dom)
 
-        if inst.AutomaticRecoveryAction != RECOVERY_VAL:
-            logger.error("%s not updated properly.", default_dom)
-            logger.error("Exp AutomaticRecoveryAction=%d, got %d", RECOVERY_VAL,
-                         inst.AutomaticRecoveryAction)
-            cleanup_env(options.ip, cxml)
-            curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
-            if curr_cim_rev <= libvirt_f9_revision and options.virt == "KVM":
-                return XFAIL_RC(f9_bug)
+            status = PASS
 
-            if options.virt == "LXC":
-                return XFAIL_RC(bug)
-            return FAIL 
+    except Exception, details:
+        logger.error(details)
+        status = FAIL
 
-    cleanup_env(options.ip, cxml)
+    defined_domains = domain_list(options.ip, options.virt)
+    if default_dom in defined_domains:
+            cxml.cim_destroy(options.ip)
 
-    return PASS 
+    curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
+    if curr_cim_rev <= libvirt_f9_revision and options.virt == "KVM":
+        return XFAIL_RC(f9_bug)
+
+    if options.virt == "LXC":
+        return XFAIL_RC(bug)
+
+    return status 
 
 if __name__ == "__main__":
     sys.exit(main())




More information about the Libvirt-cim mailing list