[Libvirt-cim] [PATCH] [TEST] #5 Update RPCS/04 to validate that the Network child pool can be created through the providers

yunguol at cn.ibm.com yunguol at cn.ibm.com
Thu May 7 05:05:16 UTC 2009


# HG changeset patch
# User Guolian Yun <yunguol at cn.ibm.com>
# Date 1241671689 25200
# Node ID af273b2ad41c2a42f999155b23122c18a5c5ee8e
# Parent  92caf252c2fa8c8a7a9b70548d12b03c52f3935c
[TEST] #5 Update RPCS/04 to validate that the Network child pool can be created through the providers


Updates from 4 to 5:
1) Move common functions to pool.py

Updates from 3 to 4:
1) Move general net function to common.py
2) move the CIM_NS import stmt along with the logger

Updates from 2 to 3:
1) Use CIM_NS from const.py instead of hardcoding
2) Check if the IP is already used on the system before setting
3) Rewrite  try, except... blocks

Updates from 1 to 2:
Test all types of networkpool including routed network, nat based network and isolated network

Tested for KVM with current sources
Signed-off-by: Guolian Yun<yunguol at cn.ibm.com>

diff -r 92caf252c2fa -r af273b2ad41c suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py
--- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Mon May 04 03:49:32 2009 -0700
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Wed May 06 21:48:09 2009 -0700
@@ -39,45 +39,47 @@
 # OUT -- Error -- String  -- Encoded error instance if the operation 
 #                            failed and did not return a job
 #
-# REVISIT : 
-# --------
-# As of now the CreateChildResourcePool() simply throws an Exception.
-# We must improve this tc once the service is implemented. 
-# 
-#                                                                            -Date: 20.02.2008
-
+# Exception details before Revision 837
+# -----
+# Error code: CIM_ERR_NOT_SUPPORTED 
+#
+# After revision 837, the service is implemented
+#
+#                                                   -Date: 20.02.2008
 
 import sys
-import pywbem 
-from XenKvmLib import rpcs_service
 from CimTest.Globals import logger
 from CimTest.ReturnCodes import FAIL, PASS
 from XenKvmLib.const import do_main, platform_sup
 from XenKvmLib.classes import get_typed_class
+from XenKvmLib.common_util import destroy_netpool
+from XenKvmLib.pool import undefine_netpool, create_verify_netpool
 
-cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
-cim_mname  = "CreateChildResourcePool"
+test_pool = ["routedpool", "natpool", "isolatedpool"]
 
 @do_main(platform_sup)
 def main():
+    status = PASS
     options = main.options
-    rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \
-                      "ResourcePoolConfigurationService"))(options.ip)
-    try:
-        rpcs_conn.CreateChildResourcePool()
-    except pywbem.CIMError, (err_no, desc):
-        if err_no == cim_errno :
-            logger.info("Got expected exception for '%s' service", cim_mname)
-            logger.info("Errno is '%s' ", err_no)
-            logger.info("Error string is '%s'", desc)
-            return PASS
-        else:
-            logger.error("Unexpected rc code %s and description %s\n",
-                         err_no, desc)
+
+    np = get_typed_class(options.virt, 'NetworkPool')
+    for i in range(0, len(test_pool)):
+        status = create_verify_netpool(options.ip, options.virt, test_pool[i])
+        if status != PASS:
+            logger.error("Error in networkpool creation and verification")
             return FAIL
-     
-    logger.error("The execution should not have reached here!!")
-    return FAIL
+
+        status = destroy_netpool(options.ip, options.virt, test_pool[i])
+        if status != PASS:
+            logger.error("Unable to destroy networkpool %s", test_pool[i])
+            status = FAIL
+
+        status = undefine_netpool(options.ip, options.virt, test_pool[i])
+        if status != PASS:
+            logger.error("Unable to undefine networkpool %s", test_pool[i])
+            status = FAIL
+
+    return status
+
 if __name__ == "__main__":
     sys.exit(main())
-    
diff -r 92caf252c2fa -r af273b2ad41c suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py	Mon May 04 03:49:32 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py	Wed May 06 21:48:09 2009 -0700
@@ -21,15 +21,21 @@
 #
 
 import sys
-from CimTest.Globals import logger
+from CimTest.Globals import logger, CIM_NS
 from CimTest.ReturnCodes import PASS, FAIL
 from XenKvmLib.classes import get_typed_class
 from XenKvmLib.const import get_provider_version, default_pool_name 
 from XenKvmLib.enumclass import EnumInstances
 from VirtLib.utils import run_remote
-from XenKvmLib.xm_virt_util import virt2uri
+from XenKvmLib.xm_virt_util import virt2uri, net_list
+from XenKvmLib import rpcs_service
+from pywbem.cim_obj import CIMInstance, CIMInstanceName
+import pywbem
 
+cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
+cim_mname  = "CreateChildResourcePool"
 input_graphics_pool_rev = 757
+libvirt_cim_child_pool_rev = 837
 
 def pool_cn_to_rasd_cn(pool_cn, virt):
     if pool_cn.find('ProcessorPool') >= 0:
@@ -97,3 +103,94 @@
 
     return volume
 
+def net_undefine(network, server, virt="Xen"):
+    """Function undefine a given virtual network"""
+
+    cmd = "virsh -c %s net-undefine %s" % (virt2uri(virt), network)
+    ret, out = run_remote(server, cmd)
+        
+    return ret
+
+def undefine_netpool(server, virt, net_name):
+    if net_name == None:
+       return FAIL
+
+    ret = net_undefine(net_name, server, virt)
+    if ret != 0:
+        logger.error("Failed to undefine Virtual Network '%s'", net_name)
+        return FAIL
+
+    return PASS    
+
+def create_verify_netpool(server, virt, test_pool):
+    status = FAIL
+    rpcs = get_typed_class(virt, "ResourcePoolConfigurationService")
+    rpcs_conn = eval("rpcs_service." + rpcs)(server)
+    curr_cim_rev, changeset = get_provider_version(virt, server)
+    if curr_cim_rev < libvirt_cim_child_pool_rev:
+        try:
+            rpcs_conn.CreateChildResourcePool()
+        except pywbem.CIMError, (err_no, desc):
+            if err_no == cim_errno :
+                logger.info("Got expected exception for '%s'service", cim_mname)
+                logger.info("Errno is '%s' ", err_no)
+                logger.info("Error string is '%s'", desc)
+                return PASS
+            else:
+                logger.error("Unexpected rc code %s and description %s\n",
+                             err_no, desc)
+                return FAIL
+    elif curr_cim_rev >= libvirt_cim_child_pool_rev: 
+        nprasd = get_typed_class(virt, 
+                                 'NetPoolResourceAllocationSettingData')
+        addr = "192.168.0.9"
+        n_list = net_list(server, virt)
+        for _net_name in n_list:
+            cmd = "virsh net-dumpxml %s | awk '/ip address/ {print}' | \
+                   cut -d ' ' -f 4 | sed 's/address=//'" % _net_name
+            s, in_use_addr = run_remote(server, cmd)
+            in_use_addr = in_use_addr.strip("'")
+            if in_use_addr == addr:
+                logger.error("IP address is in use by a different network")
+                return FAIL
+        np_prop = {
+                   "Address" : addr,
+                   "Netmask" : "255.255.255.0",
+                   "IPRangeStart" : "192.168.0.31",
+                   "IPRangeEnd" : "192.168.0.57",
+                  }     
+        np_id = 'NetworkPool/%s' % test_pool
+        iname = CIMInstanceName(nprasd,
+                                namespace = CIM_NS,
+                                keybindings = {'InstanceID':np_id})
+        if test_pool == "routedpool":
+            np_prop["ForwardMode"] = "route eth1"
+        elif test_pool == "natpool":
+            np_prop["ForwardMode"] = "nat"
+
+        nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)
+        try:
+            rpcs_conn.CreateChildResourcePool(ElementName=test_pool, 
+                                              Settings=[nrasd.tomof()])
+        except Exception, details:
+            logger.error("Error in childpool creation")
+            logger.error(details)
+            return FAIL
+       
+        networkpool = get_typed_class(virt, 'NetworkPool')
+        pool_list = EnumInstances(server, networkpool)
+        if len(pool_list) < 1:
+            logger.error("Return %i instances, expected at least one instance",
+                         len(pool_list))
+            return FAIL
+
+        for i in range(0, len(pool_list)):
+            ret_pool = pool_list[i].InstanceID
+            if ret_pool == np_id:
+                status = PASS
+                break
+            elif ret_pool != poolname and i == len(pool_list)-1:
+                logger.error("Can not find expected pool")
+                return FAIL
+
+    return status    




More information about the Libvirt-cim mailing list