
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1222843581 25200 # Node ID f97dd6bf14b97cea6492aabb540628f11c5abd91 # Parent 41c2dc5b6a669fa923a51c441de9604e1f8c5cf2 [TEST] Fixing and updating 02_reverse.py and 03_enabledstate.py of HostedDependency to work with and without sblim-base-provider. Changes for 02_reverse.py ------------------------- 1) Updated the tc to work with/without sblim-base-provider. 2) Updated the tc to use cim_define(). 3) Updated call_request_state_change() to start the domain. 3) Included the bug no 00007. 4) Used get_host_info() for getting the host information. Changes for 03_enabledstate.py ------------------------------- 1) Updated the tc to work with/without sblim-base-provider. 2) Updated the tc to use cim_define(). 3) Updated call_request_state_change() to start the domain. 3) Included the bug no 00007. 4) Used get_host_info() for getting the host information. 5) Included library function print_field_error() to print error msg. 6) Included poll_for_state_change() to verify the EnabledState value. Tested with Xen, XenFV, KVM on current sources and with/without sblim-base-provider installed. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 41c2dc5b6a66 -r f97dd6bf14b9 suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py --- a/suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py Tue Sep 30 23:16:55 2008 -0700 +++ b/suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py Tue Sep 30 23:46:21 2008 -0700 @@ -29,7 +29,7 @@ # Example cli command is # wbemcli ain -ac Xen_HostedDependency # 'http://localhost:5988/root/virt: -# Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="mx3650b.in.ibm.com"' +# Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="3650b"' # # For which we get the following output # localhost:5988/root/virt:Xen_ComputerSystem. @@ -45,44 +45,53 @@ from XenKvmLib import vxml from XenKvmLib import vxml from XenKvmLib import enumclass from XenKvmLib import assoc -from XenKvmLib.classes import get_class_basename +from XenKvmLib.classes import get_typed_class from CimTest.Globals import logger from XenKvmLib.const import do_main -from CimTest.ReturnCodes import PASS, FAIL +from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC +from XenKvmLib.common_util import get_host_info, call_request_state_change sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] test_dom = "hd_domain" test_mac = "00:11:22:33:44:55" +TIME = "00000000000000.000000:000" +bug_sblim = "00007" @do_main(sup_types) def main(): options = main.options + virt = options.virt + server = options.ip status = PASS - virtxml = vxml.get_class(options.virt) - if options.virt == "LXC": + virtxml = vxml.get_class(virt) + if virt == "LXC": cxml = virtxml(test_dom) else: cxml = virtxml(test_dom, mac = test_mac) - ret = cxml.create(options.ip) + ret = cxml.cim_define(server) if not ret: - logger.error("ERROR: Failed to Create the dom: %s" % test_dom) - status = FAIL - return status - keys = ['Name', 'CreationClassName'] + logger.error("Failed to define the dom: %s" % test_dom) + return FAIL + + rc = call_request_state_change(test_dom, server, 2, TIME, virt) + if rc != 0: + logger.error("Failed to start the dom: %s" % test_dom) + cxml.undefine(server) + return FAIL + try: - host_sys = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt) - if host_sys[0].Name == "": - raise Exception("HostName seems to be empty") - else: - # Instance of the HostSystem - host_sys = host_sys[0] + status, host_name, host_ccn = get_host_info(server, virt) + if status != PASS: + cxml.destroy(server) + cxml.undefine(server) + return status keys = ['Name', 'CreationClassName'] - cs = enumclass.enumerate(options.ip, 'ComputerSystem', keys, options.virt) - if options.virt == 'Xen' or options.virt == 'XenFV': + cs = enumclass.enumerate(server, 'ComputerSystem', keys, virt) + if virt == 'Xen' or options.virt == 'XenFV': # Xen honors additional domain-0 cs_list_len = 2 else: @@ -94,19 +103,23 @@ def main(): # ComputerSystem.EnumerateInstances() cs_names = [x.name for x in cs] + assoc_cn = get_typed_class(virt, "HostedDependency") + # Get a list of ComputerSystem instances from the HostSystem instace - host_ccn = host_sys.CreationClassName - systems = assoc.AssociatorNames(options.ip, "HostedDependency", - get_class_basename(host_ccn), - options.virt, + systems = assoc.AssociatorNames(server, assoc_cn, host_ccn, CreationClassName=host_ccn, - Name=host_sys.Name) + Name=host_name) + # Compare each returned instance to make sure it's in the list # that ComputerSystem.EnumerateInstances() returned if len(systems) < 1: - raise Exception("HostedDependency returned %d, expected at least 1" % - len(systems)) + logger.error("HostedDependency returned %d, expected at least 1", + len(systems)) + cxml.destroy(server) + cxml.undefine(server) + return XFAIL_RC(bug_sblim) + ccn = cs[0].CreationClassName for guest in systems: @@ -119,7 +132,7 @@ def main(): # checking the CreationClassName returned is Xen_ComputerSystem if ccn != guest["CreationClassName"]: - logger.error("ERROR: CreationClassName does not match") + logger.error("CreationClassName does not match") status = FAIL # Go through anything remaining in the @@ -131,15 +144,12 @@ def main(): guest["Name"]) status = FAIL - except (UnboundLocalError, NameError), detail: - logger.error("Exception: %s" % detail) - except Exception, detail: - logger.error(detail) + logger.error("Exception: %s", detail) status = FAIL - cxml.destroy(options.ip) - cxml.undefine(options.ip) + cxml.destroy(server) + cxml.undefine(server) return status if __name__ == "__main__": diff -r 41c2dc5b6a66 -r f97dd6bf14b9 suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py --- a/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Tue Sep 30 23:16:55 2008 -0700 +++ b/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Tue Sep 30 23:46:21 2008 -0700 @@ -37,120 +37,127 @@ from XenKvmLib import enumclass from XenKvmLib import enumclass from XenKvmLib import assoc from XenKvmLib.classes import get_typed_class -from XenKvmLib.common_util import get_host_info +from XenKvmLib.common_util import get_host_info, print_field_error, \ +poll_for_state_change, call_request_state_change from XenKvmLib.classes import get_class_basename from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORS, \ CIM_ERROR_GETINSTANCE from XenKvmLib.const import do_main from XenKvmLib.devices import CIM_Instance -from CimTest.ReturnCodes import PASS, FAIL +from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC sup_types = ['Xen', 'KVM', 'XenFV'] +TIME = "00000000000000.000000:000" test_dom = "hd_domain1" test_mac = "00:11:22:33:44:55" +bug_sblim = "00007" def create_list(instance): new_list = { - 'CreationClassName': instance.CreationClassName, \ - 'EnabledState' : instance.EnabledState, \ - 'Name' : instance.Name, \ + 'CreationClassName': instance.CreationClassName, + 'EnabledState' : instance.EnabledState, + 'Name' : instance.Name, 'RequestedState' : instance.RequestedState } return new_list -def print_error(field, ret_val, req_val): - logger.error("%s Mismatch", field) - logger.error("Returned %s instead of %s", ret_val, req_val) def poll_for_enabledstate_value(server, virt): status = PASS dom_field_list = {} - check_reqstate_value = None timeout = 10 try: - for i in range(1, (timeout + 1)): - sleep(1) - ccn = get_typed_class(virt, 'ComputerSystem') - keys = { - 'Name' : test_dom, - 'CreationClassName' : ccn - } - dom_cs = enumclass.getInstance(server, 'ComputerSystem', keys, virt) - if dom_cs.EnabledState == "" or dom_cs.CreationClassName == "" or \ - dom_cs.Name == "" or dom_cs.RequestedState == "": - logger.error("Empty EnabledState field.") - status = FAIL - return status, [] + status, dom_cs = poll_for_state_change(server, virt, test_dom, 9, + timeout) + if status != PASS: + logger.error("Attributes for dom '%s' is not set as expected.", + test_dom) + return FAIL, [] - dom_field_list = create_list(dom_cs) - check_reqstate_value = dom_field_list['EnabledState'] - if check_reqstate_value == 9: - break + dom_field_list = create_list(dom_cs) except Exception, detail: logger.error(CIM_ERROR_GETINSTANCE, 'ComputerSystem') logger.error("Exception: %s" % detail) status = FAIL - if check_reqstate_value != 9: - logger.error("EnabledState has %i instead of 9.", check_reqstate_value) - logger.error("Try to increase the timeout and run the test again") - status = FAIL - return status, dom_field_list -class HsError(Exception): - pass +def verify_fields(hs_ret_values, exp_hs_values): + try: + field_names = exp_hs_values.keys() + for field in field_names: + if hs_ret_values[field] != exp_hs_values[field]: + print_field_error(field, hs_ret_values[field], + exp_hs_values[field]) + return FAIL + except Exception, details: + logger.error("Exception: In fn verify_fields() %s", details) + return FAIL + + return PASS + @do_main(sup_types) def main(): options = main.options + virt = options.virt + server = options.ip status = PASS - virtxml = vxml.get_class(options.virt) + virtxml = vxml.get_class(virt) cxml = virtxml(test_dom, mac = test_mac) - ret = cxml.create(options.ip) + ret = cxml.cim_define(server) if not ret: - logger.error("Failed to Create the dom: %s" % test_dom) - status = FAIL - return status + logger.error("Failed to define the dom: %s" % test_dom) + return FAIL - ret = cxml.run_virsh_cmd(options.ip, "suspend") + rc = call_request_state_change(test_dom, server, 2, TIME, virt) + if rc != 0: + logger.error("Failed to start the dom: %s" % test_dom) + cxml.undefine(server) + return FAIL - if not ret: + rc = call_request_state_change(test_dom, server, 9, TIME, virt) + if rc != 0: logger.error("Failed to suspend the dom: %s" % test_dom) - cxml.destroy(options.ip) - cxml.undefine(options.ip) - status = FAIL - return status + cxml.destroy(server) + cxml.undefine(server) + return FAIL - status, host_name, host_ccn = get_host_info(options.ip, options.virt) + status, host_name, host_ccn = get_host_info(server, virt) if status != PASS: logger.error("Failed to get host info") - cxml.destroy(options.ip) - cxml.undefine(options.ip) + cxml.destroy(server) + cxml.undefine(server) return status try: -#Polling for the value of EnabledState to be set to 9. -#We need to wait for the EnabledState to be set appropriately since -#it does not get set immediatley to value of 9 when suspended. + #Polling for the value of EnabledState to be set to 9. + #We need to wait for the EnabledState to be set appropriately since + #it does not get set immediatley to value of 9 when suspended. dom_field_list = {} - status, dom_field_list = poll_for_enabledstate_value(options.ip, - options.virt) + status, dom_field_list = poll_for_enabledstate_value(server, virt) if status != PASS or len(dom_field_list) == 0: - raise HsError("Failed to poll for enabled state value") + logger.error("Failed to poll for enabled state value") + cxml.destroy(server) + cxml.undefine(server) + return FAIL - hs = assoc.Associators(options.ip, "HostedDependency", - get_class_basename(host_ccn), options.virt, + assoc_cn = get_typed_class(virt, "HostedDependency") + + hs = assoc.Associators(server, assoc_cn, host_ccn, CreationClassName=host_ccn, Name=host_name) if len(hs) == 0: - raise HsError("HostedDependency didn't return any instances.") + logger.error("HostedDependency didn't return any instances.") + cxml.destroy(server) + cxml.undefine(server) + return XFAIL_RC(bug_sblim) hs_field_list = [] for hsi in hs: @@ -158,35 +165,20 @@ def main(): hs_field_list = create_list(CIM_Instance(hsi)) if len(hs_field_list) == 0: - raise HsError("Association did not return expected guest instance.") + logger.error("Association did not return expected guest instance.") + cxml.destroy(server) + cxml.undefine(server) + return FAIL - if dom_field_list['CreationClassName'] != hs_field_list['CreationClassName']: - print_error('CreationClassName', hs_field_list['CreationClassName'], \ - dom_field_list['CreationClassName']) - status = FAIL - if dom_field_list['Name'] != hs_field_list['Name']: - print_error('Name', hs_field_list['Name'], \ - dom_field_list['Name']) - status = FAIL - - if dom_field_list['RequestedState'] != hs_field_list['RequestedState']: - print_error('RequestedState', hs_field_list['RequestedState'], \ - dom_field_list['RequestedState']) - status = FAIL - if dom_field_list['EnabledState'] != hs_field_list['EnabledState']: - print_error('EnabledState', hs_field_list['EnabledState'], \ - dom_field_list['EnabledState']) - status = FAIL - except HsError, detail: - status = FAIL - logger.error(detail) + status = verify_fields(hs_field_list, dom_field_list) + except Exception, detail: logger.error(CIM_ERROR_ASSOCIATORS,'HostedDependency') logger.error("Exception: %s" % detail) status = FAIL - cxml.destroy(options.ip) - cxml.undefine(options.ip) + cxml.destroy(server) + cxml.undefine(server) return status if __name__ == "__main__":