
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1231407135 28800 # Node ID 4271244c8945d777e6f42afd5cf98c433df05c2e # Parent 840f4651f746882475188adba781fafbf583c07b TEST] #3 Fixing 41_cs_to_settingdefinestate.py CS tc. Changes: --------
From Patch 2 to 3:
1) Removed space between Exception and the ( 2) changed destroy to cim_destroy
From Patch 1 to 2:
1) Removed ununsed variables. 2) Algined to comments line to 80 columns. 3) removed check_len(), print_err() functions. 4) Made main() and get_SDS_verify_RASD_build_vssdc_input() more modular and small. Patch 1: -------- 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 for KVM and Xen with current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 840f4651f746 -r 4271244c8945 suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py --- a/suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py Tue Jan 06 11:56:13 2009 -0800 +++ b/suites/libvirt-cim/cimtest/ComputerSystem/41_cs_to_settingdefinestate.py Thu Jan 08 01:32:15 2009 -0800 @@ -27,12 +27,12 @@ # SettingsDefineState. # # It traverses the following path: -# {ComputerSystem} (select the guest domain) --> [SystemDevice](from output select -# guest domain instances of Device, from the guest domain instances, -# select one Device instance) --> [SettingsDefineState] (from output, select a RASD -# instance - should only be 1) --> [VSSDComponent] (from output, select a VSSD instance -# - should only be 1) --> [SettingsDefineState] (Verify the ComputerSystem instance is -# the one we started with) +# {ComputerSystem} (select the guest domain) --> [SystemDevice](from output +# select guest domain instances of Device, from the guest domain instances, +# select one Device instance) --> [SettingsDefineState] (from output, select +# a RASD instance - should only be 1) --> [VSSDComponent] (from output, +# select a VSSD instance - should only be 1) --> [SettingsDefineState] +# (Verify the ComputerSystem instance is the one we started with) # # Steps: # ------ @@ -41,367 +41,289 @@ # and and verify the EnabledState is 2. # 3) Create info list for the guest domain to be used later for comparison. # 4) Get the various devices allocated to the domain by using the SystemDevice -# association and giving the ComputerSystem output from the previous enumeration -# as inputs to the association. -# 5) For each of the Devices get the association on SettingsDefineState, we should -# get only one record as output. +# association and giving the ComputerSystem output from the previous +# enumeration as inputs to the association. +# 5) For each of the Devices get the association on SettingsDefineState, we +# should get only one record as output. # 6) Verify the Disk, Memory, Network, Processor RASD values. # 7) Call VSSDComponent association for each of the RASD types, we should # get only one VSSD record as output. -# 8) Verify the VSSD output for every VSSDComponent association with the RASD types. -# 9) Using the VSSD output query the SettingsDefineState association, again we should -# get only one computersystem record as output. -# 10)Verify the computersystem values with the computersystem info that was created from -# the enumeration in the beginning. +# 8) Verify the VSSD output for every VSSDComponent association with the +# RASD types. +# 9) Using the VSSD output query the SettingsDefineState association, again we +# should get only one computersystem record as output. +# 10)Verify the computersystem values with the computersystem info that was +# created from the enumeration in the beginning. # 11) Destroy the domain. -# Date : 05.02.2008 +# Date : 05.02.2008 import sys 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'] test_dom = "CrossClass_GuestDom" -test_vcpus = 1 -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) + vsxml_info = virt_xml(test_dom) + ret = vsxml_info.cim_define(server) + if not ret: + logger.error("Failed to define the dom: %s", test_dom) + return FAIL, vsxml_info - ret = vsxml_info.create(server) + status = vsxml_info.cim_start(server) if not ret: - logger.error("Failed to create the dom: %s", test_dom) - status = FAIL + logger.error("Failed to start the dom: %s", test_dom) + vsxml_info.undefine(server) + return FAIL, vsxml_info - return status, 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 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, cn, an, qcn, instid): status = PASS assoc_info = [] try: assoc_info = Associators(server, - an, - cn, - InstanceID = instid) + an, + cn, + InstanceID = instid) if len(assoc_info) < 1: - logger.error("%s returned %i %s objects" % - (an, len(assoc_info), qcn)) + logger.error("%s returned %i %s objects", + an, len(assoc_info), qcn) status = FAIL except Exception, detail: - print_err(CIM_ERROR_ASSOCIATORS, detail, cn) + logger.error(CIM_ERROR_ASSOCIATORS, cn) + logger.error("Exception: %s", detail) 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 - 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') + 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 verify_values(assoc_info, vssd_cs_values, an, qcn): + if len(assoc_info) != 1: + logger.error("%s returned %i %s objects, Expected 1", an, + len(assoc_info), qcn) + return FAIL + + vssd_cs_assoc = assoc_info[0] + return compare_all_prop(vssd_cs_assoc, vssd_cs_values) + +def build_sd_info(sd_assoc_info, qcn, an, rasd_values): + sd_info = {} + + # Building the input for SettingsDefineState association. + for sd_val in sd_assoc_info: + if sd_val['SystemName'] == test_dom: + classname_keyvalue = sd_val['CreationClassName'] + deviceid = sd_val['DeviceID'] + sd_info[classname_keyvalue] = deviceid + + # Expect the SystemDevice records == len(rasd_values) entries. + if len(sd_info) != len(rasd_values): + logger.error("%s returned %i %s objects, Expected %i", an, + len(sd_info), qcn, len(rasd_values)) + return FAIL, sd_info + + return PASS, sd_info + +def get_cs_sysdev_info(server, virt, qcn, rasd_val): + sd_info={} + 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: + raise Exception("Instance matching %s was not returned" % test_dom) + + an = get_typed_class(virt, 'SystemDevice') + 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)) + + status, sd_info = build_sd_info(sd_assoc, qcn, an, rasd_val) + if status != PASS: + raise Exception("Failed to get SystemDevice info for: %s" \ + % test_dom) + + except Exception, details: + logger.error("Exception details: %s", details) + return FAIL, dom_cs, sd_info + + return PASS, dom_cs, sd_info + +def get_sds_info(server, virt, cs_cn, rasd_values, + in_setting_define_state, qcn): + sds_info = {} 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'] - 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") - qcn = "Logical Devices" - exp_len = 4 - 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") + 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 + raise Exception("%s returned %d %s objects, Expected 1" \ + % (an, len(assoc_info), cn)) + + assoc_val = assoc_info[0] + CCName = assoc_val.classname + exp_rasd = rasd_values[CCName] + if assoc_val['InstanceID'] != exp_rasd.InstanceID: + raise Exception("Got %s instead of %s" \ + % (assoc_val['InstanceID'], + exp_rasd.InstanceID)) + + # Build the input required for VSSDC association query. + vs_name = assoc_val['InstanceID'] + if vs_name.find(test_dom) >= 0: + instid = assoc_val['InstanceID'] + sds_info[CCName] = instid + + if len(sds_info) != len(rasd_values): + raise Exception("%s returned %i %s objects, Expected %i" \ + % (an, len(sds_info), qcn, len(rasd_values))) + + except Exception, details: + logger.error("Exception: %s", details) + return FAIL, sds_info + + return PASS, sds_info + +def get_vssd_info(server, virt, in_vssdc_list, qcn): + try: + # Get the vssd values which will be used for verifying the + # VSSD output from the VSSDC results. + if virt == "XenFV": + instIdval = "Xen:%s" % test_dom + else: + instIdval = "%s:%s" % (virt, test_dom) + + vssd_class = get_typed_class(virt, 'VirtualSystemSettingData') + 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) + + an = get_typed_class(virt, 'VirtualSystemSettingDataComponent') + for cn, instid in sorted((in_vssdc_list.items())): + status, vssd_assoc_info = get_associators_info(server, cn, an, + vssd_class, + instid) if status != PASS: - logger.error("Mistmatching RASD values" ) - break - vs_name = assoc_info[index]['InstanceID'] - if vs_name.find(test_dom) >= 0: - instid = assoc_info[index]['InstanceID'] - in_vssdc[CCName] = instid - except Exception, detail: - print_err(CIM_ERROR_ASSOCIATORS, detail, an) - status = FAIL - return status, in_vssdc + raise Exception("Failed to get VSSD info") + status = verify_values(vssd_assoc_info, vssd_values, an, qcn) + if status != PASS: + raise Exception("VSSD values verification error") -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 + except Exception, details: + logger.error("Exception details: %s", details) + return FAIL, vssd_assoc_info + return PASS, vssd_assoc_info -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. - exp_len = 1 +def verify_vssdc_assoc(server, virt, cs_class, vssd_assoc_info, dom_cs): + try: + # 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, cn, an, + cs_class, instid) + if status != PASS: + raise Exception("Failed to get assoc info for dom: %s", test_dom) - if check_len(an, assoc_info, qcn, exp_len) != PASS: + # 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: %s", details) 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 + return status + @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) - if status != PASS: - return status + try: + status, vsxml = setup_env(server, virt) + if status != PASS: + return status - 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 + qcn = 'Logical Devices' + rasd_val, status = init_rasd_list(virt, server) - # 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 + status, dom_cs, sd_info = get_cs_sysdev_info(server, virt, + qcn, rasd_val) + if status != PASS: + raise Exception("Failed to get SystemDevice information") - 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 + cs_class = dom_cs.CreationClassName - # 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 + status, sds_info = get_sds_info(server, virt, cs_class, rasd_val, + sd_info, qcn) + if status != PASS: + raise Exception("Failed to get SetingDefineState information") - # 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) + status, vssd_assoc_info = get_vssd_info(server, virt, sds_info, qcn) if status != PASS: - break - if status != PASS: - vsxml.destroy(server) - return status + raise Exception("Failed to get VSSD information") - # 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 + status = verify_vssdc_assoc(server, virt, cs_class, + vssd_assoc_info, dom_cs) - # 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) - vsxml.destroy(server) + except Exception, details: + logger.error("Exception details is %s", details) + status = FAIL + + vsxml.cim_destroy(server) + vsxml.undefine(server) return status if __name__ == "__main__": sys.exit(main())