[Libvirt-cim] [PATCH] [TEST] #4 Update RPCS/07_DeleteResourcePool.py validate that the Network pool can be deleted through the providers

yunguol at cn.ibm.com yunguol at cn.ibm.com
Mon Apr 27 08:10:16 UTC 2009


# HG changeset patch
# User Guolian Yun <yunguol at cn.ibm.com>
# Date 1240819808 25200
# Node ID fc3416aaa19e164920af1d7b264175706d68222b
# Parent  e8dc06eefada41252ba8d27b08fcef8ef6604251
[TEST] #4 Update RPCS/07_DeleteResourcePool.py validate that the Network pool can be deleted through the providers


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 e8dc06eefada -r fc3416aaa19e suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py
--- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Tue Apr 21 17:08:06 2009 -0700
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Mon Apr 27 01:10:08 2009 -0700
@@ -39,45 +39,104 @@
 # 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.Globals import logger, CIM_NS
 from CimTest.ReturnCodes import FAIL, PASS
-from XenKvmLib.const import do_main, platform_sup
+from XenKvmLib.const import do_main, platform_sup, get_provider_version
 from XenKvmLib.classes import get_typed_class
+from pywbem.cim_obj import CIMInstanceName, CIMInstance
+from XenKvmLib.common_util import destroy_netpool, undefine_netpool, \
+                                  verify_pool
+from XenKvmLib.xm_virt_util import net_list
+from VirtLib.utils import run_remote
 
 cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
 cim_mname  = "CreateChildResourcePool"
+libvirt_cim_child_pool_rev = 837
+test_pool = ["routedpool", "natpool", "isolatedpool"]
 
 @do_main(platform_sup)
 def main():
     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)
-            return FAIL
-     
-    logger.error("The execution should not have reached here!!")
-    return FAIL
+
+    curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
+    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(options.virt, 
+                                 'NetPoolResourceAllocationSettingData')
+        addr = "192.168.0.30"
+        n_list = net_list(options.ip, options.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(options.ip, 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",
+                  }     
+        for i in range(0, len(test_pool)):
+            np_id = 'NetworkPool/%s' % test_pool[i]
+            iname = CIMInstanceName(nprasd,
+                                    namespace = CIM_NS,
+                                    keybindings = {'InstanceID':np_id})
+            if test_pool[i] == "routedpool":
+                np_prop["ForwardMode"] = "route eth1"
+            elif test_pool[i] == "natpool":
+                np_prop["ForwardMode"] = "nat"
+
+            nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)
+            try:
+                rpcs_conn.CreateChildResourcePool(ElementName=test_pool[i], 
+                                                  Settings=[nrasd.tomof()])
+                np = get_typed_class(options.virt, 'NetworkPool')
+                status = verify_pool(options.ip, np, np_id)
+                if status != PASS:
+                    raise Exception("Error in networkpool verification")
+                status = destroy_netpool(options.ip, options.virt, test_pool[i])
+                if status != PASS:
+                    raise Exception("Unable to destroy networkpool %s"
+                                    % test_pool[i])
+                status = undefine_netpool(options.ip, options.virt, test_pool[i])
+                if status != PASS:
+                    raise Exception("Unable to undefine networkpool %s"
+                                    % test_pool[i])
+            except Exception, details:
+                logger.error("Error in networkpool %s creation and verification"
+                             " through provider", np_id)
+                logger.error(details)
+                return FAIL
+       
+        return status
+
 if __name__ == "__main__":
     sys.exit(main())
-    
diff -r e8dc06eefada -r fc3416aaa19e suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Tue Apr 21 17:08:06 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Mon Apr 27 01:10:08 2009 -0700
@@ -26,7 +26,8 @@
 from time import sleep
 from distutils.file_util import move_file
 from XenKvmLib.test_xml import * 
-from XenKvmLib.test_doms import * 
+from XenKvmLib.test_doms import *
+from XenKvmLib.enumclass import EnumInstances
 from XenKvmLib import vsms
 from CimTest import Globals 
 from XenKvmLib import enumclass 
@@ -385,7 +386,29 @@
         logger.error("Failed to destroy Virtual Network '%s'", net_name)
         return FAIL
 
-    return PASS 
+    return PASS
+
+def net_undefine(network, server, virt="Xen"):
+    """Function undefine a given virtual network"""
+
+    cmd = "virsh -c %s net-undefine %s" % (virt2uri(virt), network)
+    print cmd
+    ret, out = utils.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 libvirt_cached_data_poll(ip, virt, dom_name):
     cs = None
@@ -435,3 +458,20 @@
 
     return guest_name, devid, PASS
 
+def verify_pool(server, networkpool, poolname):
+    status = FAIL
+    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 == poolname:
+            status = PASS
+            break
+        elif ret_pool != poolname and i == len(pool_list)-1:
+            logger.error("Can not find expected pool")
+
+    return status




More information about the Libvirt-cim mailing list