[PATCH 0 of 3] [TEST] #2 Fix test issues with ESD 01

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1212719310 25200 # Node ID 7ea2f4ed91cd8b69bc0b8c34304cf3ef870a1b05 # Parent 8f450e62922d9b07896c2c505ae0b565a4097c9c Fix getInstance in enumclass.py to return matching type on error. getInstance() returns a single element, so if the call encounters an error, it should return None instead of []. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 8f450e62922d -r 7ea2f4ed91cd suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Mon Jul 14 09:09:29 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Thu Jun 05 19:28:30 2008 -0700 @@ -320,6 +320,6 @@ except pywbem.CIMError, arg: print arg[1] - return [] + return None return inst

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 30509a2ca9f2c68bf925f0d5fa2a3a65c602073f # Parent 7ea2f4ed91cd8b69bc0b8c34304cf3ef870a1b05 [TEST] #2 Add compare_all_prop(). This function takes an instance from the list returned bu the Associators() call and an instance from a getInstance() / enumerate_instances() call. It compares all of the property values to ensure the instances are identical. This function could probably be added to a fair number of tests as an additional verification check. Updates from 1 to 2: -Added logger import statement -Included FAIL in the ReturnCodes import. -Tested failure path to be sure error message is logged and FAIL is returned properly. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 7ea2f4ed91cd -r 30509a2ca9f2 suites/libvirt-cim/lib/XenKvmLib/assoc.py --- a/suites/libvirt-cim/lib/XenKvmLib/assoc.py Thu Jun 05 19:28:30 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/assoc.py Fri Jul 11 13:04:59 2008 -0700 @@ -27,6 +27,8 @@ import pywbem from pywbem.cim_obj import CIMInstanceName from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import PASS, FAIL +from CimTest.Globals import logger def AssociatorNames(host, basetype, baseobj, virt="Xen", **keys): '''Resolve the association specified by @type, given the @@ -139,3 +141,17 @@ return new_list +def compare_all_prop(inst, exp_inst): + prop_vals = inst.items() + + for i in range(0, len(prop_vals)): + key = prop_vals[i][0] + val = eval('exp_inst.' + key) + + if prop_vals[i][1] != val: + logger.error("%s val mismatch: got %s, expected %s" % (key, + prop_vals[i][1], val)) + return FAIL + + return PASS +

+1 from me Best, Regards Daisy (运国莲) VSM Team, China Systems & Technology Labs (CSTL) E-mail: yunguol@cn.ibm.com TEL: (86)-21-60922144 Building 10, 399 Ke Yuan Rd, Pudong Shanghai, 201203 libvirt-cim-bounces@redhat.com wrote on 2008-07-16 00:10:46:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 30509a2ca9f2c68bf925f0d5fa2a3a65c602073f # Parent 7ea2f4ed91cd8b69bc0b8c34304cf3ef870a1b05 [TEST] #2 Add compare_all_prop().
This function takes an instance from the list returned bu the Associators() call and an instance from a getInstance() / enumerate_instances() call. It compares all of the property values to ensure the instances are identical.
This function could probably be added to a fair number of tests as an additional verification check.
Updates from 1 to 2: -Added logger import statement -Included FAIL in the ReturnCodes import. -Tested failure path to be sure error message is logged and FAIL is returned properly.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 7ea2f4ed91cd -r 30509a2ca9f2 suites/libvirt-cim/lib/XenKvmLib/assoc.py --- a/suites/libvirt-cim/lib/XenKvmLib/assoc.py Thu Jun 05 19:28: 30 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/assoc.py Fri Jul 11 13:04: 59 2008 -0700 @@ -27,6 +27,8 @@ import pywbem from pywbem.cim_obj import CIMInstanceName from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import PASS, FAIL +from CimTest.Globals import logger
def AssociatorNames(host, basetype, baseobj, virt="Xen", **keys): '''Resolve the association specified by @type, given the @@ -139,3 +141,17 @@
return new_list
+def compare_all_prop(inst, exp_inst): + prop_vals = inst.items() + + for i in range(0, len(prop_vals)): + key = prop_vals[i][0] + val = eval('exp_inst.' + key) + + if prop_vals[i][1] != val: + logger.error("%s val mismatch: got %s, expected %s" % (key, + prop_vals[i][1], val)) + return FAIL + + return PASS +
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 7e91a4012131a1200f9d25711061a61f009bb4bc # Parent 30509a2ca9f2c68bf925f0d5fa2a3a65c602073f [TEST] #2 Fix potiential false positive in ESD 01. Test needs to verify the number of VSSD and RASD elemnts returned were the values expected. Instead of calling EnumerateInstances() for the VSSD and RASD instances, this test should call getInstance() to get the expected instances. Most of this test was written to support that. Test now also supports XenFV. Updates 1 to 2: -Uncomment cxml.undefine() on line 147. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 30509a2ca9f2 -r 7e91a4012131 suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py --- a/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Fri Jul 11 13:04:59 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Fri Jul 11 13:04:59 2008 -0700 @@ -49,82 +49,114 @@ import sys from VirtLib import utils -from XenKvmLib import enumclass -from XenKvmLib import assoc -from XenKvmLib.classes import get_class_basename -from CimTest import Globals -from CimTest.Globals import do_main +from XenKvmLib.enumclass import getInstance +from XenKvmLib.assoc import Associators, compare_all_prop +from XenKvmLib.classes import get_typed_class +from CimTest.Globals import do_main, logger, CIM_ERROR_ASSOCIATORS +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.vxml import get_class +from XenKvmLib import const -sup_types = ['Xen', 'KVM', 'LXC'] -esd_cn = 'ElementSettingData' -vssd_cn = 'VirtualSystemSettingData' -vssdc_cn = 'VirtualSystemSettingDataComponent' -rasd_cn = 'ResourceAllocationSettingData' +sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] -def test_assoc(host, class_name, id, virt): +test_dom = "esd_dom" +vmac = "00:11:22:33:44:aa" + +def get_inst(ip, virt, cn, key): + inst = None + try: - ret_inst = assoc.AssociatorNames(host,esd_cn, class_name, virt, - InstanceID = id) + key_list = {"InstanceID" : key } + + inst = getInstance(ip, cn, key_list, virt) + + except Exception, details: + logger.error("Exception %s" % details) + return None + + if inst is None: + logger.error("Expected at least one %s instance" % cn) + return None + + return inst + + +def test_assoc(host, acn, cn, virt, inst): + id = inst.InstanceID + + try: + ret_inst = Associators(host, acn, cn, virt, InstanceID=id) + except Exception: - Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, esd_cn) - return 1 + logger.error(CIM_ERROR_ASSOCIATORS, acn) + return FAIL if len(ret_inst) != 1: - Globals.logger.error("%s returned %i %s instances", esd_cn, - len(ret_inst), class_name) - return 1 + logger.error("%s returned %i %s instances" % (an, len(ret_inst), cn)) + return FAIL - ret_id = ret_inst[0].keybindings["InstanceID"] + ret_id = ret_inst[0]['InstanceID'] if ret_id != id: - Globals.logger.error("%s returned %s instance with wrong id %s", - esd_cn, class_name, ret_id) - return 1 + logger.error("%s returned %s inst with wrong id %s" % (acn, cn, ret_id)) + return FAIL - return 0; + status = compare_all_prop(ret_inst[0], inst) + + return status @do_main(sup_types) def main(): options = main.options - try: - key_list = ["InstanceID"] - vssd_lst = enumclass.enumerate(options.ip, vssd_cn, key_list, - options.virt) + esd_cn = 'ElementSettingData' - except Exception, details: - Globals.logger.error("Exception %s", details) - return 1 + if options.virt == 'XenFV': + virt_type = 'Xen' + else: + virt_type = options.virt - for vssd in vssd_lst: + keys = { 'VirtualSystemSettingData' : "%s:%s" % (virt_type, test_dom), + 'MemResourceAllocationSettingData' : "%s/mem" % test_dom, + } + - rc = test_assoc(options.ip, vssd_cn, vssd.InstanceID, options.virt) - if rc != 0: - Globals.logger.error("Unable to get associated %s from %s", - vssd_cn, esd_cn) - return 1 + if options.virt == "Xen": + vdisk = "xvda" + else: + vdisk = "hda" + + virt_class = get_class(options.virt) + if options.virt == 'LXC': + cxml = virt_class(test_dom) + else: + cxml = virt_class(test_dom, mac = vmac, disk = vdisk) + keys['ProcResourceAllocationSettingData'] = "%s/proc" % test_dom + keys['DiskResourceAllocationSettingData'] = "%s/%s" % (test_dom, vdisk) + keys['NetResourceAllocationSettingData'] = "%s/%s" % (test_dom, vmac) + + ret = cxml.define(options.ip) + if not ret: + logger.error("Failed to define the dom: %s", test_dom) + return FAIL + + inst_list = {} + + for cn, k in keys.iteritems(): + inst_list[cn] = get_inst(options.ip, options.virt, cn, k) + if inst_list[cn] is None: + cxml.undefine(options.ip) + return FAIL + + status = FAIL + for cn, inst in inst_list.iteritems(): + status = test_assoc(options.ip, esd_cn, cn, options.virt, inst) + if status != PASS: + logger.error("Unable to get %s insts from %s" % (cn, esd_cn)) + break - try: - rasd_list = assoc.Associators(options.ip, vssdc_cn, vssd_cn, - options.virt, - InstanceID = vssd.InstanceID) - except Exception: - Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, vssdc_cn) - return 1 - - if len(rasd_list) == 0: - Globals.logger.error("%s returned %i %s instances", esd_cn, - len(rasd_list), vssd_cn) - return 1 - - for rasd in rasd_list: - rc = test_assoc(options.ip, get_class_basename(rasd.classname), - rasd["InstanceID"], options.virt) - if rc != 0: - Globals.logger.error("Unable to get associated %s from %s", - rasd_cn, esd_cn) - return 1 + cxml.undefine(options.ip) - return 0 + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 7e91a4012131a1200f9d25711061a61f009bb4bc # Parent 30509a2ca9f2c68bf925f0d5fa2a3a65c602073f [TEST] #2 Fix potiential false positive in ESD 01.
Test needs to verify the number of VSSD and RASD elemnts returned were the values expected.
Instead of calling EnumerateInstances() for the VSSD and RASD instances, this test should call getInstance() to get the expected instances. Most of this test was written to support that.
Test now also supports XenFV.
Updates 1 to 2: -Uncomment cxml.undefine() on line 147.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 30509a2ca9f2 -r 7e91a4012131 suites/libvirt- cim/cimtest/ElementSettingData/01_forward.py --- a/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Fri Jul 11 13:04:59 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Fri Jul 11 13:04:59 2008 -0700 @@ -49,82 +49,114 @@
import sys from VirtLib import utils -from XenKvmLib import enumclass -from XenKvmLib import assoc -from XenKvmLib.classes import get_class_basename -from CimTest import Globals -from CimTest.Globals import do_main +from XenKvmLib.enumclass import getInstance +from XenKvmLib.assoc import Associators, compare_all_prop +from XenKvmLib.classes import get_typed_class +from CimTest.Globals import do_main, logger, CIM_ERROR_ASSOCIATORS +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.vxml import get_class +from XenKvmLib import const
-sup_types = ['Xen', 'KVM', 'LXC'] -esd_cn = 'ElementSettingData' -vssd_cn = 'VirtualSystemSettingData' -vssdc_cn = 'VirtualSystemSettingDataComponent' -rasd_cn = 'ResourceAllocationSettingData' +sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
-def test_assoc(host, class_name, id, virt): +test_dom = "esd_dom" +vmac = "00:11:22:33:44:aa" + +def get_inst(ip, virt, cn, key): + inst = None + try: - ret_inst = assoc.AssociatorNames(host,esd_cn, class_name, virt, - InstanceID = id) + key_list = {"InstanceID" : key } + + inst = getInstance(ip, cn, key_list, virt) + + except Exception, details: + logger.error("Exception %s" % details) + return None + + if inst is None: + logger.error("Expected at least one %s instance" % cn) + return None + + return inst + + +def test_assoc(host, acn, cn, virt, inst): + id = inst.InstanceID + + try: + ret_inst = Associators(host, acn, cn, virt, InstanceID=id) + except Exception: - Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, esd_cn) - return 1 + logger.error(CIM_ERROR_ASSOCIATORS, acn) + return FAIL
if len(ret_inst) != 1: - Globals.logger.error("%s returned %i %s instances", esd_cn, - len(ret_inst), class_name) - return 1 + logger.error("%s returned %i %s instances" % (an, len(ret_inst), cn)) + return FAIL
- ret_id = ret_inst[0].keybindings["InstanceID"] + ret_id = ret_inst[0]['InstanceID'] if ret_id != id: - Globals.logger.error("%s returned %s instance with wrong id %s", - esd_cn, class_name, ret_id) - return 1 + logger.error("%s returned %s inst with wrong id %s" % (acn, cn, ret_id)) + return FAIL
- return 0; + status = compare_all_prop(ret_inst[0], inst) + + return status
@do_main(sup_types) def main(): options = main.options
- try: - key_list = ["InstanceID"] - vssd_lst = enumclass.enumerate(options.ip, vssd_cn, key_list, - options.virt) + esd_cn = 'ElementSettingData'
- except Exception, details: - Globals.logger.error("Exception %s", details) - return 1 + if options.virt == 'XenFV': + virt_type = 'Xen' + else: + virt_type = options.virt
- for vssd in vssd_lst: + keys = { 'VirtualSystemSettingData' : "%s:%s" % (virt_type, test_dom), + 'MemResourceAllocationSettingData' : "%s/mem" % test_dom, + } +
- rc = test_assoc(options.ip, vssd_cn, vssd.InstanceID,
+1 from me. Best, Regards Daisy (运国莲) VSM Team, China Systems & Technology Labs (CSTL) E-mail: yunguol@cn.ibm.com TEL: (86)-21-60922144 Building 10, 399 Ke Yuan Rd, Pudong Shanghai, 201203 libvirt-cim-bounces@redhat.com wrote on 2008-07-16 00:10:47: options.virt)
- if rc != 0: - Globals.logger.error("Unable to get associated %s from %s", - vssd_cn, esd_cn) - return 1 + if options.virt == "Xen": + vdisk = "xvda" + else: + vdisk = "hda" + + virt_class = get_class(options.virt) + if options.virt == 'LXC': + cxml = virt_class(test_dom) + else: + cxml = virt_class(test_dom, mac = vmac, disk = vdisk) + keys['ProcResourceAllocationSettingData'] = "%s/proc" % test_dom + keys['DiskResourceAllocationSettingData'] = "%s/%s" % (test_dom, vdisk) + keys['NetResourceAllocationSettingData'] = "%s/%s" % (test_dom, vmac) + + ret = cxml.define(options.ip) + if not ret: + logger.error("Failed to define the dom: %s", test_dom) + return FAIL + + inst_list = {} + + for cn, k in keys.iteritems(): + inst_list[cn] = get_inst(options.ip, options.virt, cn, k) + if inst_list[cn] is None: + cxml.undefine(options.ip) + return FAIL + + status = FAIL + for cn, inst in inst_list.iteritems(): + status = test_assoc(options.ip, esd_cn, cn, options.virt, inst) + if status != PASS: + logger.error("Unable to get %s insts from %s" % (cn, esd_cn)) + break
- try: - rasd_list = assoc.Associators(options.ip, vssdc_cn, vssd_cn, - options.virt, - InstanceID = vssd.InstanceID) - except Exception: - Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, vssdc_cn) - return 1 - - if len(rasd_list) == 0: - Globals.logger.error("%s returned %i %s instances", esd_cn, - len(rasd_list), vssd_cn) - return 1 - - for rasd in rasd_list: - rc = test_assoc(options.ip, get_class_basename(rasd.classname), - rasd["InstanceID"], options.virt) - if rc != 0: - Globals.logger.error("Unable to get associated %s from %s", - rasd_cn, esd_cn) - return 1 + cxml.undefine(options.ip)
- return 0 + return status
if __name__ == "__main__": sys.exit(main())
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (2)
-
Guo Lian Yun
-
Kaitlin Rupert