
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1222777662 25200 # Node ID 1672cfb8d124a9f0dec77fa035f7ca1ef2f890d6 # Parent 74c27c6878537864db0d9a2f37dcfc826abffa5b [TEST] Fixing and updating 03_enabledstate.py of HostedDependency to work with sblim-base-provider. 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 74c27c687853 -r 1672cfb8d124 suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py --- a/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Tue Sep 30 05:25:04 2008 -0700 +++ b/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Tue Sep 30 05:27:42 2008 -0700 @@ -37,120 +37,131 @@ 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, + if host_ccn != 'Linux_ComputerSystem': + hs_ccn = get_class_basename(host_ccn) + else: + hs_ccn = host_ccn + + hs = assoc.Associators(server, "HostedDependency", + hs_ccn, virt, 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 +169,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__":