[PATCH] [TEST] #2 patch set of fixing HostSystem-01_enum.py with sblim base provider installed

# HG changeset patch # User Guolian Yun <yunguol@cn.ibm.com> # Date 1222236393 25200 # Node ID 83add054f191b8b6ad2c4ba53fce67cdca455989 # Parent d2ae228a60c34b78c3dd1e4f43f6a5413898980d [TEST] #2 patch set of fixing HostSystem-01_enum.py with sblim base provider installed Signed-off-by: Guolian Yun <yunguol@cn.ibm.com> diff -r d2ae228a60c3 -r 83add054f191 suites/libvirt-cim/cimtest/HostSystem/01_enum.py --- a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py Mon Sep 22 11:28:02 2008 -0700 +++ b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py Tue Sep 23 23:06:33 2008 -0700 @@ -27,12 +27,13 @@ import sys from XenKvmLib import enumclass +from XenKvmLib.common_util import check_sblim from XenKvmLib.classes import get_typed_class from VirtLib import live from VirtLib import utils from CimTest.Globals import logger, CIM_ERROR_ENUMERATE from XenKvmLib.const import do_main -from CimTest.ReturnCodes import PASS, FAIL +from CimTest.ReturnCodes import PASS, FAIL, XFAIL SUPPORTED_TYPES = ['Xen', 'KVM', 'XenFV', 'LXC'] @@ -43,27 +44,34 @@ def main(): status = FAIL keys = ['Name', 'CreationClassName'] - try: - hs = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt) - name = get_typed_class(options.virt, 'HostSystem') + + status, linux_cs = check_sblim(options.ip, options.virt) + if status == PASS: + name = 'Linux_ComputerSystem' + system = linux_cs[0] + else: + try: + hs = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt) + name = get_typed_class(options.virt, 'HostSystem') - if len(hs) != 1: - logger.error("Expected 1 %s instance returned" % name) - return FAIL + if len(hs) != 1: + logger.error("Expected 1 %s instance returned" % name) + return XFAIL - system = hs[0] + system = hs[0] + except Exception, details: + logger.error("%s %s: %s" % (CIM_ERROR_ENUMERATE, name, details)) + status = FAIL - if system.CreationClassName != name or system.Name != host: - logger.error("Exp %s, got %s" % (name, system.CreationClassName)) - logger.error("Exp %s, got %s" % (host, system.Name)) - status = FAIL - else: - logger.info("%s is %s" % (name, host)) - status = PASS - except Exception, details: - logger.error("%s %s: %s" % (CIM_ERROR_ENUMERATE, name, details)) + if system.CreationClassName != name or system.Name != host: + logger.error("Exp %s, got %s" % (name, system.CreationClassName)) + logger.error("Exp %s, got %s" % (host, system.Name)) status = FAIL + else: + logger.info("%s is %s" % (name, host)) + status = PASS + return status diff -r d2ae228a60c3 -r 83add054f191 suites/libvirt-cim/lib/XenKvmLib/classes.py --- a/suites/libvirt-cim/lib/XenKvmLib/classes.py Mon Sep 22 11:28:02 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py Tue Sep 23 23:06:33 2008 -0700 @@ -22,10 +22,6 @@ virt_types = ['Xen', 'KVM', 'XenFV', 'LX virt_types = ['Xen', 'KVM', 'XenFV', 'LXC'] def get_typed_class(virt, basename): - if virt not in virt_types: - if virt != "Virt" and basename != "MigrationJob": - raise ValueError('Invalid class type') - if basename == None or basename == '': raise ValueError('Invalide class base name') diff -r d2ae228a60c3 -r 83add054f191 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Mon Sep 22 11:28:02 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Sep 23 23:06:33 2008 -0700 @@ -27,7 +27,8 @@ from distutils.file_util import move_fil from distutils.file_util import move_file from XenKvmLib.test_xml import * from XenKvmLib.test_doms import * -from XenKvmLib import vsms +from XenKvmLib import vsms +from CimTest import Globals from XenKvmLib import enumclass from pywbem.cim_obj import CIMInstanceName from XenKvmLib.devices import CIM_Instance @@ -477,4 +478,22 @@ def libvirt_cached_data_poll(ip, virt, d sleep(1) - return cs + return cs + +def check_sblim(server, virt='Xen'): + status = FAIL + Globals.CIM_NS = 'root/cimv2' + keys = ['Name', 'CreationClassName'] + try: + linux_cs = enumclass.enumerate(server, 'ComputerSystem', keys, 'Linux') + host_sys = enumclass.enumerate(server, 'HostSystem', keys, virt) + if len(linux_cs) == 1 and len(host_sys) == 0: + status = PASS + else: + logger.info("sblim base provider is not installed") + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, 'Linux_ComputerSystem') + logger.error("Exception: %s", detail) + + Globals.CIM_NS = 'root/virt' + return status, linux_cs diff -r d2ae228a60c3 -r 83add054f191 suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Mon Sep 22 11:28:02 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Tue Sep 23 23:06:33 2008 -0700 @@ -63,6 +63,23 @@ class CIM_MyClass(CIM_Instance): return self.inst[attr] else: return CimExt._Method(self.__invoke, attr) + +class Linux_ComputerSystem(CIM_Instance): + def __init__(self, server, keys): + conn = pywbem.WBEMConnection('http://%s' % server, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + + try: + classname = self.__class__.__name__ + ref = CIMInstanceName(classname, + keybindings=keys) + inst = conn.GetInstance(ref) + except pywbem.CIMError, arg: + raise arg + + CIM_Instance.__init__(self, inst) + class CIM_ComputerSystem(CIM_MyClass): pass

yunguol@cn.ibm.com wrote:
# HG changeset patch # User Guolian Yun <yunguol@cn.ibm.com> # Date 1222236393 25200 # Node ID 83add054f191b8b6ad2c4ba53fce67cdca455989 # Parent d2ae228a60c34b78c3dd1e4f43f6a5413898980d [TEST] #2 patch set of fixing HostSystem-01_enum.py with sblim base provider installed
Signed-off-by: Guolian Yun <yunguol@cn.ibm.com>
diff -r d2ae228a60c3 -r 83add054f191 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Mon Sep 22 11:28:02 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Sep 23 23:06:33 2008 -0700 @@ -27,7 +27,8 @@ from distutils.file_util import move_fil from distutils.file_util import move_file from XenKvmLib.test_xml import * from XenKvmLib.test_doms import * -from XenKvmLib import vsms +from XenKvmLib import vsms +from CimTest import Globals from XenKvmLib import enumclass from pywbem.cim_obj import CIMInstanceName from XenKvmLib.devices import CIM_Instance @@ -477,4 +478,22 @@ def libvirt_cached_data_poll(ip, virt, d
sleep(1)
- return cs + return cs + +def check_sblim(server, virt='Xen'): + status = FAIL + Globals.CIM_NS = 'root/cimv2' + keys = ['Name', 'CreationClassName'] + try: + linux_cs = enumclass.enumerate(server, 'ComputerSystem', keys, 'Linux') + host_sys = enumclass.enumerate(server, 'HostSystem', keys, virt) + if len(linux_cs) == 1 and len(host_sys) == 0: + status = PASS + else: + logger.info("sblim base provider is not installed") + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, 'Linux_ComputerSystem') + logger.error("Exception: %s", detail) + + Globals.CIM_NS = 'root/virt' + return status, linux_cs
The return statement will throw an error in case the exception block is hit, something similar to the one below. *UnboundLocalError: local variable 'linux_cs' referenced before assignment.* You should declare and initialize linux_cs before the try block.

+ else: + try: + hs = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt) + name = get_typed_class(options.virt, 'HostSystem')
- if len(hs) != 1: - logger.error("Expected 1 %s instance returned" % name) - return FAIL + if len(hs) != 1: + logger.error("Expected 1 %s instance returned" % name) + return XFAIL
This needs to be XFAIL_RC() with a bug number.
+ +def check_sblim(server, virt='Xen'): + status = FAIL + Globals.CIM_NS = 'root/cimv2' + keys = ['Name', 'CreationClassName'] + try: + linux_cs = enumclass.enumerate(server, 'ComputerSystem', keys, 'Linux') + host_sys = enumclass.enumerate(server, 'HostSystem', keys, virt) + if len(linux_cs) == 1 and len(host_sys) == 0: + status = PASS
You don't return linux_cs in this case.
+ else: + logger.info("sblim base provider is not installed")
This print is a little misleading. Because if len(linux_cs) == 1 and len(host_sys) == 1, you return SBLIM is installed. Plus, this function checks to determine whether SBLIM is installed or not. If you return FAIL in the case of len(linux_cs) == 1 and len(host_sys) == 1, then the test case thinks SBLIM isn't installed, when isn't accurate. I would make it so that this function just checks to determine whether SBLIM is installed or not. It's up to the test case to verify that HostSystem doesn't return an instance when SBLIM is installed. I would expect that only the HostSystem 01_enum.py test needs to be concerned about whether both SBLIM and HostSystem return an instance. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
+ else: + try: + hs = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt) + name = get_typed_class(options.virt, 'HostSystem') - if len(hs) != 1: - logger.error("Expected 1 %s instance returned" % name) - return FAIL + if len(hs) != 1: + logger.error("Expected 1 %s instance returned" % name) + return XFAIL
This needs to be XFAIL_RC() with a bug number.
My mistake here - this shouldn't be an XFAIL at all. I was confused last time I reviewed this patch. It should just be a FAIL. Since this bit of code should only be executed it SBLIM isn't installed, it would be a failure if HostSystem didn't return an instance. Sorry for the confusion! -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

+def check_sblim(server, virt='Xen'): + status = FAIL + Globals.CIM_NS = 'root/cimv2' + keys = ['Name', 'CreationClassName'] + try: + linux_cs = enumclass.enumerate(server, 'ComputerSystem', keys, 'Linux') + host_sys = enumclass.enumerate(server, 'HostSystem', keys, virt) + if len(linux_cs) == 1 and len(host_sys) == 0: + status = PASS + else: + logger.info("sblim base provider is not installed") + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, 'Linux_ComputerSystem') + logger.error("Exception: %s", detail) + + Globals.CIM_NS = 'root/virt' + return status, linux_cs
Also, this function should return linux_cs[0], so that the test cases don't need to call host_sys = linux_cs[0] -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Deepti B Kalakeri
-
Kaitlin Rupert
-
yunguol@cn.ibm.com