[PATCH 0 of 4] [TEST] HostedDependency KVM support

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208313842 -28800 # Node ID a5730873a2d21e18f8f843b1ffe34daa7aa99f53 # Parent a2a1ad930edf17836a46abe2af08ef6fc9af5d30 [TEST] Add KVM support for HostedDependency.01 Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r a2a1ad930edf -r a5730873a2d2 suites/libvirt-cim/cimtest/HostedDependency/01_forward.py --- a/suites/libvirt-cim/cimtest/HostedDependency/01_forward.py Wed Apr 16 10:44:02 2008 +0800 +++ b/suites/libvirt-cim/cimtest/HostedDependency/01_forward.py Wed Apr 16 10:44:02 2008 +0800 @@ -45,16 +45,17 @@ import sys import pywbem -from XenKvmLib.test_xml import testxml from VirtLib import utils +from XenKvmLib import vxml from XenKvmLib import computersystem from XenKvmLib import assoc -from XenKvmLib.test_doms import test_domain_function from XenKvmLib import hostsystem +from XenKvmLib.classes import get_class_basename from CimTest import Globals from CimTest.Globals import do_main +from CimTest.ReturnCodes import PASS, FAIL -sup_types = ['Xen'] +sup_types = ['Xen', 'KVM'] test_dom = "hd_domain" test_mac = "00:11:22:33:44:55" @@ -62,78 +63,79 @@ test_mac = "00:11:22:33:44:55" @do_main(sup_types) def main(): options = main.options - status = 0 + status = PASS Globals.log_param() - test_xml = testxml(test_dom, mac = test_mac) - ret = test_domain_function(test_xml, options.ip, cmd = "define") + virtxml = vxml.get_class(options.virt) + cxml = virtxml(test_dom, mac = test_mac) + ret = cxml.define(options.ip) if not ret: Globals.logger.error("Failed to Create the dom: %s", test_dom) - status = 1 + status = FAIL return status try: - host = hostsystem.enumerate(options.ip)[0] + host = hostsystem.enumerate(options.ip, options.virt)[0] except Exception,detail: - Globals.logger.error(Globals.CIM_ERROR_ENUMERATE, 'Xen_Hostsystem') + Globals.logger.error(Globals.CIM_ERROR_ENUMERATE, 'Hostsystem') Globals.logger.error("Exception: %s", detail) - status = 1 + status = FAIL + cxml.undefine(options.ip) return status try: - cs = computersystem.enumerate(options.ip) + cs = computersystem.enumerate(options.ip, options.virt) except Exception,detail: - Globals.logger.error(Globals.CIM_ERROR_ENUMERATE, 'Xen_ComputerSystem') + Globals.logger.error(Globals.CIM_ERROR_ENUMERATE, 'ComputerSystem') Globals.logger.error("Exception: %s", detail) - status = 1 + status = FAIL + cxml.undefine(options.ip) return status + hs_cn = "HostedDependency" try: for system in cs: - hs = assoc.Associators(options.ip, - "Xen_HostedDependency", - system.CreationClassName, - CreationClassName = system.CreationClassName, + ccn = get_class_basename(system.CreationClassName) + hs = assoc.Associators(options.ip, hs_cn, ccn, options.virt, + CreationClassName=system.CreationClassName, Name=system.name) if not hs: - ret = test_domain_function(test_dom, options.ip, \ - cmd = "undefine") + cxml.undefine(options.ip) Globals.logger.error("HostName seems to be empty") - status = 1 + status = FAIL break if len(hs) != 1: test = "(len(hs), system.name)" Globals.logger.error("HostedDependency returned %i HostSystem \ objects for domain '%s'", len(hs), system.name) - status = 1 + status = FAIL break - cn = hs[0]["CreationClassName"] - sn = hs[0]["Name"] + cn = hs[0]["CreationClassName"] + sn = hs[0]["Name"] if cn != host.CreationClassName: Globals.logger.error("CreationClassName does not match") - status = 1 + status = FAIL if sn != host.Name: Globals.logger.error("Name does not match") - status = 1 + status = FAIL if status != 0: break except Exception,detail: - Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, 'Xen_HostedDependency') + Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, hs_cn) Globals.logger.error("Exception: %s", detail) - status = 1 + status = FAIL + cxml.undefine(options.ip) return status - ret = test_domain_function(test_dom, options.ip, \ - cmd = "destroy") + cxml.undefine(options.ip) return status - if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208313843 -28800 # Node ID 29a35b835943eee34952e099797d03d5e89a923e # Parent a5730873a2d21e18f8f843b1ffe34daa7aa99f53 [TEST] Add KVM support HostedDependency.02 Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r a5730873a2d2 -r 29a35b835943 suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py --- a/suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py Wed Apr 16 10:44:02 2008 +0800 +++ b/suites/libvirt-cim/cimtest/HostedDependency/02_reverse.py Wed Apr 16 10:44:03 2008 +0800 @@ -41,15 +41,16 @@ # Date : 15-11-2007 import sys -from XenKvmLib.test_xml import testxml from VirtLib import utils +from XenKvmLib import vxml from XenKvmLib import hostsystem from XenKvmLib import computersystem from XenKvmLib import assoc -from XenKvmLib.test_doms import test_domain_function +from XenKvmLib.classes import get_class_basename from CimTest.Globals import log_param, logger, do_main +from CimTest.ReturnCodes import PASS, FAIL -sup_types = ['Xen'] +sup_types = ['Xen', 'KVM'] test_dom = "hd_domain" test_mac = "00:11:22:33:44:55" @@ -58,72 +59,65 @@ def main(): def main(): options = main.options log_param() - status = 0 + status = PASS - test_xml = testxml(test_dom, mac = test_mac) - ret = test_domain_function(test_xml, options.ip, cmd = "create") + virtxml = vxml.get_class(options.virt) + cxml = virtxml(test_dom, mac = test_mac) + ret = cxml.create(options.ip) if not ret: logger.error("ERROR: Failed to Create the dom: %s" % test_dom) - status = 1 + status = FAIL return status try: - host_sys = hostsystem.enumerate(options.ip) + host_sys = hostsystem.enumerate(options.ip, options.virt) if host_sys[0].Name == "": - ret = test_domain_function(test_dom, options.ip, \ - cmd = "destroy") - logger.error("ERROR: HostName seems to be empty") - status = 1 - return status + raise Exception("HostName seems to be empty") else: # Instance of the HostSystem host_sys = host_sys[0] - cs = computersystem.enumerate(options.ip) - # The len should be atleast two , bcs the CS returns info - # one regd VS and the other one for Dom-0 - if len(cs) < 2: - logger.error("ERROR: Wrong number of systems returned") - status = 1 - return status + cs = computersystem.enumerate(options.ip, options.virt) + if options.virt == 'Xen' or options.virt == 'XenFV': + # Xen honors additional domain-0 + cs_list_len = 2 + else: + cs_list_len = 1 + if len(cs) < cs_list_len: + raise Exception("Wrong number of systems returned") # Build a list of ComputerSystem names from the list returned from # ComputerSystem.EnumerateInstances() - cs_names = [] - for inst in cs: - cs_names.append(inst.name) - # Store the Creation classname - ccn = cs[0].CreationClassName + cs_names = [x.name for x in cs] # Get a list of ComputerSystem instances from the HostSystem instace host_ccn = host_sys.CreationClassName - systems = assoc.AssociatorNames(options.ip, - "Xen_HostedDependency", - host_ccn, - CreationClassName = host_ccn, + systems = assoc.AssociatorNames(options.ip, "HostedDependency", + get_class_basename(host_ccn), + options.virt, + CreationClassName=host_ccn, Name=host_sys.Name) # Compare each returned instance to make sure it's in the list # that ComputerSystem.EnumerateInstances() returned if len(systems) < 1: - logger.error("HostedDependency returned %d, expected at least 1" % - len(systems)) - test_domain_function(test_dom, options.ip, cmd = "destroy") - return 1 + raise Exception("HostedDependency returned %d, expected at least 1" % + len(systems)) + ccn = cs[0].CreationClassName for guest in systems: if guest["Name"] in cs_names: cs_names.remove(guest["Name"]) else: logger.error("HostedDependency returned unexpected guest %s" % guest["Name"]) - status = 1 + status = FAIL # checking the CreationClassName returned is Xen_ComputerSystem if ccn != guest["CreationClassName"]: logger.error("ERROR: CreationClassName does not match") - status = 1 + status = FAIL # Go through anything remaining in the # ComputerSystem.EnumerateInstances() list and complain about them @@ -132,12 +126,18 @@ def main(): for guest in cs_names: logger.error("HostedDependency did not return expected guest %s" % guest["Name"]) - status = 1 + status = FAIL except (UnboundLocalError, NameError), detail: logger.error("Exception: %s" % detail) + + except Exception, detail: + logger.error(detail) + status = FAIL - ret = test_domain_function(test_dom, options.ip, cmd = "destroy") + cxml.destroy(options.ip) + cxml.undefine(options.ip) return status + if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208313844 -28800 # Node ID 0b517aabe906fc9525c95d54ce6434d6c6790ce0 # Parent 29a35b835943eee34952e099797d03d5e89a923e [TEST] Add KVM support for HostedDependency.03 Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r 29a35b835943 -r 0b517aabe906 suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py --- a/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Wed Apr 16 10:44:03 2008 +0800 +++ b/suites/libvirt-cim/cimtest/HostedDependency/03_enabledstate.py Wed Apr 16 10:44:04 2008 +0800 @@ -32,19 +32,19 @@ import sys from time import sleep -from XenKvmLib.test_xml import testxml from VirtLib import utils +from XenKvmLib import vxml from XenKvmLib import computersystem from XenKvmLib import assoc from XenKvmLib.common_util import get_host_info -from XenKvmLib.test_doms import test_domain_function, destroy_and_undefine_all +from XenKvmLib.classes import get_class_basename from CimTest.Globals import log_param, logger, CIM_ERROR_ASSOCIATORS, \ CIM_ERROR_GETINSTANCE from CimTest.Globals import do_main from XenKvmLib.devices import CIM_Instance from CimTest.ReturnCodes import PASS, FAIL -sup_types = ['Xen'] +sup_types = ['Xen', 'KVM'] test_dom = "hd_domain1" test_mac = "00:11:22:33:44:55" @@ -62,7 +62,7 @@ def print_error(field, ret_val, req_val) logger.error("%s Mismatch", field) logger.error("Returned %s instead of %s", ret_val, req_val) -def poll_for_enabledstate_value(server): +def poll_for_enabledstate_value(server, virt): status = PASS dom_field_list = {} check_reqstate_value = None @@ -70,7 +70,8 @@ def poll_for_enabledstate_value(server): try: for i in range(1, (timeout + 1)): sleep(1) - dom_cs = computersystem.Xen_ComputerSystem(server, name=test_dom) + cs = computersystem.get_cs_class(virt) + dom_cs = cs(server, name=test_dom) if dom_cs.EnabledState == "" or dom_cs.CreationClassName == "" or \ dom_cs.Name == "" or dom_cs.RequestedState == "": logger.error("Empty EnabledState field.") @@ -83,7 +84,7 @@ def poll_for_enabledstate_value(server): break except Exception, detail: - logger.error(CIM_ERROR_GETINSTANCE, 'Xen_ComputerSystem') + logger.error(CIM_ERROR_GETINSTANCE, 'ComputerSystem') logger.error("Exception: %s" % detail) status = FAIL @@ -94,31 +95,39 @@ def poll_for_enabledstate_value(server): return status, dom_field_list +class HsError(Exception): + pass + @do_main(sup_types) def main(): options = main.options log_param() status = PASS - destroy_and_undefine_all(options.ip) - test_xml = testxml(test_dom, mac = test_mac) - ret = test_domain_function(test_xml, options.ip, cmd = "create") + virtxml = vxml.get_class(options.virt) + cxml = virtxml(test_dom, mac = test_mac) + + ret = cxml.create(options.ip) if not ret: logger.error("Failed to Create the dom: %s" % test_dom) status = FAIL return status - ret = test_domain_function(test_dom, options.ip, cmd = "suspend") + ret = cxml.run_virsh_cmd(options.ip, "suspend") if not ret: logger.error("Failed to suspend the dom: %s" % test_dom) + cxml.destroy(options.ip) + cxml.undefine(options.ip) status = FAIL return status - status, host_name, host_ccn = get_host_info(options.ip) + status, host_name, host_ccn = get_host_info(options.ip, options.virt) if status != PASS: - ret = test_domain_function(test_dom, options.ip, cmd = "destroy") + logger.error("Failed to get host info") + cxml.destroy(options.ip) + cxml.undefine(options.ip) return status try: @@ -128,25 +137,26 @@ def main(): #it does not get set immediatley to value of 9 when suspended. dom_field_list = {} - status, dom_field_list = poll_for_enabledstate_value(options.ip) + status, dom_field_list = poll_for_enabledstate_value(options.ip, + options.virt) if status != PASS or len(dom_field_list) == 0: - test_domain_function(test_dom, options.ip, cmd = "destroy") - return status + raise HsError("Failed to poll for enabled state value") - hs = assoc.Associators(options.ip, "Xen_HostedDependency", host_ccn, \ + hs = assoc.Associators(options.ip, "HostedDependency", + get_class_basename(host_ccn), options.virt, CreationClassName=host_ccn, Name=host_name) if len(hs) == 0: - logger.error("HostedDependency didn't return any instances.") - return FAIL + status = FAIL + raise HsError("HostedDependency didn't return any instances.") hs_field_list = [] - for i in range(len(hs)): - if hs[i]['Name'] == test_dom: - hs_field_list = create_list(CIM_Instance(hs[i])) + for hsi in hs: + if hsi['Name'] == test_dom: + hs_field_list = create_list(CIM_Instance(hsi)) if len(hs_field_list) == 0: - logger.error("Association did not return expected guest instance.") - return FAIL + status = FAIL + raise HsError("Association did not return expected guest instance.") if dom_field_list['CreationClassName'] != hs_field_list['CreationClassName']: print_error('CreationClassName', hs_field_list['CreationClassName'], \ @@ -165,12 +175,15 @@ def main(): print_error('EnabledState', hs_field_list['EnabledState'], \ dom_field_list['EnabledState']) status = FAIL + except HsError, detail: + logger.error(detail) except Exception, detail: - logger.error(CIM_ERROR_ASSOCIATORS,'Xen_HostedDependency') + logger.error(CIM_ERROR_ASSOCIATORS,'HostedDependency') logger.error("Exception: %s" % detail) status = FAIL - ret = test_domain_function(test_dom, options.ip, cmd = "destroy") + cxml.destroy(options.ip) + cxml.undefine(options.ip) return status if __name__ == "__main__": diff -r 29a35b835943 -r 0b517aabe906 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed Apr 16 10:44:03 2008 +0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed Apr 16 10:44:04 2008 +0800 @@ -136,7 +136,7 @@ def get_host_info(server, virt="Xen"): host_ccn = host_sys.CreationClassName host_name = host_sys.Name except Exception, detail: - logger.error(CIM_ERROR_ENUMERATE, 'Xen_HostSystem') + logger.error(CIM_ERROR_ENUMERATE, 'HostSystem') logger.error("Exception: %s", detail) status = FAIL return status, host_name, host_ccn

- hs = assoc.Associators(options.ip, "Xen_HostedDependency", host_ccn, \ + hs = assoc.Associators(options.ip, "HostedDependency", + get_class_basename(host_ccn), options.virt, CreationClassName=host_ccn, Name=host_name) if len(hs) == 0: - logger.error("HostedDependency didn't return any instances.") - return FAIL + status = FAIL
Instead of setting status = FAIL here, can you set this where you catch the exception? That way you only have to set it once and we can be sure we're setting the right return code.
+ raise HsError("HostedDependency didn't return any instances.")
hs_field_list = [] - for i in range(len(hs)): - if hs[i]['Name'] == test_dom: - hs_field_list = create_list(CIM_Instance(hs[i])) + for hsi in hs: + if hsi['Name'] == test_dom: + hs_field_list = create_list(CIM_Instance(hsi))
if len(hs_field_list) == 0: - logger.error("Association did not return expected guest instance.") - return FAIL + status = FAIL
Same here - this can be removed.
+ raise HsError("Association did not return expected guest instance.")
if dom_field_list['CreationClassName'] != hs_field_list['CreationClassName']: print_error('CreationClassName', hs_field_list['CreationClassName'], \ @@ -165,12 +175,15 @@ def main(): print_error('EnabledState', hs_field_list['EnabledState'], \ dom_field_list['EnabledState']) status = FAIL + except HsError, detail: + logger.error(detail)
I've applied the other 3 in this set since they don't depend on one another (and the cimtest queue is a bit largish today). -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Instead of setting status = FAIL here, can you set this where you catch the exception? That way you only have to set it once and we can be sure we're setting the right return code.
I've applied the other 3 in this set since they don't depend on one another (and the cimtest queue is a bit largish today).
New patch on the way. Thanks for the catch! :) -- - Zhengang

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208314195 -28800 # Node ID 68de226362a6f903a2e66537278733ac17c3551f # Parent 0b517aabe906fc9525c95d54ce6434d6c6790ce0 [TEST] Add KVM support for HostedDependency.04 Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r 0b517aabe906 -r 68de226362a6 suites/libvirt-cim/cimtest/HostedDependency/04_reverse_errs.py --- a/suites/libvirt-cim/cimtest/HostedDependency/04_reverse_errs.py Wed Apr 16 10:44:04 2008 +0800 +++ b/suites/libvirt-cim/cimtest/HostedDependency/04_reverse_errs.py Wed Apr 16 10:49:55 2008 +0800 @@ -29,16 +29,16 @@ # Date : 17-01-2008 import sys -from XenKvmLib.test_xml import testxml from VirtLib import utils from XenKvmLib import assoc -from XenKvmLib.test_doms import test_domain_function, destroy_and_undefine_all +from XenKvmLib import vxml from CimTest.Globals import log_param, logger, CIM_USER, CIM_PASS, CIM_NS from CimTest.Globals import do_main +from XenKvmLib.classes import get_typed_class from XenKvmLib.common_util import get_host_info, try_assoc from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC -sup_types = ['Xen'] +sup_types = ['Xen', 'KVM'] test_dom = "hd_domain1" test_mac = "00:11:22:33:44:55" @@ -55,11 +55,10 @@ expr_values = { "invalid_ccname_keyvalue" : { 'rc' : exp_rc, 'desc' : exp_d2 } } -def err_invalid_name_keyname(server, conn, field): - status, host_name, classname = get_host_info(server) +def err_invalid_name_keyname(server, conn, virt, assoc_classname, field): + status, host_name, classname = get_host_info(server, virt) if status: return status - assoc_classname = 'Xen_HostedDependency' keys = { 'CreationClassName' : classname, \ field : host_name @@ -68,11 +67,10 @@ def err_invalid_name_keyname(server, con expr_values=expr_values['invalid_name_keyname'], \ bug_no=bug) -def err_invalid_name_keyvalue(server, conn, field): - status, host_name, classname = get_host_info(server) +def err_invalid_name_keyvalue(server, conn, virt, assoc_classname, field): + status, host_name, classname = get_host_info(server, virt) if status: return status - assoc_classname = 'Xen_HostedDependency' keys = { 'CreationClassName' : classname, \ 'Name' : field @@ -81,11 +79,10 @@ def err_invalid_name_keyvalue(server, co expr_values=expr_values['invalid_name_keyvalue'], \ bug_no=bug) -def err_invalid_ccname_keyname(server, conn, field): - status, host_name, classname = get_host_info(server) +def err_invalid_ccname_keyname(server, conn, virt, assoc_classname, field): + status, host_name, classname = get_host_info(server, virt) if status: return status - assoc_classname = 'Xen_HostedDependency' keys = { field : classname, \ 'Name' : host_name @@ -93,11 +90,10 @@ def err_invalid_ccname_keyname(server, c return try_assoc(conn, classname, assoc_classname, keys, field_name=field, \ expr_values=expr_values['invalid_ccname_keyname'], \ bug_no=bug) -def err_invalid_ccname_keyvalue(server, conn, field): - status, host_name, classname = get_host_info(server) +def err_invalid_ccname_keyvalue(server, conn, virt, assoc_classname, field): + status, host_name, classname = get_host_info(server, virt) if status: return status - assoc_classname = 'Xen_HostedDependency' keys = { 'CreationClassName' : field, \ 'Name' : host_name @@ -113,33 +109,41 @@ def main(): log_param() status = PASS server = options.ip - destroy_and_undefine_all(options.ip) - test_xml = testxml(test_dom, mac = test_mac) + virtxml = vxml.get_class(options.virt) + cxml = virtxml(test_dom, mac = test_mac) - ret = test_domain_function(test_xml, options.ip, cmd = "create") + ret = cxml.create(options.ip) if not ret: logger.error("Failed to Create the dom: %s" % test_dom) status = FAIL return status - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - ret_value = err_invalid_name_keyname(server, conn, field='INVALID_KeyName') + conn = assoc.myWBEMConnection('http://%s' % options.ip, + (CIM_USER, CIM_PASS), CIM_NS) + acn = get_typed_class(options.virt, 'HostedDependency') + ret_value = err_invalid_name_keyname(server, conn, options.virt, acn, + field='INVALID_KeyName') if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Name.------") + logger.error("--- FAILED: Invalid Name Key Name.---") status = ret_value - ret_value = err_invalid_name_keyvalue(server, conn, field='INVALID_NameValue') + ret_value = err_invalid_name_keyvalue(server, conn, options.virt, acn, + field='INVALID_NameValue') if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Value.------") + logger.error("--- FAILED: Invalid Name Key Value.---") status = ret_value - ret_value = err_invalid_ccname_keyname(server, conn, field='INVALID_CCNKeyName') + ret_value = err_invalid_ccname_keyname(server, conn, options.virt, acn, + field='INVALID_CCNKeyName') if ret_value != PASS: - logger.error("------ FAILED: Invalid CreationClassName Key Name------") + logger.error("--- FAILED: Invalid CreationClassName Key Name---") status = ret_value - ret_value = err_invalid_ccname_keyvalue(server, conn, field='INVALID_CCNameValue') + ret_value = err_invalid_ccname_keyvalue(server, conn, options.virt, acn, + field='INVALID_CCNameValue') if ret_value != PASS: - logger.error("------ FAILED: Invalid CreationClassName Key Value------") + logger.error("--- FAILED: Invalid CreationClassName Key Value---") status = ret_value - ret = test_domain_function(test_dom, options.ip, cmd = "destroy") + cxml.destroy(options.ip) + cxml.undefine(options.ip) return status + if __name__ == "__main__": sys.exit(main())
participants (3)
-
Kaitlin Rupert
-
Zhengang Li
-
zli@linux.vnet.ibm.com