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

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Nov 10 20:42:59 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1226349773 28800
# Node ID 8d04c525d233623ba00fd256a20a626b4eebfe53
# Parent  ceff8a7a75e001a24da909528ea8f333d6a7021c
[TEST] #2 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:
  -Return from test case if init_vs_pool_values() returns a failure

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

diff -r ceff8a7a75e0 -r 8d04c525d233 suites/libvirt-cim/cimtest/ElementConforms/01_forward.py
--- a/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Fri Nov 07 13:04:40 2008 -0800
+++ b/suites/libvirt-cim/cimtest/ElementConforms/01_forward.py	Mon Nov 10 12:42:53 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"
@@ -39,104 +37,71 @@
 #                                                          Date : 04-12-2007
 
 import sys
+from sets import Set
 from VirtLib import utils, live
 from XenKvmLib import assoc
 from XenKvmLib.test_doms import destroy_and_undefine_all
 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 +115,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:
@@ -164,51 +129,6 @@
     profiles_instid_list = [ profile.InstanceID for profile in proflist ] 
 
     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():
@@ -232,11 +152,54 @@
         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)
+    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:
+        return status
+
+    status, verify_ectp_list = init_vs_pool_values(server, virt)
+    if status != PASS:
+        Globals.CIM_NS = prev_namespace
+        cxml.destroy(server)
+        cxml.undefine(server)
+        return status
+
+    for prof_id in prof_inst_lst:
+        logger.info("Verifying '%s' with '%s'", an, prof_id)
+        try:
+            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:
+                    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") 
+
+        except Exception, detail:
+            logger.error("Exception: %s" % detail)
+            status = FAIL
+
+    if status == PASS:
+        for k, l in verify_ectp_list.iteritems():
+            if len(l) != 0:
+                logger.error("%s items weren't returned: %s", k, l)
+                status = FAIL
 
     Globals.CIM_NS = prev_namespace
     cxml.destroy(server)




More information about the Libvirt-cim mailing list