[PATCH 0 of 3] Update enumclass to improve enumerate() calls.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223330027 25200 # Node ID 66508277e8139993c9fb8bcc0368a77f8f597052 # Parent 311bf6eda3786eb8e47ede06c4da6dc1570aff61 [TEST] Add new enumerate infrastructure... CIM_CimtestClass, EnumNames, EnumInstances, and GetInstance will replace the existing CIM_MyClass, enumerate, enumerate_inst, and getInstance. Since there are a lot of tests to change, the original infrastructure is left in place. This should be removed once the tests are updated to use the new infrastructure. There's a few problems with the existing infrastructure. These replacesments aim to remove these issues: -A new classes require an entry in enumclass.py for each virt type. These changes remove the requirement. -A key_list is a necessary parameter to the enumerate calls. This goes against the extrinsic API definitions - the CIM API does not include an equivallent paremeter for the enumerate calls. -The enumerate() call currently takes a base classname, and a virt type. Really, the just the classname (complete with prefix) should be passed in. This way, SBLIM classes are supported in a more natrual way. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 311bf6eda378 -r 66508277e813 suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Sun Oct 05 23:56:40 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Mon Oct 06 14:53:47 2008 -0700 @@ -28,6 +28,8 @@ from XenKvmLib.devices import CIM_Instance from XenKvmLib.classes import get_typed_class from CimTest import Globals, CimExt +from VirtLib import utils +from CimTest.Globals import logger class CIM_MyClass(CIM_Instance): def __init__(self, server, keys): @@ -405,3 +407,86 @@ return None return inst + +class CIM_CimtestClass(CIM_Instance): + def __init__(self, host, ref): + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + try: + inst = conn.GetInstance(ref) + except pywbem.CIMError, arg: + raise arg + + self.conn = conn + self.inst = inst + self.ref = ref + + CIM_Instance.__init__(self, inst) + + def __invoke(self, method, params): + try: + return self.conn.InvokeMethod(method, + self.ref, + **params) + except pywbem.CIMError, arg: + print 'InvokeMethod(%s): %s' % (method, arg[1]) + raise + + def __getattr__(self, attr): + if self.inst.has_key(attr): + return self.inst[attr] + else: + return CimExt._Method(self.__invoke, attr) + +def EnumNames(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstanceName objects.''' + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + + names = [] + + try: + names = conn.EnumerateInstanceNames(cn) + except pywbem.CIMError, arg: + print arg[1] + return names + + return names + +def EnumInstances(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + refs = [] + + try: + refs = EnumNames(host, cn) + except pywbem.CIMError, arg: + print arg[1] + + list = [] + + for name in refs: + list.append(CIM_CimtestClass(host, name)) + + return list + +def GetInstance(host, cn, keys): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + ref = CIMInstanceName(cn, keybindings=keys) + inst = None + + try: + inst = CIM_CimtestClass(host, ref) + except pywbem.CIMError, arg: + print arg[1] + + return inst +

+1 from me for the patch set =) libvirt-cim-bounces@redhat.com wrote on 2008-10-07 05:56:28:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223330027 25200 # Node ID 66508277e8139993c9fb8bcc0368a77f8f597052 # Parent 311bf6eda3786eb8e47ede06c4da6dc1570aff61 [TEST] Add new enumerate infrastructure...
CIM_CimtestClass, EnumNames, EnumInstances, and GetInstance will replace the existing CIM_MyClass, enumerate, enumerate_inst, and getInstance. Since there are a lot of tests to change, the original infrastructure is left in place. This should be removed once the tests are updated to use the new infrastructure.
There's a few problems with the existing infrastructure. These replacesments aim to remove these issues:
-A new classes require an entry in enumclass.py for each virt type. These changes remove the requirement.
-A key_list is a necessary parameter to the enumerate calls. This goes against the extrinsic API definitions - the CIM API does not include an equivallent paremeter for the enumerate calls.
-The enumerate() call currently takes a base classname, and a virt type. Really, the just the classname (complete with prefix) should be passed in. This way, SBLIM classes are supported in a more natrual way.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 311bf6eda378 -r 66508277e813 suites/libvirt- cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Sun Oct 05 23: 56:40 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Mon Oct 06 14: 53:47 2008 -0700 @@ -28,6 +28,8 @@ from XenKvmLib.devices import CIM_Instance from XenKvmLib.classes import get_typed_class from CimTest import Globals, CimExt +from VirtLib import utils +from CimTest.Globals import logger
class CIM_MyClass(CIM_Instance): def __init__(self, server, keys): @@ -405,3 +407,86 @@ return None
return inst + +class CIM_CimtestClass(CIM_Instance): + def __init__(self, host, ref): + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + try: + inst = conn.GetInstance(ref) + except pywbem.CIMError, arg: + raise arg + + self.conn = conn + self.inst = inst + self.ref = ref + + CIM_Instance.__init__(self, inst) + + def __invoke(self, method, params): + try: + return self.conn.InvokeMethod(method, + self.ref, + **params) + except pywbem.CIMError, arg: + print 'InvokeMethod(%s): %s' % (method, arg[1]) + raise + + def __getattr__(self, attr): + if self.inst.has_key(attr): + return self.inst[attr] + else: + return CimExt._Method(self.__invoke, attr) + +def EnumNames(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstanceName objects.''' + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + + names = [] + + try: + names = conn.EnumerateInstanceNames(cn) + except pywbem.CIMError, arg: + print arg[1] + return names + + return names + +def EnumInstances(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + refs = [] + + try: + refs = EnumNames(host, cn) + except pywbem.CIMError, arg: + print arg[1] + + list = [] + + for name in refs: + list.append(CIM_CimtestClass(host, name)) + + return list + +def GetInstance(host, cn, keys): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + ref = CIMInstanceName(cn, keybindings=keys) + inst = None + + try: + inst = CIM_CimtestClass(host, ref) + except pywbem.CIMError, arg: + print arg[1] + + 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 1222912864 25200 # Node ID 6927f0fc1112e53ef7b8f75885aff8e602eb03b7 # Parent 66508277e8139993c9fb8bcc0368a77f8f597052 [TEST] Modify AC 01_enumpy to use new EnumInstance() call. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 66508277e813 -r 6927f0fc1112 suites/libvirt-cim/cimtest/AllocationCapabilities/01_enum.py --- a/suites/libvirt-cim/cimtest/AllocationCapabilities/01_enum.py Mon Oct 06 14:53:47 2008 -0700 +++ b/suites/libvirt-cim/cimtest/AllocationCapabilities/01_enum.py Wed Oct 01 19:01:04 2008 -0700 @@ -26,42 +26,40 @@ # import sys -from VirtLib.live import virsh_version -from XenKvmLib import enumclass +from XenKvmLib.enumclass import EnumInstances from XenKvmLib.const import do_main, platform_sup from CimTest.Globals import logger, CIM_ERROR_ENUMERATE from CimTest.ReturnCodes import PASS, FAIL -from XenKvmLib.const import default_pool_name +from XenKvmLib.common_util import cleanup_restore +from XenKvmLib.classes import get_typed_class sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -def enum_pools_and_ac(ip, virt, cn): +def enum_pools_and_ac(ip, ac_cn, p_names): pools = {} ac = [] - pt = ['MemoryPool', 'ProcessorPool', 'DiskPool', 'NetworkPool'] + try: + ac = EnumInstances(ip, ac_cn) - try: - key = ["InstanceID"] - ac = enumclass.enumerate(ip, cn, key, virt) - - for p in pt: - enum_list = enumclass.enumerate(ip, p, key, virt) + for p_cn in p_names: + + enum_list = EnumInstances(ip, p_cn) if len(enum_list) < 1: - logger.error("%s did not return any instances" % p) + logger.error("%s did not return any instances" % p_cn) return pools, ac for pool in enum_list: pools[pool.InstanceID] = pool except Exception, details: - logger.error(CIM_ERROR_ENUMERATE, cn) + logger.error(CIM_ERROR_ENUMERATE, ac_cn) logger.error(details) return pools, ac if len(ac) != len(pools): - logger.error("%s returned %s instances, expected %s" % (cn, len(ac), + logger.error("%s returned %s instances, expected %s" % (ac_cn, len(ac), len(pools))) return pools, ac @@ -85,9 +83,13 @@ def main(): options = main.options - cn = 'AllocationCapabilities' + cn = get_typed_class(options.virt, 'AllocationCapabilities') + pt = [get_typed_class(options.virt, 'MemoryPool'), + get_typed_class(options.virt, 'ProcessorPool'), + get_typed_class(options.virt, 'DiskPool'), + get_typed_class(options.virt, 'NetworkPool')] - pools, ac = enum_pools_and_ac(options.ip, options.virt, cn) + pools, ac = enum_pools_and_ac(options.ip, cn, pt) if len(pools) < 4: logger.error("Only %d pools returned, expected at least 4" % len(pools)) cleanup_restore(options.ip, options.virt)

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1222912864 25200 # Node ID b66e4ffc75b323c9b0e40c8ae99563bd97cb7065 # Parent 6927f0fc1112e53ef7b8f75885aff8e602eb03b7 [TEST] Modify ESD 01_forward.py to use new GetInstance() call. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 6927f0fc1112 -r b66e4ffc75b3 suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py --- a/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Wed Oct 01 19:01:04 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ElementSettingData/01_forward.py Wed Oct 01 19:01:04 2008 -0700 @@ -49,7 +49,7 @@ import sys from VirtLib import utils -from XenKvmLib.enumclass import getInstance +from XenKvmLib.enumclass import GetInstance from XenKvmLib.assoc import Associators, compare_all_prop from XenKvmLib.classes import get_typed_class from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORS @@ -62,13 +62,13 @@ test_dom = "esd_dom" vmac = "00:11:22:33:44:aa" -def get_inst(ip, virt, cn, key): +def get_inst(ip, cn, key): inst = None try: key_list = {"InstanceID" : key } - inst = getInstance(ip, cn, key_list, virt) + inst = GetInstance(ip, cn, key_list) except Exception, details: logger.error("Exception %s" % details) @@ -143,7 +143,8 @@ inst_list = {} for cn, k in keys.iteritems(): - inst_list[cn] = get_inst(options.ip, options.virt, cn, k) + classname = get_typed_class(options.virt, cn); + inst_list[cn] = get_inst(options.ip, classname, k) if inst_list[cn] is None: cxml.undefine(options.ip) return FAIL
participants (2)
-
Guo Lian Yun
-
Kaitlin Rupert