[PATCH] [TEST] Fixing the 01_verify_rasd_fields.py tc of RASD

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1230542050 28800 # Node ID 3d716a88ae175ef1f19cc1c55addfb3fcdbcb18e # Parent b7d80fdeb2a3318749f0faa4b2ad9725da97cc56 [TEST] Fixing the 01_verify_rasd_fields.py tc of RASD. Tested for KVM, Xen, LXC with current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r b7d80fdeb2a3 -r 3d716a88ae17 suites/libvirt-cim/cimtest/RASD/01_verify_rasd_fields.py --- a/suites/libvirt-cim/cimtest/RASD/01_verify_rasd_fields.py Mon Dec 22 23:03:01 2008 -0800 +++ b/suites/libvirt-cim/cimtest/RASD/01_verify_rasd_fields.py Mon Dec 29 01:14:10 2008 -0800 @@ -47,18 +47,14 @@ import sys -from CimTest import Globals from XenKvmLib.const import do_main -from XenKvmLib.test_doms import destroy_and_undefine_all from XenKvmLib import assoc from XenKvmLib import vxml from XenKvmLib.classes import get_typed_class -from XenKvmLib import rasd -from CimTest.Globals import logger +from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORS 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.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] @@ -67,74 +63,82 @@ test_mem = 128 test_mac = "00:11:22:33:44:aa" -def assoc_values(assoc_info, xml, disk, virt="Xen"): - status, rasd_values, in_list = rasd_init_list(xml, virt, disk, test_dom, - test_mac, test_mem) +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 + + 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_rasd(virt, ip, assoc_info): + rasds, status = init_rasd_list(virt, ip) if status != PASS: return status - - procrasd = rasd_values['%s' %in_list['proc']] - netrasd = rasd_values['%s' %in_list['net']] - diskrasd = rasd_values['%s' %in_list['disk']] - memrasd = rasd_values['%s' %in_list['mem']] - if virt == 'LXC': - proc_status = 0 - disk_status = 0 - else: - proc_status = 1 - disk_status = 1 + if len(assoc_info) != len(rasds): + logger.error("%d assoc_info != %d RASD insts", + len(assoc_info), len(rasds)) + return FAIL - net_status = 0 - mem_status = 1 - status = 0 - try: - for res in assoc_info: - if res['InstanceID'] == procrasd['InstanceID']: - proc_status = rasd.verify_procrasd_values(res, procrasd) - elif res['InstanceID'] == netrasd['InstanceID']: - net_status = rasd.verify_netrasd_values(res, netrasd) - elif res['InstanceID'] == diskrasd['InstanceID']: - disk_status = rasd.verify_diskrasd_values(res, diskrasd) - elif res['InstanceID'] == memrasd['InstanceID']: - mem_status = rasd.verify_memrasd_values(res, memrasd) + for rasd in assoc_info: + guest, dev, status = parse_instance_id(rasd['InstanceID']) + if status != PASS: + logger.error("Unable to parse InstanceID: %s", rasd['InstanceID']) + return status + + if guest != test_dom: + continue + + logger.info("Verifying: %s", rasd.classname) + exp_rasd = rasds[rasd.classname] + for item in rasd.items(): + key = item[0] + exp_val = eval('exp_rasd.' + key) + ret_rasd_val = rasd[key] + if ret_rasd_val == exp_val: + status = PASS else: - status = 1 - if status != 0 or proc_status != 0 or net_status != 0 or \ - disk_status != 0 or mem_status != 0 : - logger.error("Mistmatching association values" ) - status = 1 - except Exception, detail : - logger.error("Exception in assoc_values function: %s" % detail) - status = 1 - - return status - + logger.info("Got %s instead of %s", ret_rasd_val, exp_val) + status = FAIL + break + + if status != PASS: + logger.error("RASD with id %s not returned", exp_rasd.InstanceID) + return FAIL + + return PASS + @do_main(sup_types) def main(): options = main.options virt = options.virt - status = PASS - - destroy_and_undefine_all(options.ip) - if virt == 'Xen': - test_disk = 'xvda' - else: - test_disk = 'hda' + server = options.ip + status = FAIL virt_xml = vxml.get_class(virt) if virt == 'LXC': cxml = virt_xml(test_dom) else: cxml = virt_xml(test_dom, mem=test_mem, vcpus = test_vcpus, - mac = test_mac, disk = test_disk) - ret = cxml.create(options.ip) + mac = test_mac) + + ret = cxml.create(server) if not ret: logger.error('Unable to create domain %s' % test_dom) return FAIL - if status == 1: - destroy_and_undefine_all(options.ip) - return FAIL + if virt == "XenFV": instIdval = "Xen:%s" % test_dom else: @@ -143,20 +147,15 @@ vssdc_cn = get_typed_class(virt, 'VirtualSystemSettingDataComponent') vssd_cn = get_typed_class(virt, 'VirtualSystemSettingData') try: - assoc_info = assoc.Associators(options.ip, vssdc_cn, vssd_cn, + assoc_info = assoc.Associators(server, vssdc_cn, vssd_cn, InstanceID = instIdval) - status = assoc_values(assoc_info, cxml, test_disk, virt) + status = verify_rasd(virt, server, assoc_info) except Exception, details: - logger.error(Globals.CIM_ERROR_ASSOCIATORS, - get_typed_class(virt, vssdc_cn)) + logger.error(CIM_ERROR_ASSOCIATORS, vssdc_cn) logger.error("Exception : %s" % details) status = FAIL - - try: - cxml.destroy(options.ip) - cxml.undefine(options.ip) - except Exception: - logger.error("Destroy or undefine domain failed") + + cxml.destroy(server) return status if __name__ == "__main__":

import sys -from CimTest import Globals from XenKvmLib.const import do_main -from XenKvmLib.test_doms import destroy_and_undefine_all from XenKvmLib import assoc from XenKvmLib import vxml
Change this to XenKvmLib.vxml import get_class
+ for rasd in assoc_info: + guest, dev, status = parse_instance_id(rasd['InstanceID']) + if status != PASS: + logger.error("Unable to parse InstanceID: %s", rasd['InstanceID']) + return status + + if guest != test_dom: + continue
Instead of a continue here, this should throw an error. VirtualSystemSettingDataComponent should only return RASDs that correspond to a give VSSD. And a VSSD instance can only represent one guest. This is a mistake I made in SettingsDefine/02_reverse.py, which is the test I told you to reference. Sorry for the error here! I'll send a patch to fix this bug. Really, we don't need to do this check at all. When I was re-writing SettingsDefine/02_reverse.py, I was thinking that it is a good idea to verify that the RASDs match the guest we're testing. But really, if VirtualSystemSettingDataComponent returns the wrong instances, that's something the VirtualSystemSettingDataComponent related tests should find. This test should be concerned with verifying the RASD properties, it shouldn't be concerned with also verifying the output of VirtualSystemSettingDataComponent. But it's still a valid check to have. So you can leave it in or remove it. Either way is fine by me. =)
+ + logger.info("Verifying: %s", rasd.classname) + exp_rasd = rasds[rasd.classname] + for item in rasd.items(): + key = item[0] + exp_val = eval('exp_rasd.' + key) + ret_rasd_val = rasd[key] + if ret_rasd_val == exp_val: + status = PASS
Will compare_all_prop() work for this? When we spoke, I said that compare_all_prop() should be phased out once the association related calls return the same object type as the enumeration related calls. However, since the the return types of the enumeration calls and the association calls don't match yet, I'd rather compare_all_prop() be used instead of duplicating the code here. When it comes time to remove compare_all_prop(), it's easier to replace the function name than it is to replace an entire code block. Sorry for the confusion there.
else: - status = 1 - if status != 0 or proc_status != 0 or net_status != 0 or \ - disk_status != 0 or mem_status != 0 : - logger.error("Mistmatching association values" ) - status = 1 - except Exception, detail : - logger.error("Exception in assoc_values function: %s" % detail) - status = 1 - - return status - + logger.info("Got %s instead of %s", ret_rasd_val, exp_val) + status = FAIL + break + + if status != PASS: + logger.error("RASD with id %s not returned", exp_rasd.InstanceID)
This message is misleading.. because you verify all the properties. So even if the InstanceID matches, one of the other properties could be different. I would use a more generic message to indicate that a matching RASD wasn't found. The providers shouldn't return more than one RASD with the same InstanceID. But it's possible it could happen in some kind of odd error condition.
virt_xml = vxml.get_class(virt) if virt == 'LXC': cxml = virt_xml(test_dom) else: cxml = virt_xml(test_dom, mem=test_mem, vcpus = test_vcpus, - mac = test_mac, disk = test_disk) - ret = cxml.create(options.ip) + mac = test_mac) + + ret = cxml.create(server)
Can you change this to define() and cim_start().
if not ret: logger.error('Unable to create domain %s' % test_dom) return FAIL - if status == 1: - destroy_and_undefine_all(options.ip) - return FAIL
status = FAIL - - try: - cxml.destroy(options.ip) - cxml.undefine(options.ip) - except Exception: - logger.error("Destroy or undefine domain failed") + + cxml.destroy(server)
Add an undefine() here. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

import sys -from CimTest import Globals from XenKvmLib.const import do_main -from XenKvmLib.test_doms import destroy_and_undefine_all from XenKvmLib import assoc from XenKvmLib import vxml
Change this to XenKvmLib.vxml import get_class
+ for rasd in assoc_info: + guest, dev, status = parse_instance_id(rasd['InstanceID']) + if status != PASS: + logger.error("Unable to parse InstanceID: %s", rasd['InstanceID']) + return status + + if guest != test_dom: + continue
Instead of a continue here, this should throw an error.
VirtualSystemSettingDataComponent should only return RASDs that correspond to a give VSSD. And a VSSD instance can only represent one guest.
This is a mistake I made in SettingsDefine/02_reverse.py, which is the test I told you to reference. Sorry for the error here! I'll send a patch to fix this bug.
Really, we don't need to do this check at all. When I was re-writing SettingsDefine/02_reverse.py, I was thinking that it is a good idea to verify that the RASDs match the guest we're testing.
But really, if VirtualSystemSettingDataComponent returns the wrong instances, that's something the VirtualSystemSettingDataComponent related tests should find. This test should be concerned with verifying the RASD properties, it shouldn't be concerned with also verifying the output of VirtualSystemSettingDataComponent.
But it's still a valid check to have. So you can leave it in or remove it. Either way is fine by me. =) Yesthis is true. For now I have left the above check as it is, since the VSSDC test cases does not verify this as of now.
+ + logger.info("Verifying: %s", rasd.classname) + exp_rasd = rasds[rasd.classname] + for item in rasd.items(): + key = item[0] + exp_val = eval('exp_rasd.' + key) + ret_rasd_val = rasd[key] + if ret_rasd_val == exp_val: + status = PASS
Will compare_all_prop() work for this? When we spoke, I said that compare_all_prop() should be phased out once the association related calls return the same object type as the enumeration related calls.
However, since the the return types of the enumeration calls and the association calls don't match yet, I'd rather compare_all_prop() be used instead of duplicating the code here. When it comes time to remove compare_all_prop(), it's easier to replace the function name than it is to replace an entire code block.
Sorry for the confusion there. I thought since we plan to remove the compare_all_prop() sometime and since it is used in very few place, I wrote this above piece of code in
Kaitlin Rupert wrote: the tc itself. I have changed the above to use compare_all_prop().
else: - status = 1 - if status != 0 or proc_status != 0 or net_status != 0 or \ - disk_status != 0 or mem_status != 0 : - logger.error("Mistmatching association values" ) - status = 1 - except Exception, detail : - logger.error("Exception in assoc_values function: %s" % detail) - status = 1 - - return status - + logger.info("Got %s instead of %s", ret_rasd_val, exp_val) + status = FAIL + break + + if status != PASS: + logger.error("RASD with id %s not returned", exp_rasd.InstanceID)
This message is misleading.. because you verify all the properties. So even if the InstanceID matches, one of the other properties could be different. I would use a more generic message to indicate that a matching RASD wasn't found.
The providers shouldn't return more than one RASD with the same InstanceID. But it's possible it could happen in some kind of odd error condition.
virt_xml = vxml.get_class(virt) if virt == 'LXC': cxml = virt_xml(test_dom) else: cxml = virt_xml(test_dom, mem=test_mem, vcpus = test_vcpus, - mac = test_mac, disk = test_disk) - ret = cxml.create(options.ip) + mac = test_mac) + + ret = cxml.create(server)
Can you change this to define() and cim_start().
Should have noticed this before itself. Changed the tc to use define and start now. Thanks and Regards, Deepti.
participants (3)
-
Deepti B Kalakeri
-
Deepti B. Kalakeri
-
Kaitlin Rupert