
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1252002019 25200 # Node ID 54bf724a87d4dcf370ca68714809cfaaf55457ca # Parent 30196cc506c07d81642c94a01fc65b34421c0714 [TEST] #2 Add try / except to VSMS 15 This will catch any unexpected exceptions. Otherwise, the exception isn't caught and the guest may not be properly undefined Updates: -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@us.ibm.com> diff -r 30196cc506c0 -r 54bf724a87d4 suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py Wed Sep 02 05:11:16 2009 -0700 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py Thu Sep 03 11:20:19 2009 -0700 @@ -26,7 +26,7 @@ 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 from XenKvmLib.classes import get_typed_class, inst_to_mof from XenKvmLib.enumclass import GetInstance from XenKvmLib.common_util import poll_for_state_change @@ -74,72 +74,70 @@ 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.start(options.ip) + if not 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": + cxml.cim_destroy(options.ip) + status, cs = poll_for_state_change(options.ip, options.virt, + default_dom, DEFINED_STATE) + 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) - 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())