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

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Nov 12 23:44:07 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1226533400 28800
# Node ID db20e254823bc7999a28b0db63b2301bf03996b7
# Parent  8d6f2db22eda9bda08ff26caa8982f137a3d4486
[TEST] #4 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 3 to 4:
   -Fix false positive - if an exception is encountered, be sure to set the
    return status as FAILED.
   -Build the appropriate profile list needed for testing with older providers
   -Change provider version from 680 to 686 (which has additional ECTP changes
    needed to have ECTP work properly).

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 8d6f2db22eda -r db20e254823b suites/libvirt-cim/cimtest/ElementConforms/01_forward.py
--- a/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Tue Nov 11 00:19:20 2008 -0800
+++ b/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Wed Nov 12 15:43:20 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,69 @@
 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
+libvirt_cim_ectp_changes = 686
 
-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 = ["ComputerSystem"]
 
-    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
+    curr_cim_rev, changeset = get_provider_version(virt, server)
+    if curr_cim_rev >= libvirt_cim_ectp_changes:
+        cn_names2 = ["VirtualSystemMigrationService", "DiskPool", "NetworkPool",
+                     "ProcessorPool", "MemoryPool"]
+        cn_names.extend(cn_names2)
 
-    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'
+    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
 
-    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)
+    #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
 
-                       
-    return verify_ectp_list
+    verify_ectp_list[host_ccn] = insts
 
-def verify_fields(assoc_val, pllst_index, vs_pool_values):
+    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
+
+        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,8 +119,8 @@
             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)
-            status = FAIL
+                         reg_classname, len(proflist), 'Profile', len_prof_list)
+            return FAIL, profiles_instid_list
 
     except Exception, detail:
         logger.error(CIM_ERROR_ENUMERATE, reg_classname)
@@ -161,54 +130,17 @@
     if status != PASS:
         return status, profiles_instid_list
 
-    profiles_instid_list = [ profile.InstanceID for profile in proflist ] 
+    unsupp_prof = []
+    if curr_cim_rev < libvirt_cim_ectp_changes:
+        unsupp_prof = ["CIM:DSP1059-GenericDeviceResourceVirtualization-1.0.0",
+                       "CIM:DSP1045-MemoryResourceVirtualization-1.0.0",
+                       "CIM:DSP1081-VirtualSystemMigration-0.8.1"]
+
+    for profile in proflist:
+        if profile.InstanceID not in unsupp_prof:
+            profiles_instid_list.append(profile.InstanceID)
 
     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():
@@ -216,7 +148,7 @@
     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 +164,53 @@
         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") 
+
+        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 len(assoc_info) < 1:
+                ret_val, linux_cs = check_sblim(server, virt)
+                if ret_val != PASS:
+                    status = FAIL
+                    raise Exception(" '%s' returned (%d) '%s' objects" % \
+                                    (len(assoc_info), reg_classname))
+                else:
+                    status = XFAIL_RC(bug_sblim)
+                    raise Exception("Known failure")
+
+            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:
+                    status = FAIL
+                    raise Exception("%s items weren't returned: %s" % (k, l))
+
+    except Exception, detail:
+        logger.error("Exception: %s" % detail)
+        if status == PASS:
+            status = FAIL
 
     Globals.CIM_NS = prev_namespace
     cxml.destroy(server)




More information about the Libvirt-cim mailing list