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

#2 added [TEST] on all patch headers #3 Fixed code style Enhanced the way objects are compared using the compare_all_prop

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1233866975 7200 # Node ID 40e312d4e1cb360712c161f0164d460ad1d9269b # Parent 643ae1ea950d124b8453661080b18094f589a2bc [TEST] Created testcases for the forward HostedAccessPoint association (HostSystem -> KVMRedirectionSAP Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 643ae1ea950d -r 40e312d4e1cb 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 Thu Feb 05 18:49:35 2009 -0200 @@ -0,0 +1,147 @@ +#!/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.common_util import get_host_info +from XenKvmLib.enumclass import EnumInstances +from XenKvmLib.assoc import compare_all_prop + +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 define the dom: %s", test_dom) + return FAIL, cxml + + 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 get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest" + return kvmrsap_inst, FAIL + kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list: + if item.classname != kvmrsap_inst.Classname: + print "Wrong returned class name (%s)", item.classname + return status + + if compare_all_prop(item, kvmrsap_inst) == PASS: + if status == PASS: + print "More than one instance found" + return FAIL + status = PASS + + 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") + + if kvmrsap_inst is None: + raise Exception("No kvmrsap instance returned") + + 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())

+ +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)
These 4 lines shouldn't be under the else. On Xen systems, you don't assign cxml. I didn't notice this during the last review. Also, the KVMRedirectionSAP provider was introduced in changeset 716. So you'll need to have this test return SKIP if the provider version is older than that. Otherwise, this test will fail when run with older providers. See test KVMRedirectionSAP/01_enum_KVMredSAP.py for an example on how to branch this test. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Accidentally hit send before finishing my review..
+def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest"
Instead of using print, elogger.error() should be used.
+ return kvmrsap_inst, FAIL
Since you also return the inst and FAIL in the except block, you could remove the line above and change the print to a "raise Exception()" call. Either one is valid, though I think raising an exception is cleaner.
+ kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list:
You should get get only one KVMRedirectionSAP. Verify enum_list only has one element. If it has more than one, return an error. Remove the for loop - since there's only one element in the list, no need to use a loop here.
+ if item.classname != kvmrsap_inst.Classname: + print "Wrong returned class name (%s)", item.classname
This needs to be a logger.error() call instead of a print.
+ return status + + if compare_all_prop(item, kvmrsap_inst) == PASS: + if status == PASS: + print "More than one instance found"
Replace the print with logger.error() -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Accidentally hit send before finishing my review..
+def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest"
Instead of using print, elogger.error() should be used.
+ return kvmrsap_inst, FAIL
Since you also return the inst and FAIL in the except block, you could remove the line above and change the print to a "raise Exception()" call.
Either one is valid, though I think raising an exception is cleaner.
+ kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list:
You should get get only one KVMRedirectionSAP. Verify enum_list only has one element. If it has more than one, return an error.
Remove the for loop - since there's only one element in the list, no need to use a loop here.
I don't get it. When I execute the ServiceAccessBySAP query (ConsoleRedirectionService -> KVMRedirectionSAP) I receive one item per virtual machine configured in the host. The same happens when I do the query using pywbem.
+ if item.classname != kvmrsap_inst.Classname: + print "Wrong returned class name (%s)", item.classname
This needs to be a logger.error() call instead of a print.
+ return status + + if compare_all_prop(item, kvmrsap_inst) == PASS: + if status == PASS: + print "More than one instance found"
Replace the print with logger.error()
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com

+ kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list:
You should get get only one KVMRedirectionSAP. Verify enum_list only has one element. If it has more than one, return an error.
Remove the for loop - since there's only one element in the list, no need to use a loop here.
I don't get it. When I execute the ServiceAccessBySAP query (ConsoleRedirectionService -> KVMRedirectionSAP) I receive one item per virtual machine configured in the host. The same happens when I do the query using pywbem
Oh,yes - you're right. The structure of the test case threw me off some. Let me send an updated review, because I misunderstood what you were trying to verify. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

+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)
Move the 4 lines above out from underneath the else.
+def get_kvmrsap_inst(virt, ip, guest_name):
This is what threw me off in the last review. You're trying to verify the result of the output of HostSystem -> KVMRedirectionSAP. As you noted in your mail, this will return all the KVMRedirectionSAP instances present on the host. Because of this, you want to verify that the AssociatorNames() call returns the same list that the EnumInstances() of KVMRedirectionSAP returns.
+ kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest"
Replace print with logger.error()
+ return kvmrsap_inst, FAIL + kvmrsap_inst = kvmrsap
So here, you want to do 2 things: 1) Verify that one of the instances in enum_list corresponds to the guest we defined in the test. If there is no corresponding instance, return an error. 2) Return the whole list, not just the instance corresponding to the guest.
+ + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_kvmrsap(enum_list, kvmrsap_inst): + status = FAIL + + for item in enum_list: + if item.classname != kvmrsap_inst.Classname + print "Wrong returned class name (%s)", item.classname
No need to verify the classname - all the instances will have the same classname.
+ return status + + if compare_all_prop(item, kvmrsap_inst) == PASS:
Since you don't know how many guests are running on the system, you want to verify that HostSystem -> KVMRedirectionSAP returns the same number of instances that the enum of KVMRedirectionSAP returns. You can also verify the individual instances - to do that, you'll need to loop through the list returned by HostSystem -> KVMRedirectionSAP, then loop through the list returned by KVMRedirectionSAP to find a match. Sorry for the confusion - originally, I thought you were just trying to compare a single instance - but really, you want to verify the list returned by EnumInstances() of KVMRedirectionSAP is identical to the list returned by HostSystem -> KVMRedirectionSAP. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1233894676 7200 # Node ID c9af0154836392cacc25c67aa73b25a005c3d70f # Parent 40e312d4e1cb360712c161f0164d460ad1d9269b [TEST] Created reverse test (KVMRedirectionSAP -> HostSystem) test Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 40e312d4e1cb -r c9af01548363 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 Fri Feb 06 02:31:16 2009 -0200 @@ -0,0 +1,151 @@ +#!/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.common_util import get_host_info +from XenKvmLib.enumclass import EnumInstances +from XenKvmLib.assoc import compare_all_prop + +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 define the dom: %s", test_dom) + return FAIL, cxml + + 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 get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest" + return kvmrsap_inst, FAIL + kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + 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 + + if compare_all_prop(item, host_inst) == PASS: + if status == PASS: + print "More than one instance found" + return FAIL + + status = PASS + + 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())

+ +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)
These 4 lines need to be moved out from under the else.
+ +def get_kvmrsap_inst(virt, ip, guest_name): + kvmrsap_inst = None + + try: + kvmrsap_cn = get_typed_class(virt, 'KVMRedirectionSAP') + enum_list = EnumInstances(ip, kvmrsap_cn) + + for kvmrsap in enum_list: + if kvmrsap.SystemName == guest_name: + if kvmrsap_inst is not None: + print "More than one KVMRedirectionSAP found \ + the same guest" + return kvmrsap_inst, FAIL
Remove the return here and change the print to a "raise Exception()" call.
+ kvmrsap_inst = kvmrsap + + except Exception, details: + logger.error(details) + return kvmrsap_inst, FAIL + + return kvmrsap_inst, PASS + +def verify_host(enum_list, host_inst): + status = FAIL + + for item in enum_list:
Remove the for loop. Verify enum_list is just one element.
+ if item.classname != host_inst.Classname: + print "Returned class name (%s) is not correct", item.classname
This should be a logger.error() call.
+ return status + + if compare_all_prop(item, host_inst) == PASS: + if status == PASS: + print "More than one instance found"
This should be a logger.error() call. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel