
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1230733277 28800 # Node ID 7e5820001e1f1dbcc8b58b22f7c0506f5a56e288 # Parent 5849e413cc6e3d3330d11fbda9e9b954af774ac0 [TEST] Fixing 41_cs_to_settingdefinestate.py CS tc. This test has been almost re-written to accomdate latest library changes. 1) cim_define and cim_start usage. 2) Use the library fn enum_rasd(). 3) Removed unnecessary import statements. 4) Algined the tc to 80 columns. Tested with KVM on current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 5849e413cc6e -r 7e5820001e1f suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py --- a/suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py Tue Dec 23 13:51:22 2008 -0800 +++ b/suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py Wed Dec 31 06:21:17 2008 -0800 @@ -60,17 +60,13 @@ from VirtLib import utils from XenKvmLib.vxml import get_class from XenKvmLib.classes import get_typed_class -from XenKvmLib.test_doms import destroy_and_undefine_all -from XenKvmLib.assoc import Associators, AssociatorNames -from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORNAMES, \ -CIM_ERROR_ASSOCIATORS +from XenKvmLib.assoc import Associators, AssociatorNames, compare_all_prop +from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORS from XenKvmLib.const import do_main from CimTest.ReturnCodes import PASS, FAIL -from XenKvmLib import rasd -from XenKvmLib.rasd import verify_procrasd_values, verify_netrasd_values, \ -verify_diskrasd_values, verify_memrasd_values, rasd_init_list -from XenKvmLib.common_util import poll_for_state_change -from XenKvmLib.classes import get_typed_class +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.enumclass import GetInstance +from XenKvmLib.common_util import parse_instance_id sup_types = ['Xen', 'XenFV', 'KVM'] @@ -79,91 +75,39 @@ test_mem = 128 test_mac = "00:11:22:33:44:aa" -def vssd_init_list(virt): - """ - Creating the lists that will be used for comparisons. - """ - if virt == 'XenFV': - virt = 'Xen' - - vssd_values = { - 'Caption' : "Virtual System", - 'InstanceID' : '%s:%s' % (virt, test_dom), - 'ElementName' : test_dom, - 'VirtualSystemIdentifier' : test_dom, - 'VirtualSystemType' : virt, - 'Classname' : get_typed_class(virt, - "VirtualSystemSettingData") - } - - return vssd_values - -def cs_init_list(cs_dom): - """ - Creating the lists that will be used for comparisons. - """ - cs_values = { - 'Caption' : cs_dom.Caption, - 'EnabledState' : cs_dom.EnabledState, - 'RequestedState' : cs_dom.RequestedState, - 'CreationClassName' : cs_dom.CreationClassName, - 'Name' : cs_dom.Name - } - return cs_values - -def setup_env(server, virt, test_disk): +def setup_env(server, virt): vsxml_info = None - status = PASS - destroy_and_undefine_all(server) virt_xml = get_class(virt) vsxml_info = virt_xml(test_dom, mem = test_mem, vcpus=test_vcpus, - mac = test_mac, - disk = test_disk) + mac = test_mac) - ret = vsxml_info.create(server) + ret = vsxml_info.cim_define(server) if not ret: - logger.error("Failed to create the dom: %s", test_dom) - status = FAIL + logger.error("Failed to define the dom: %s", test_dom) + return FAIL, vsxml_info - return status, vsxml_info + status = vsxml_info.cim_start(server) + if not ret: + logger.error("Failed to start the dom: %s", test_dom) + vsxml_info.undefine(server) + return FAIL, vsxml_info + return PASS, vsxml_info def print_err(err, detail, cn): logger.error(err % cn) logger.error("Exception: %s", detail) -def vssd_sds_err( an, fieldname, ret_val, exp_val): - error = "Mismatching %s Values in %s association" - details = "Returned %s instead of %s" - err = error % (fieldname, an) - detail = details % (ret_val, exp_val) - logger.error(err) - logger.error(detail) +def check_len(an, assoc_list_info, qcn, exp_len): + if len(assoc_list_info) != exp_len: + logger.error("%s returned %i %s objects", an, + len(assoc_list_info), qcn) + return FAIL + return PASS -def get_associatornames_info(server, virt, vsxml, cn, an, qcn, name): - status = PASS - assoc_info = [] - try: - assoc_info = AssociatorNames(server, - an, - cn, - CreationClassName=cn, - Name = name) - if len(assoc_info) < 1: - logger.error("%s returned %i %s objects" % (an, len(assoc_info), qcn)) - status = FAIL - except Exception, detail: - print_err(CIM_ERROR_ASSOCIATORNAMES, detail, cn) - status = FAIL - - if status != PASS: - vsxml.destroy(server) - - return status, assoc_info - -def get_associators_info(server, virt, vsxml, cn, an, qcn, instid): +def get_associators_info(server, virt, cn, an, qcn, instid): status = PASS assoc_info = [] try: @@ -180,228 +124,168 @@ print_err(CIM_ERROR_ASSOCIATORS, detail, cn) status = FAIL - if status != PASS: - vsxml.destroy(server) - return status, assoc_info -def check_len(an, assoc_list_info, qcn, exp_len): - if len(assoc_list_info) != exp_len: - logger.error("%s returned %i %s objects", an, - len(assoc_list_info), qcn) - return FAIL - return PASS +def init_rasd_list(virt, ip): + rasd_insts = {} + rasds, status = enum_rasds(virt, ip) + if status != PASS: + logger.error("Enum RASDs failed") + return rasd_insts, status -def get_SDS_verify_RASD_build_vssdc_input(server, virt, vsxml, - test_disk, sd_assoc_info): - status = PASS + for rasd_cn, rasd_list in rasds.iteritems(): + for rasd in rasd_list: + guest, dev, status = parse_instance_id(rasd.InstanceID) + if status != PASS: + logger.error("Unable to parse InstanceID: %s" % rasd.InstanceID) + return rasd_insts, FAIL + + if guest == test_dom: + rasd_insts[rasd.Classname] = rasd + + return rasd_insts, PASS + + +def get_SDS_verify_RASD_build_vssdc_input(server, virt, an, cs_cn, + rasd_values, sd_assoc_info): in_setting_define_state = {} in_vssdc = {} - prasd = get_typed_class(virt, 'ProcResourceAllocationSettingData') - mrasd = get_typed_class(virt, 'MemResourceAllocationSettingData') - nrasd = get_typed_class(virt, 'NetResourceAllocationSettingData') - drasd = get_typed_class(virt, 'DiskResourceAllocationSettingData') - try: - # Building the input for SettingsDefineState association. - for i in range(len(sd_assoc_info)): - if sd_assoc_info[i]['SystemName'] == test_dom: - classname_keyvalue = sd_assoc_info[i]['CreationClassName'] - deviceid = sd_assoc_info[i]['DeviceID'] + for sd_val in sd_assoc_info: + if sd_val['SystemName'] == test_dom: + classname_keyvalue = sd_val['CreationClassName'] + deviceid = sd_val['DeviceID'] in_setting_define_state[classname_keyvalue] = deviceid - # Expect the SystemDevice to return 4 logical device records. - # one each for memory, network, disk and processor and hence 4. - # and hence expect the in_setting_define_state to contain just 4 entries. - an = get_typed_class(virt, "SystemDevice") + # Expect the SystemDevice records == len(rasd_values) entries. qcn = "Logical Devices" - exp_len = 4 + exp_len = len(rasd_values) if check_len(an, in_setting_define_state, qcn, exp_len) != PASS: return FAIL, in_setting_define_state - - # Get the rasd values that will be used to compare with the SettingsDefineState - # output. - status, rasd_values, in_list = rasd_init_list(vsxml, virt, test_disk, - test_dom, test_mac, - test_mem) - if status != PASS: - return status, rasd_values - sccn = get_typed_class(virt,"ComputerSystem") an = get_typed_class(virt,"SettingsDefineState") for cn, devid in sorted(in_setting_define_state.items()): - assoc_info = Associators(server, - an, - cn, - DeviceID = devid, + assoc_info = Associators(server, an, cn, DeviceID = devid, CreationClassName = cn, SystemName = test_dom, - SystemCreationClassName = sccn) + SystemCreationClassName = cs_cn) - # we expect only one RASD record to be returned for each device that is used to - # query with the SettingsDefineState association. + # we expect only one RASD record to be returned for each device + # type when queried with SDS association. if len(assoc_info) != 1: - logger.error("%s returned %i %s objects" % (an, len(assoc_info), cn)) - status = FAIL - break - index = (len(assoc_info) - 1) - rasd = rasd_values[cn] - CCName = assoc_info[index].classname - if CCName == prasd: - status = verify_procrasd_values(assoc_info[index], rasd) - elif CCName == nrasd: - status = verify_netrasd_values(assoc_info[index], rasd) - elif CCName == drasd: - status = verify_diskrasd_values(assoc_info[index], rasd) - elif CCName == mrasd: - status = verify_memrasd_values(assoc_info[index], rasd) - else: - status = FAIL - if status != PASS: - logger.error("Mistmatching RASD values" ) - break - vs_name = assoc_info[index]['InstanceID'] + logger.error("%s returned %d %s objects", + an, len(assoc_info), cn) + return FAIL, in_vssdc + + assoc_val = assoc_info[0] + CCName = assoc_val.classname + exp_rasd = rasd_values[CCName] + if assoc_val['InstanceID'] != exp_rasd.InstanceID: + logger.error("Got %s instead of %s" + % (assoc_val['InstanceID'], exp_rasd.InstanceID)) + return FAIL, in_vssdc + + # Build the input required for VSSDC association query. + vs_name = assoc_val['InstanceID'] if vs_name.find(test_dom) >= 0: - instid = assoc_info[index]['InstanceID'] + instid = assoc_val['InstanceID'] in_vssdc[CCName] = instid + except Exception, detail: print_err(CIM_ERROR_ASSOCIATORS, detail, an) - status = FAIL - return status, in_vssdc + return FAIL, in_vssdc + return PASS, in_vssdc -def verify_fields(an, field_name, vssd_cs_assoc_info, vssd_cs_values): - if vssd_cs_assoc_info[field_name] != vssd_cs_values[field_name]: - vssd_sds_err(an, field_name, vssd_cs_assoc_info[field_name], \ - vssd_cs_values[field_name]) - return FAIL - return PASS - - -def verify_VSSD_values(assoc_info, vssd_values, an, qcn): - # We expect that VirtualSystemSettingDataComponent returns only one - # VirtualSystemSettingData object when queried with disk, processor, - # network and memory rasd's and all of them return the same output. +def verify_values(assoc_info, vssd_cs_values, an, qcn): exp_len = 1 - if check_len(an, assoc_info, qcn, exp_len) != PASS: return FAIL - vssd_assoc = assoc_info[0] - if verify_fields(an, 'Caption', vssd_assoc, vssd_values) != PASS: - return FAIL - if verify_fields(an, 'InstanceID', vssd_assoc, vssd_values) != PASS: - return FAIL - if verify_fields(an, 'ElementName', vssd_assoc, vssd_values) != PASS: - return FAIL - if verify_fields(an, 'VirtualSystemIdentifier', vssd_assoc, vssd_values) != PASS: - return FAIL - if verify_fields(an, 'VirtualSystemType', vssd_assoc, vssd_values) != PASS: - return FAIL - if vssd_assoc.classname != vssd_values['Classname']: - vssd_sds_err(an, 'Classname', vssd_assoc.classname, - vssd_values['Classname']) - return FAIL - return PASS -def verify_CS_values(assoc_info, cs_values, an, qcn): - exp_len = 1 - - if check_len(an, assoc_info, qcn, exp_len) != PASS: - return FAIL - cs_assoc = assoc_info[0] - if verify_fields(an, 'Caption', cs_assoc, cs_values) != PASS: - return FAIL - if verify_fields(an, 'EnabledState', cs_assoc, cs_values) != PASS: - return FAIL - if verify_fields(an, 'RequestedState', cs_assoc, cs_values) != PASS: - return FAIL - if verify_fields(an, 'CreationClassName', cs_assoc, cs_values) != PASS: - return FAIL - if verify_fields(an, 'Name', cs_assoc, cs_values) != PASS: - return FAIL - return PASS + vssd_cs_assoc = assoc_info[0] + return compare_all_prop(vssd_cs_assoc, vssd_cs_values) @do_main(sup_types) def main(): server = main.options.ip virt = main.options.virt - if virt == 'Xen': - test_disk = "xvda" - else: - test_disk = "hda" - status, vsxml = setup_env(server, virt, test_disk) + status, vsxml = setup_env(server, virt) if status != PASS: return status + try: + cs_class = get_typed_class(virt, 'ComputerSystem') + keys = { 'Name' : test_dom, 'CreationClassName' : cs_class } + dom_cs = GetInstance(server, cs_class, keys) + if dom_cs.Name != test_dom and dom_cs.RequestedState != 0: + raise Exception("Instance matching %s was not returned" % test_dom) - status, cs_dom = poll_for_state_change(server, virt, test_dom, 2, - timeout=10) - if status != PASS and cs_dom.RequestedState != 0: - vsxml.destroy(server) - return FAIL + an = get_typed_class(virt, 'SystemDevice') + qcn = 'Logical Devices' + sd_assoc = AssociatorNames(server, an, cs_class, + CreationClassName=cs_class, + Name = test_dom) + if len(sd_assoc) < 1: + raise Exception ("%s returned %d %s objects" \ + % (an, len(sd_assoc), qcn)) - # Creating the cs info list which will be used later for comparison. - cs_values = cs_init_list(cs_dom) - - cn = cs_dom.CreationClassName - an = get_typed_class(virt, 'SystemDevice') - qcn = 'Logical Devices' - name = test_dom - status, sd_assoc_info = get_associatornames_info(server, virt, vsxml, - cn, an, qcn, name) - if status != PASS or len(sd_assoc_info) == 0: - return status + rasd_val, status = init_rasd_list(virt, server) + status, in_vssdc_list = get_SDS_verify_RASD_build_vssdc_input(server, + virt, an, + cs_class, + rasd_val, + sd_assoc) + exp_len = len(rasd_val) + if status !=PASS or check_len(an, in_vssdc_list, qcn, exp_len) != PASS: + raise Exception ("Failed to get VSSDC info") - status, in_vssdc_list = get_SDS_verify_RASD_build_vssdc_input(server, virt, - vsxml, test_disk, - sd_assoc_info) - if status != PASS or len(in_vssdc_list) == 0 : - vsxml.destroy(server) - return status + # Get the vssd values which will be used for verifying the + # VSSD output from the VSSDC results. + vssd_class = get_typed_class(virt, 'VirtualSystemSettingData') + if virt == "XenFV": + instIdval = "Xen:%s" % test_dom + else: + instIdval = "%s:%s" % (virt, test_dom) + keys = { 'InstanceID' : instIdval } + vssd_values = GetInstance(server, vssd_class, keys) + if vssd_values.ElementName != test_dom: + raise Exception ("Instance matching %s was not returned" \ + % test_dom) - # Verifying that the in_vssdc_list contains 4 entries one each for mem rasd, - # network rasd, processor rasd and disk rasd. - exp_len = 4 - if check_len(an, in_vssdc_list, qcn, exp_len) != PASS: - vsxml.destroy(server) - return FAIL + an = get_typed_class(virt, 'VirtualSystemSettingDataComponent') + for cn, instid in sorted((in_vssdc_list.items())): + status, vssd_assoc_info = get_associators_info(server, virt, cn, an, + vssd_class, instid) + if status != PASS or len(vssd_assoc_info) == 0: + raise Exception ("Failed to get VSSD info") - # Get the vssd values which will be used for verifying the - # VirtualSystemSettingData output from the - # VirtualSystemSettingDataComponent results. - vssd_values = vssd_init_list(virt) - an = get_typed_class(virt, 'VirtualSystemSettingDataComponent') - qcn = get_typed_class(virt, 'VirtualSystemSettingData') - for cn, instid in sorted((in_vssdc_list.items())): - status, vssd_assoc_info = get_associators_info(server, virt, vsxml, cn, - an, qcn, instid) - if status != PASS or len(vssd_assoc_info) == 0: - break - status = verify_VSSD_values(vssd_assoc_info, vssd_values, an, qcn) - if status != PASS: - break - if status != PASS: - vsxml.destroy(server) - return status + status = verify_values(vssd_assoc_info, vssd_values, an, qcn) + if status != PASS: + raise Exception ("VSSD values verification error") - # Since the VirtualSystemSettingDataComponent returns similar - # output when queried with every RASD, we are taking the output of - # the last associtaion query as inputs for - # querying SettingsDefineState. - cn = vssd_assoc_info[0].classname - an = get_typed_class(virt, 'SettingsDefineState') - qcn = get_typed_class(virt, 'ComputerSystem') - instid = vssd_assoc_info[0]['InstanceID'] - status, cs_assoc_info = get_associators_info(server, virt, vsxml, cn, - an, qcn, instid) - if status != PASS or len(cs_assoc_info) == 0: - return status + # Since the VirtualSystemSettingDataComponent returns similar + # output when queried with every RASD, we are taking the output of + # the last associtaion query as inputs for + # querying SettingsDefineState. + cn = vssd_assoc_info[0].classname + an = get_typed_class(virt, 'SettingsDefineState') + instid = vssd_assoc_info[0]['InstanceID'] + status, cs_assoc_info = get_associators_info(server, virt, cn, an, + cs_class, instid) + if status != PASS or len(cs_assoc_info) == 0: + raise Exception ("Failed to get assoc info for dom: %s", test_dom) - # verify the results of SettingsDefineState with the cs_values list that was - # built using the output of the enumeration on ComputerSystem. - status = verify_CS_values(cs_assoc_info, cs_values, an, qcn) + # verify the results of SettingsDefineState with the cs_values list that was + # built using the output of the GetInstance on ComputerSystem. + status = verify_values(cs_assoc_info, dom_cs, an, cs_class) + + except Exception, details: + logger.error("Exception details is %s", details) + status = FAIL + vsxml.destroy(server) + vsxml.undefine(server) return status if __name__ == "__main__": sys.exit(main())