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

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1212719310 25200 # Node ID 6fe68391f0c820e815251022bfe8469a0a93115b # Parent 27d89d4b1ea884a49da6ce4fd93e0f7c71a6b36b 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 27d89d4b1ea8 -r 6fe68391f0c8 suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Fri Jul 11 13:26:03 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

Yes thats correct. +1 for me . Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1212719310 25200 # Node ID 6fe68391f0c820e815251022bfe8469a0a93115b # Parent 27d89d4b1ea884a49da6ce4fd93e0f7c71a6b36b 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 27d89d4b1ea8 -r 6fe68391f0c8 suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Fri Jul 11 13:26:03 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
_______________________________________________ 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 ee18f55760d08d21cd8f9809293d972b4a0b4549 # Parent 6fe68391f0c820e815251022bfe8469a0a93115b [TEST] 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. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 6fe68391f0c8 -r ee18f55760d0 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,7 @@ import pywbem from pywbem.cim_obj import CIMInstanceName from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import PASS def AssociatorNames(host, basetype, baseobj, virt="Xen", **keys): '''Resolve the association specified by @type, given the @@ -139,3 +140,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 +

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID ee18f55760d08d21cd8f9809293d972b4a0b4549 # Parent 6fe68391f0c820e815251022bfe8469a0a93115b [TEST] 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.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 6fe68391f0c8 -r ee18f55760d0 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,7 @@ import pywbem from pywbem.cim_obj import CIMInstanceName from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import PASS
Need to import logger. otherwise +1 for me. I liked the approach. :)
def AssociatorNames(host, basetype, baseobj, virt="Xen", **keys): '''Resolve the association specified by @type, given the @@ -139,3 +140,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

--- 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,7 @@ import pywbem from pywbem.cim_obj import CIMInstanceName from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import PASS
Need to import logger. otherwise +1 for me. I liked the approach. :)
Oops, I originally had this function in the test case, and I tested the failure path there. I forgot to retest the failure path when I moved the function to assoc.py. Thanks! -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 463274d67d8f35ac562c5665e561ab970ddc55c1 # Parent ee18f55760d08d21cd8f9809293d972b4a0b4549 [TEST] 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. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r ee18f55760d0 -r 463274d67d8f 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())

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 463274d67d8f35ac562c5665e561ab970ddc55c1 # Parent ee18f55760d08d21cd8f9809293d972b4a0b4549 [TEST] 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.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r ee18f55760d0 -r 463274d67d8f 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)
I think you need to uncomment this ? otherwise +1 for me.
+ 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

+ + 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)
I think you need to uncomment this ? otherwise +1 for me.
Good catch! Yes, I had this commented out for testing purposes. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1215806699 25200 # Node ID 463274d67d8f35ac562c5665e561ab970ddc55c1 # Parent ee18f55760d08d21cd8f9809293d972b4a0b4549 [TEST] 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.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r ee18f55760d0 -r 463274d67d8f 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 +
The above function can be moved to a library . We can probably pass the key_list to get_inst() fn.
+ +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())
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

+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 +
The above function can be moved to a library . We can probably pass the key_list to get_inst() fn.
I think I'll leave this as is. Having a getInstance() function, and then another, similar, get_inst() function is confusing. The only thing this function adds is trapping of the exception and some additional error checking. It's not much extra work to have the test case trap the exception and test for error conditions. It's possible that the calling function will want to trap the exception differently or return a different error message. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B Kalakeri
-
Kaitlin Rupert