[Libvirt-cim] [PATCH] [TEST] #3 Fix ECTP 01_forward.py to support system with multiple networks defined

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Tue Nov 11 22:15:36 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1226441701 28800
# Node ID 89135530d992a488e3240e5ae6418464cc3fd187
# Parent  9d24629f17819c31889e22f22492e998760d1394
[TEST] #3 Fix ECTP 01_forward.py to support system with multiple networks defined

This test was doing a lot of unnecessary checking (and unessary building of
lists).  Instead, this test calls EnumInstances on each of the classes expected
to be returned by the association.

These instances are then compared against the list of instances returned by the ECTP association query.

The FIXME will be fixed when bug 0007 is fixed.

Updates from 2 to 3:
  -Place most of main block in a try/except.  When a failure is encountered,
   an exception is raised, and the test is cleaned up properly.
  -If the provider is < 680, don't check the ECTP values for
   CIM:DSP1059-GenericDeviceResourceVirtualization-1.0.0 - ECTP doesn't support
   this provider version.

Updates from 1 to 2:
  -Return from test case if init_vs_pool_values() returns a failure

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 9d24629f1781 -r 89135530d992 suites/libvirt-cim/cimtest/ElementConforms/01_forward.py
--- a/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Sun Nov 09 20:40:42 2008 -0800
+++ b/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Tue Nov 11 14:15:01 2008 -0800
@@ -23,10 +23,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 #
 
-# This tc is used to verify the EnabledState, HealthState, EnabledDefault and
-# the Classname are set appropriately for the results returned by the 
-# ElementConformsToProfile association for the RegisteredProfile class
-# and ManagedElement Class
+# This tc is used to verify the results of the ElementConformsToProfile 
+# association.  This test focuses on RegisteredProfile -> ManagedElement
 # 
 #   "CIM:DSP1042-SystemVirtualization-1.0.0" ,
 #   "CIM:DSP1057-VirtualSystem-1.0.0a"
@@ -45,98 +43,64 @@
 from XenKvmLib.classes import get_typed_class
 from XenKvmLib import vxml
 from CimTest import Globals 
-from XenKvmLib.common_util import print_field_error, check_sblim
-from CimTest.Globals import logger, CIM_ERROR_ASSOCIATORS, CIM_ERROR_ENUMERATE
-from XenKvmLib.const import do_main 
+from XenKvmLib.common_util import print_field_error, check_sblim, get_host_info 
+from CimTest.Globals import logger, CIM_ERROR_ENUMERATE
+from XenKvmLib.const import do_main, get_provider_version 
 from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
 from XenKvmLib.enumclass import EnumInstances
-from XenKvmLib.const import default_network_name, default_pool_name 
-from XenKvmLib.const import get_provider_version
-
 
 sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
 test_dom = "domU"
 bug_sblim = '00007'
 libvirt_cim_ectp_changes = 680
 
-def pool_init(verify_list, pool_cn, pool_name, virt):
-    ccn = get_typed_class(virt, pool_cn)
-    instid = '%s/%s' %(pool_cn, pool_name)
-    verify_list[ccn]= {'InstanceID' : instid }
-    return verify_list
-   
 def  init_vs_pool_values(server, virt):
-    verify_ectp_list = { }
-    hs_ccn = get_typed_class(virt, 'HostSystem')
-    host = live.hostname(server)
-    cs_fields = {
-                  'CreationClassName'    : hs_ccn,
-                  'Name'                 : host
-                }
+    verify_ectp_list = {} 
 
-    verify_ectp_list[hs_ccn] = cs_fields
+    cn_names = ["VirtualSystemMigrationService", "ComputerSystem", "DiskPool",
+                "NetworkPool", "ProcessorPool", "MemoryPool"] 
 
-    cs_ccn = get_typed_class(virt, 'ComputerSystem')
-    verify_ectp_list[cs_ccn] = cs_fields.copy()
-    verify_ectp_list[cs_ccn]['CreationClassName']   = cs_ccn
-    verify_ectp_list[cs_ccn]['Name']   = test_dom
+    status, host_name, host_ccn = get_host_info(server, virt)
+    if status != PASS:
+        logger.error("Unable to get host system instance objects")
+        return FAIL, verify_ectp_list
 
-    vs_ccn = get_typed_class(virt, 'VirtualSystemMigrationService')
-    verify_ectp_list[vs_ccn] = cs_fields.copy()
-    verify_ectp_list[vs_ccn]['CreationClassName']   = vs_ccn
-    verify_ectp_list[vs_ccn]['SystemCreationClassName']   =  hs_ccn
-    verify_ectp_list[vs_ccn]['SystemName']   =  host
-    verify_ectp_list[vs_ccn]['Name']   =  'MigrationService'
+    #FIXME - get_host_info() should be updated to return the host instance
+    insts = EnumInstances(server, host_ccn, True)
+    if len(insts) < 1: 
+        logger.error("Expected 1 %s instance", host_ccn)
+        return FAIL, verify_ectp_list
 
-    verify_ectp_list = pool_init(verify_ectp_list, 'DiskPool', 
-                                 default_pool_name, virt)
-    verify_ectp_list = pool_init(verify_ectp_list, 'NetworkPool', 
-                                 default_network_name, virt)
-    verify_ectp_list = pool_init(verify_ectp_list, 'ProcessorPool', 0, virt)
-    verify_ectp_list = pool_init(verify_ectp_list, 'MemoryPool', 0, virt)
+    verify_ectp_list[host_ccn] = insts
 
-                       
-    return verify_ectp_list
+    for cn_base in cn_names:
+        cn = get_typed_class(virt, cn_base)
+        insts = EnumInstances(server, cn, True)
+         
+        if len(insts) < 1: 
+            logger.error("Expected at least 1 %s instance", cn)
+            return FAIL, verify_ectp_list
 
-def verify_fields(assoc_val, pllst_index, vs_pool_values):
+        verify_ectp_list[cn] = insts
+
+    return PASS, verify_ectp_list
+
+def verify_fields(assoc_val, managed_ele_values):
     try:
-        field_names  = vs_pool_values[pllst_index].keys()
-        values = vs_pool_values[pllst_index]
-        for field in field_names:
-            if values[field] != assoc_val[field]:
-                print_field_error(field,  assoc_val[field], values[field]) 
-                return FAIL
+        cn = assoc_val.classname
+        elements = managed_ele_values[cn]
+ 
+        for ele in elements:
+            if assoc_val.items() == ele.items():
+                managed_ele_values[cn].remove(ele)
+                return PASS, managed_ele_values
+
     except Exception, details:
-        logger.error("Exception: In fn verify_fields() %s", details)
-        return FAIL
+        logger.error("verify_fields() exception: %s", details)
+        return FAIL, managed_ele_values
       
-    return PASS
-
-def verify_cs_hs_mig_fields(assoc_info, vs_pool_values):
-    try:
-        pllst_index = assoc_info[0]['CreationClassName']
-        assoc_val   = None 
-        if 'HostSystem' in pllst_index or \
-           'VirtualSystemMigrationService' in pllst_index:
-            if len(assoc_info) != 1:
-                logger.error("'%s' returned '%d' records, expected 1", 
-                              pllst_index, len(assoc_info)) 
-                return FAIL
-            assoc_val = assoc_info[0]
-        else: 
-            # For ComputerSystem info
-            for inst in assoc_info:
-                if inst['Name'] == test_dom:
-                    assoc_val = inst
-                    break
-    except Exception, details:
-        logger.error("Exception: In fn verify_cs_hs_mig_fields() %s", details)
-        return FAIL
-
-    if assoc_val == None:
-       return FAIL
-
-    return verify_fields(assoc_val, pllst_index, vs_pool_values)
+    logger.error("%s not in expected list %s", assoc_val, elements)
+    return FAIL, managed_ele_values
 
 def get_proflist(server, reg_classname, virt):
     profiles_instid_list = []
@@ -150,7 +114,7 @@
             len_prof_list = 7 
         if len(proflist) < len_prof_list:
             logger.error("'%s' returned '%d' '%s' objects, expected atleast %d",
-                          reg_classname, len(proflist), 'Profile', len_prof_list)
+                         reg_classname, len(proflist), 'Profile', len_prof_list)
             status = FAIL
 
     except Exception, detail:
@@ -165,58 +129,13 @@
 
     return status, profiles_instid_list 
 
-
-def verify_ectp_assoc(server, virt):
-    reg_classname = get_typed_class(virt, "RegisteredProfile")
-    an = get_typed_class(virt,"ElementConformsToProfile")
-
-    status, inst_lst = get_proflist(server, reg_classname, virt)
-    if status != PASS:
-        return status
-
-    verify_ectp_list = init_vs_pool_values(server, virt)
-    for devid in inst_lst :
-        logger.info("Verifying '%s' with '%s'", an, devid)
-        try:
-            assoc_info = assoc.Associators(server, 
-                                           an, 
-                                           reg_classname,
-                                           InstanceID = devid)  
-            if len(assoc_info) < 1:
-                ret_val, linux_cs = check_sblim(server, virt)
-                if ret_val != PASS:
-                    logger.error(" '%s' returned (%d) '%s' objects", an, 
-                                 len(assoc_info), reg_classname)
-                    return FAIL
-                else:
-                    return XFAIL_RC(bug_sblim) 
-                break
-
-            if 'DSP1059' in devid or 'DSP1045' in devid:
-                instid        = assoc_info[0]['InstanceID']
-                index, other  = instid.split("/")
-                cn = get_typed_class(virt, index)
-                status = verify_fields(assoc_info[0], cn, verify_ectp_list)
-            else:
-                ccn = assoc_info[0]['CreationClassName']
-                status = verify_cs_hs_mig_fields(assoc_info, verify_ectp_list)
-
-            if status != PASS:
-                break
-
-        except Exception, detail:
-            logger.error(CIM_ERROR_ASSOCIATORS, an)
-            logger.error("Exception: %s" % detail)
-            status = FAIL
-    return status
-
 @do_main(sup_types)
 def main():
     options = main.options
     server  = options.ip
     virt    = options.virt
   
-    status = PASS
+    status = None 
     destroy_and_undefine_all(options.ip, options.virt)
 
     virt_xml = vxml.get_class(options.virt)
@@ -232,11 +151,59 @@
         logger.error('Unable to start domain %s' % test_dom)
         return FAIL
 
-
     prev_namespace = Globals.CIM_NS
     Globals.CIM_NS = 'root/interop'
 
-    status = verify_ectp_assoc(server, virt)
+    try:
+        reg_classname = get_typed_class(virt, "RegisteredProfile")
+        an = get_typed_class(virt,"ElementConformsToProfile")
+
+        status, prof_inst_lst = get_proflist(server, reg_classname, virt)
+        if status != PASS:
+            raise Exception("Failed to get profile list") 
+
+        status, verify_ectp_list = init_vs_pool_values(server, virt)
+        if status != PASS:
+            raise Exception("Failed to get instances needed for verification") 
+
+        curr_cim_rev, changeset = get_provider_version(virt, server)
+
+        for prof_id in prof_inst_lst:
+            logger.info("Verifying '%s' with '%s'", an, prof_id)
+            assoc_info = assoc.Associators(server,
+                                           an,
+                                           reg_classname,
+                                           InstanceID = prof_id)
+
+            if curr_cim_rev < libvirt_cim_ectp_changes and \
+               prof_id.find("GenericDeviceResourceVirtualization"):
+                continue
+
+            if len(assoc_info) < 1:
+                ret_val, linux_cs = check_sblim(server, virt)
+                if ret_val != PASS:
+                    logger.error(" '%s' returned (%d) '%s' objects", an,
+                                 len(assoc_info), reg_classname)
+                    return FAIL
+                else:
+                    return XFAIL_RC(bug_sblim)
+                break
+
+            for inst in assoc_info:
+                status, verify_ectp_list = verify_fields(inst, verify_ectp_list)
+                if status != PASS:
+                    raise Exception("Failed to verify instance") 
+
+        if status == PASS:
+            for k, l in verify_ectp_list.iteritems():
+                if len(l) != 0:
+                    raise Exception("%s items weren't returned: %s", k, l) 
+                    status = FAIL
+
+    except Exception, detail:
+        logger.error("Exception: %s" % detail)
+        if status == None:
+            status = FAIL
 
     Globals.CIM_NS = prev_namespace
     cxml.destroy(server)




More information about the Libvirt-cim mailing list