[PATCH 0 of 2] [TEST] #2 Added testcases for the HostedAccessPoint association

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1233177214 7200 # Node ID 767d1922190f08c2343c1b2110bd025c89124d55 # Parent 6cb990930f0c3e82c85d4e3437d7b9b5e0d0037a [TEST] Created testcases for the forward HostedAccessPoint association (HostSystem -> KVMRedirectionSAP Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 6cb990930f0c -r 767d1922190f suites/libvirt-cim/cimtest/HostedAccessPoint/01_forward.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/HostedAccessPoint/01_forward.py Wed Jan 28 19:13:34 2009 -0200 @@ -0,0 +1,184 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Richard Maciel <rmaciel@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import sys +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.vxml import get_class +from XenKvmLib.assoc import AssociatorNames +from XenKvmLib.classes import get_typed_class +from XenKvmLib.const import do_main, get_provider_version +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id +from XenKvmLib.vsms import enumerate_instances +from XenKvmLib.test_doms import virdomid_list +from XenKvmLib.common_util import get_host_info +from XenKvmLib.enumclass import EnumInstances + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] + +test_dom = "domu1" + +def setup_env(server, virt): + if virt == 'Xen': + test_disk = 'xvda' + else: + test_disk = 'hda' + virt_xml = get_class(virt) + if virt == 'LXC': + cxml = virt_xml(test_dom) + else: + cxml = virt_xml(test_dom, disk = test_disk) + + ret = cxml.cim_define(server) + if not ret: + logger.error("Failed to Create the dom: %s", test_dom) + return FAIL, cmxl + + status = cxml.cim_start(server) + if status != PASS: + logger.error("Unable start dom '%s'", test_dom) + cxml.undefine(server) + return status, cxml + + return PASS, cxml + +def enum_kvmrsaps(virt, ip): + kvmrsap_insts = {} + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + if enum_list < 1: + logger.error("No KVM Redirection SAP instances returned") + return kvmrsap_insts, FAIL + + for kvmrsap in enum_list: + if kvmrsap.Classname not in kvmrsap_insts.keys(): + kvmrsap_insts[kvmrsap.Classname] = [] + kvmrsap_insts[kvmrsap.Classname].append(kvmrsap) + + except Exception, details: + logger.error(details) + return kvmrsap_insts, FAIL + + return kvmrsap_insts, PASS + +def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Get KVMRSAPs failed") + return kvmrsap_inst, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName + + if guest == guest_name: + kvmrsap_inst = kvmrsap + + return kvmrsap_inst, PASS + +def init_kvmrsap_list(virt, ip, guest_name): + kvmrsap_insts = {} + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Enum KVMRSAPs failed") + return kvmrsap_insts, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName + + if guest == guest_name: + kvmrsap_insts[kvmrsap.Classname] = kvmrsap + + return kvmrsap_insts, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list: + if item.classname != kvmrsap_inst.Classname: + print "Returned class name (%s) is not correct", item.classname + return status + + guest = item.keybindings['SystemName'] + + print "Iteration guest name: ", guest + print "Iteration host name: ", item.host + + if guest == kvmrsap_inst.SystemName: + status = PASS + break + + return status + + +@do_main(sup_types) +def main(): + options = main.options + status = FAIL + server = options.ip + virt = options.virt + + status, cxml = setup_env(options.ip, options.virt) + if status != PASS: + cxml.undefine(options.ip) + return status + + try: + status, host_inst = get_host_info(server, virt) + if status != PASS: + raise Exception("Failed to get host info.") + + kvmrsap_inst, status = get_kvmrsap_inst(options.virt, options.ip, test_dom) + if status != PASS: + raise Exception("Unable to fetch kvmrsap instance (domain: %s)", test_dom) + + an = get_typed_class(options.virt, 'HostedAccessPoint') + + host_ccn = host_inst.CreationClassName + + assoc_info = AssociatorNames(options.ip, an, host_ccn, + CreationClassName = host_ccn, + Name = host_inst.Name) + + status = verify_kvmrsap(assoc_info, kvmrsap_inst) + + if status != PASS: + raise Exception("Failed to verify KVMRedirectionSAPs") + + except Exception, details: + logger.error(details) + status = FAIL + + cxml.cim_destroy(options.ip) + cxml.undefine(options.ip) + return status + +if __name__ == "__main__": + sys.exit(main())

+from XenKvmLib.const import do_main, get_provider_version +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id +from XenKvmLib.vsms import enumerate_instances +from XenKvmLib.test_doms import virdomid_list
This test doesn't include these functions, no need to import them.
+sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] + +test_dom = "domu1" + +def setup_env(server, virt): + if virt == 'Xen': + test_disk = 'xvda' + else: + test_disk = 'hda' + virt_xml = get_class(virt) + if virt == 'LXC': + cxml = virt_xml(test_dom) + else: + cxml = virt_xml(test_dom, disk = test_disk) + + ret = cxml.cim_define(server) + if not ret: + logger.error("Failed to Create the dom: %s", test_dom)
This should be "define" instead of "create" - there's a slight difference between libvirt's notion of define and create, so it'd be good to use "define" here.
+ return FAIL, cmxl
This should be cxml, not cmxl.
+ +def enum_kvmrsaps(virt, ip): + kvmrsap_insts = {} + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + if enum_list < 1: + logger.error("No KVM Redirection SAP instances returned") + return kvmrsap_insts, FAIL + + for kvmrsap in enum_list: + if kvmrsap.Classname not in kvmrsap_insts.keys(): + kvmrsap_insts[kvmrsap.Classname] = [] + kvmrsap_insts[kvmrsap.Classname].append(kvmrsap)
All of the instances returned by EnunmInstances will have the same classname. There's no need to build a dictionary. This function isn't really necessary. Just call the EnumInstances() call in get_kvmrsap_inst(). Then loop through the list returned by EnumInstances() to kind the instance that corresponds to your guest.
+ + except Exception, details: + logger.error(details) + return kvmrsap_insts, FAIL + + return kvmrsap_insts, PASS + +def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Get KVMRSAPs failed") + return kvmrsap_inst, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName
You don't use the guest param for anything else, so you can just do: if kvmrsap.SystemName == guest_name
+ + if guest == guest_name: + kvmrsap_inst = kvmrsap
You want to make sure the expected number of KVMRedirectionSAPs are returned before returning from the function. If kvmrsap_inst is None, return an error.
+ + return kvmrsap_inst, PASS + +def init_kvmrsap_list(virt, ip, guest_name):
This function isn't being used. It should be removed.
+ kvmrsap_insts = {} + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Enum KVMRSAPs failed") + return kvmrsap_insts, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName + + if guest == guest_name: + kvmrsap_insts[kvmrsap.Classname] = kvmrsap + + return kvmrsap_insts, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list:
Also, you need to verify that enum_list has the proper number of KVMRedirectionSAP instances. Since you are not connecting to the guest's console, there should only be one instance. Because of this, the loop isn't needed here.
+ if item.classname != kvmrsap_inst.Classname: + print "Returned class name (%s) is not correct", item.classname + return status + + guest = item.keybindings['SystemName'] + + print "Iteration guest name: ", guest + print "Iteration host name: ", item.host
Remove print statements.
+ + if guest == kvmrsap_inst.SystemName: + status = PASS + break
This function should verify all the properties of the instance. Take a look at compare_all_prop() for this.
+ + return status + + +@do_main(sup_types) +def main(): + options = main.options + status = FAIL + server = options.ip + virt = options.virt + + status, cxml = setup_env(options.ip, options.virt) + if status != PASS: + cxml.undefine(options.ip) + return status + + try: + status, host_inst = get_host_info(server, virt) + if status != PASS: + raise Exception("Failed to get host info.") + + kvmrsap_inst, status = get_kvmrsap_inst(options.virt, options.ip, test_dom)
This line needs to be 80 characters.
+ if status != PASS: + raise Exception("Unable to fetch kvmrsap instance (domain: %s)", test_dom)
This line needs to be 80 characters. Also, the format for Exception is to use a % for args, not a comma: raise Exception("Unable to fetch kvmrsap instance (domain: %s)" % test_dom) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
+from XenKvmLib.const import do_main, get_provider_version +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id +from XenKvmLib.vsms import enumerate_instances +from XenKvmLib.test_doms import virdomid_list
This test doesn't include these functions, no need to import them.
Correction - you need to keep the do_main import, just remove the get_provider_version. I failed to see do_main in the list when I responded originally. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1233177219 7200 # Node ID f33c1c9e02ce795ea273ebe4098a2dd3692155d6 # Parent 767d1922190f08c2343c1b2110bd025c89124d55 [TEST] Created reverse test (KVMRedirectionSAP -> HostSystem) test Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 767d1922190f -r f33c1c9e02ce suites/libvirt-cim/cimtest/HostedAccessPoint/02_reverse.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/HostedAccessPoint/02_reverse.py Wed Jan 28 19:13:39 2009 -0200 @@ -0,0 +1,171 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Richard Maciel <rmaciel@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import sys +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.vxml import get_class +from XenKvmLib.assoc import AssociatorNames +from XenKvmLib.classes import get_typed_class +from XenKvmLib.const import do_main, get_provider_version +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id +from XenKvmLib.vsms import enumerate_instances +from XenKvmLib.test_doms import virdomid_list +from XenKvmLib.common_util import get_host_info +from XenKvmLib.enumclass import EnumInstances + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] + +test_dom = "domu1" + +def setup_env(server, virt): + if virt == 'Xen': + test_disk = 'xvda' + else: + test_disk = 'hda' + virt_xml = get_class(virt) + if virt == 'LXC': + cxml = virt_xml(test_dom) + else: + cxml = virt_xml(test_dom, disk = test_disk) + + ret = cxml.cim_define(server) + if not ret: + logger.error("Failed to Create the dom: %s", test_dom) + return FAIL, cmxl + + status = cxml.cim_start(server) + if status != PASS: + logger.error("Unable start dom '%s'", test_dom) + cxml.undefine(server) + return status, cxml + + return PASS, cxml + +def enum_kvmrsaps(virt, ip): + kvmrsap_insts = {} + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + if enum_list < 1: + logger.error("No KVM Redirection SAP instances returned") + return kvmrsap_insts, FAIL + + for kvmrsap in enum_list: + if kvmrsap.Classname not in kvmrsap_insts.keys(): + kvmrsap_insts[kvmrsap.Classname] = [] + kvmrsap_insts[kvmrsap.Classname].append(kvmrsap) + + except Exception, details: + logger.error(details) + return kvmrsap_insts, FAIL + + return kvmrsap_insts, PASS + +def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Get KVMRSAPs failed") + return kvmrsap_inst, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName + + if guest == guest_name: + kvmrsap_inst = kvmrsap + + return kvmrsap_inst, PASS + +def verify_host(enum_list, host_inst): + status = FAIL + + for item in enum_list: + if item.classname != host_inst.Classname: + print "Returned class name (%s) is not correct", item.classname + return status + + host = item.keybindings['Name'] + + print "Iteration host name: ", host_inst.Name + + if host == host_inst.Name: + status = PASS + break + + return status + + +@do_main(sup_types) +def main(): + options = main.options + status = FAIL + server = options.ip + virt = options.virt + + status, cxml = setup_env(options.ip, options.virt) + if status != PASS: + cxml.undefine(options.ip) + return status + + try: + status, host_inst = get_host_info(server, virt) + if status != PASS: + raise Exception("Failed to get host info.") + + kvmrsap_inst, status = get_kvmrsap_inst(options.virt, options.ip, test_dom) + if status != PASS: + raise Exception("Unable to fetch kvmrsap instance (domain: %s)", test_dom) + + an = get_typed_class(options.virt, 'HostedAccessPoint') + + + kvm_ccn = kvmrsap_inst.CreationClassName + name = kvmrsap_inst.Name + sys_ccn = kvmrsap_inst.SystemCreationClassName + + assoc_info = AssociatorNames(options.ip, an, kvm_ccn, + CreationClassName = kvm_ccn, + Name = kvmrsap_inst.Name, + SystemCreationClassName = sys_ccn, + SystemName = test_dom) + + status = verify_host(assoc_info, host_inst) + + if status != PASS: + raise Exception("Failed to verify KVMRedirectionSAPs") + + except Exception, details: + logger.error(details) + status = FAIL + + cxml.cim_destroy(options.ip) + cxml.undefine(options.ip) + return status + +if __name__ == "__main__": + sys.exit(main())

+from XenKvmLib.const import do_main, get_provider_version
You don't use get_provider_version, however - you probably should (and on the other HAP test as well). Because these tests won't work with older versions of the providers.
+from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id +from XenKvmLib.vsms import enumerate_instances +from XenKvmLib.test_doms import virdomid_list
These aren't used; they should be removed.
+from XenKvmLib.common_util import get_host_info +from XenKvmLib.enumclass import EnumInstances + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] + +test_dom = "domu1" + +def setup_env(server, virt): + if virt == 'Xen': + test_disk = 'xvda' + else: + test_disk = 'hda' + virt_xml = get_class(virt) + if virt == 'LXC': + cxml = virt_xml(test_dom) + else: + cxml = virt_xml(test_dom, disk = test_disk) + + ret = cxml.cim_define(server) + if not ret: + logger.error("Failed to Create the dom: %s", test_dom)
This should be "define" instead of "create" - there's a slight difference between libvirt's notion of define and create, so it'd be good to use "define" here.
+ return FAIL, cmxl
This should be cxml, not cmxl.
+ + status = cxml.cim_start(server) + if status != PASS: + logger.error("Unable start dom '%s'", test_dom) + cxml.undefine(server) + return status, cxml + + return PASS, cxml + +def enum_kvmrsaps(virt, ip): + kvmrsap_insts = {} + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + if enum_list < 1: + logger.error("No KVM Redirection SAP instances returned") + return kvmrsap_insts, FAIL + + for kvmrsap in enum_list: + if kvmrsap.Classname not in kvmrsap_insts.keys(): + kvmrsap_insts[kvmrsap.Classname] = [] + kvmrsap_insts[kvmrsap.Classname].append(kvmrsap)
All of the instances returned by EnunmInstances will have the same classname. There's no need to build a dictionary. This function isn't really necessary. Just call the EnumInstances() call in get_kvmrsap_inst(). Then loop through the list returned by EnumInstances() to kind the instance that corresponds to your guest.
+ + except Exception, details: + logger.error(details) + return kvmrsap_insts, FAIL + + return kvmrsap_insts, PASS + +def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + kvmrsaps, status = enum_kvmrsaps(virt, ip) + if status != PASS: + logger.error("Get KVMRSAPs failed") + return kvmrsap_inst, status + + for kvmrsap_cn, kvmrsap_list in kvmrsaps.iteritems(): + for kvmrsap in kvmrsap_list: + guest = kvmrsap.SystemName + + if guest == guest_name: + kvmrsap_inst = kvmrsap
You don't use the guest param for anything else, so you can just do: if kvmrsap.SystemName == guest_name
+ + return kvmrsap_inst, PASS
You want to make sure the expected number of KVMRedirectionSAPs are returned before returning from the function. If kvmrsap_inst is None, return an error.
+ +def verify_host(enum_list, host_inst): + status = FAIL + + for item in enum_list: + if item.classname != host_inst.Classname: + print "Returned class name (%s) is not correct", item.classname + return status + + host = item.keybindings['Name'] + + print "Iteration host name: ", host_inst.Name
Remove print statement.
+ + if host == host_inst.Name: + status = PASS + break
This function should verify all the properties of the instance. Take a look at compare_all_prop() for this.
+ + return status + + +@do_main(sup_types) +def main(): + options = main.options + status = FAIL + server = options.ip + virt = options.virt + + status, cxml = setup_env(options.ip, options.virt) + if status != PASS: + cxml.undefine(options.ip) + return status + + try: + status, host_inst = get_host_info(server, virt) + if status != PASS: + raise Exception("Failed to get host info.") + + kvmrsap_inst, status = get_kvmrsap_inst(options.virt, options.ip, test_dom)
This line needs to be 80 characters.
+ if status != PASS: + raise Exception("Unable to fetch kvmrsap instance (domain: %s)", test_dom)
This line needs to be 80 characters. Also, the format for Exception is to use a % for args, not a comma: raise Exception("Unable to fetch kvmrsap instance (domain: %s)" % test_dom) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel