[Libvirt-cim] [PATCH] [TEST] 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
Fri Apr 24 05:35:04 UTC 2009


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


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

diff -r e8dc06eefada -r f279580cad62 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py
--- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py	Tue Apr 21 17:08:06 2009 -0700
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py	Thu Apr 23 22:34:55 2009 -0700
@@ -33,10 +33,12 @@
 # OUT -- Job -- CIM_ConcreteJob REF -- Returned job if started
 # OUT -- Error-- String -- Encoded error instance if the operation 
 #                          failed and did not return a job.
-# REVISIT : 
-# --------
-# As of now the DeleteResourcePool() simply throws an Exception.
-# We must improve this tc once the service is implemented. 
+#
+# Exception details before Revision 841
+# -----
+# Error code: CIM_ERR_NOT_SUPPORTED 
+#
+# After revision 841, the service is implemented
 # 
 #                                                  -Date: 20.02.2008
 
@@ -45,33 +47,84 @@
 import pywbem 
 from XenKvmLib import rpcs_service
 from CimTest.Globals import logger
+from CimTest.Globals import 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 pywbem.cim_obj import CIMInstanceName, CIMInstance
+from XenKvmLib.enumclass import EnumInstances
 from XenKvmLib.classes import get_typed_class
 
 cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
 cim_mname  = "DeleteResourcePool"
+libvirt_cim_child_pool_rev = 841
+test_pool = "nat_pool"
 
 @do_main(platform_sup)
 def main():
+    status = FAIL
     options = main.options
     rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \
                       "ResourcePoolConfigurationService"))(options.ip)
-    try:
-        rpcs_conn.DeleteResourcePool()
-    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.DeleteResourcePool()
+        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')
+        np = get_typed_class(options.virt, 'NetworkPool')                          
+        np_id = 'NetworkPool/%s' % test_pool
+        iname = CIMInstanceName(nprasd,
+                                namespace = CIM_NS,
+                                keybindings = {'InstanceID':np_id})
+        np_prop = {
+                   "Address" : "192.168.0.20",
+                   "Netmask" : "255.255.255.0",
+                   "IPRangeStart" : "192.168.0.21",
+                   "IPRangeEnd"   : "192.168.0.30"
+                  }                       
+        nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)     
+        try:
+            rpcs_conn.CreateChildResourcePool(ElementName=test_pool,
+                                              Settings=[nrasd.tomof()])
+            netpool = EnumInstances(options.ip, np)
+            if len(netpool) < 1:
+                raise Exception("Return %i instances, expected at least"\
+                                "one instance" % len(netpool))
+            for i in range(0, len(netpool)):
+                ret_pool = netpool[i].InstanceID
+                if ret_pool == np_id:
+                    break
+                elif ret_pool != np_id and i == len(netpool) - 1:
+                    raise Exception("Can not find expected pool")
+
+            pool = CIMInstanceName(np, keybindings = {'InstanceID':np_id})
+            rpcs_conn.DeleteResourcePool(Pool = pool)
+            netpool = EnumInstances(options.ip, np)
+            if len(netpool) < 1:
+                status = PASS
+            else:
+                for i in range(0, len(netpool)):
+                    ret_pool = netpool[i].InstanceID
+                    if ret_pool == np_id:
+                        raise Exception("Failed to delete %s" % test_pool)
+                        break
+                    elif ret_pool != np_id and i == len(netpool) -1:
+                        status = PASS
+        except Exception, details:
+            logger.error(details)
+            return status
+                 
+        return status
 if __name__ == "__main__":
     sys.exit(main())
-    




More information about the Libvirt-cim mailing list