[Libvirt-cim] [PATCH 1 of 5] [TEST] #4 Modified pool.py to support RPCS CreateResourceInPool

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Wed Sep 16 17:51:34 UTC 2009


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1253106314 25200
# Node ID 741c93090d6f7cffadc7684563590282b073149d
# Parent  d35d1a2956a81c7798712ec3b6d4a3906c75e480
[TEST] #4 Modified pool.py to support RPCS CreateResourceInPool.

Patch 4:
--------
1) Moved cleanup_pool_vol() to pool.py as it referenced by couple of tests

PS: will update RPCS/10*py to reference cleanup_pool_vol() from pool.py once
these patches get accepted.

Patch 3:
--------
1) Moved get_sto_vol_rasd() to pool.py as get_sto_vol_rasd_for_pool(),
   since it is used in RPCS/13*py and RPCS/14*py

Patch 2:
-------
1) Added check in get_stovol_rasd_from_sdc()
2) Added get_diskpool() to pool.py as it is used in 10*py/11*py, RPCS/12*py
   and will be useful for further tests as well
3) Added rev for storagevol deletion

NOTE: Please base this patch on the patch "Modifying common_util.py for netnfs"

Patch 1:
--------
Added the following two functions which are used in RPCS/10*py and RPCS/11*py
1) get_stovol_rasd_from_sdc() to get the stovol rasd from sdc
2) get_stovol_default_settings() to get default sto vol settings
Also, modified common_util.py to remove the backed up exportfs file
Added RAW_VOL_TYPE which is the FormatType supported by RPCS currently

Once this patch gets accepted we can modify RPCS/10*py to refer to these functions.
Tested with KVM and current sources on SLES11.
Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r d35d1a2956a8 -r 741c93090d6f suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Wed Sep 16 06:05:10 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Wed Sep 16 06:05:14 2009 -0700
@@ -582,6 +582,8 @@
     try:
         # Backup the original exports file.
         if (os.path.exists(exports_file)):
+            if os.path.exists(back_exports_file):
+                os.remove(back_exports_file)
             move_file(exports_file, back_exports_file)
         fd = open(exports_file, "w")
         line = "\n %s %s(rw)" %(src_dir_for_mnt, server)
diff -r d35d1a2956a8 -r 741c93090d6f suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py	Wed Sep 16 06:05:10 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py	Wed Sep 16 06:05:14 2009 -0700
@@ -21,11 +21,13 @@
 #
 
 import sys
+import os
+from VirtLib import utils
 from CimTest.Globals import logger, CIM_NS
 from CimTest.ReturnCodes import PASS, FAIL, SKIP
 from XenKvmLib.classes import get_typed_class, inst_to_mof
 from XenKvmLib.const import get_provider_version, default_pool_name 
-from XenKvmLib.enumclass import EnumInstances, GetInstance
+from XenKvmLib.enumclass import EnumInstances, GetInstance, EnumNames
 from XenKvmLib.assoc import Associators
 from VirtLib.utils import run_remote
 from XenKvmLib.xm_virt_util import virt2uri, net_list
@@ -34,11 +36,14 @@
 from CimTest.CimExt import CIMClassMOF
 from XenKvmLib.vxml import NetXML, PoolXML
 from XenKvmLib.xm_virt_util import virsh_version
+from XenKvmLib.vsms import RASD_TYPE_STOREVOL
+from XenKvmLib.common_util import destroy_diskpool
 
 cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
 cim_mname  = "CreateChildResourcePool"
 input_graphics_pool_rev = 757
 libvirt_cim_child_pool_rev = 837
+libvirt_rasd_spool_del_changes = 971
 
 DIR_POOL = 1L
 FS_POOL = 2L
@@ -48,6 +53,9 @@
 LOGICAL_POOL = 6L
 SCSI_POOL = 7L
 
+#Volume types
+RAW_VOL_TYPE = 1
+
 def pool_cn_to_rasd_cn(pool_cn, virt):
     if pool_cn.find('ProcessorPool') >= 0:
         return get_typed_class(virt, "ProcResourceAllocationSettingData")
@@ -297,3 +305,100 @@
             status = PASS
 
     return status
+
+def get_stovol_rasd_from_sdc(virt, server, dp_inst_id):
+    rasd = None
+    ac_cn = get_typed_class(virt, "AllocationCapabilities")
+    an_cn = get_typed_class(virt, "SettingsDefineCapabilities")
+    key_list = {"InstanceID" : dp_inst_id} 
+    
+    try:
+        inst = GetInstance(server, ac_cn, key_list)
+        if inst == None:
+            raise Exception("Failed to GetInstance for %s" % dp_inst_id)
+
+        rasd = Associators(server, an_cn, ac_cn, InstanceID=inst.InstanceID)
+        if len(rasd) < 4:
+            raise Exception("Failed to get default StorageVolRASD , "\
+                            "Expected atleast 4, Got '%s'" % len(rasd))
+
+    except Exception, detail:
+        logger.error("Exception: %s", detail)
+        return FAIL, None
+
+    return PASS, rasd
+
+def get_stovol_default_settings(virt, server, dp_cn,
+                                pool_name, path, vol_name):
+
+    dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+    status, dp_rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id) 
+    if status != PASS:
+        logger.error("Failed to get the StorageVol RASD's")
+        return None
+
+    for dpool_rasd in dp_rasds:
+        if dpool_rasd['ResourceType'] == RASD_TYPE_STOREVOL and \
+            'Default' in dpool_rasd['InstanceID']:
+
+            dpool_rasd['PoolID'] =  dp_inst_id
+            dpool_rasd['Path'] = path 
+            dpool_rasd['VolumeName'] = vol_name
+            break
+
+    if not pool_name in dpool_rasd['PoolID']:
+        return None
+
+    return dpool_rasd
+
+def get_diskpool(server, virt, dp_cn, pool_name):
+    dp_inst = None
+    dpool_cn = get_typed_class(virt, dp_cn)
+    pools = EnumNames(server, dpool_cn)
+
+    dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+    for pool in pools:
+        if pool['InstanceID'] == dp_inst_id:
+            dp_inst = pool
+            break
+
+    return dp_inst
+
+def get_sto_vol_rasd_for_pool(virt, server, dp_cn, pool_name, exp_vol_path):
+    dv_rasds = None 
+    dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+    status, rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id)
+    if status != PASS:     
+        logger.error("Failed to get the StorageVol for '%s' vol", exp_vol_path)
+        return FAIL
+
+    for item in rasds:
+        if item['Address'] == exp_vol_path and item['PoolID'] == dp_inst_id:
+           dv_rasds = item
+           break 
+    
+    return dv_rasds
+
+def cleanup_pool_vol(server, virt, pool_name, exp_vol_path):
+    try:
+        status = destroy_diskpool(server, virt, pool_name)
+        if status != PASS:
+            raise Exception("Unable to destroy diskpool '%s'" % pool_name)
+        else:
+            status = undefine_diskpool(server, virt, pool_name)
+            if status != PASS:
+                raise Exception("Unable to undefine diskpool '%s'" % pool_name)
+
+        if os.path.exists(exp_vol_path):
+            cmd = "rm -rf %s" % exp_vol_path
+            ret, out = utils.run_remote(server, cmd)
+            if ret != 0:
+                raise Exception("'%s' was not removed, please remove it "\
+                                "manually" % exp_vol_path)
+
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        return FAIL
+
+    return PASS
+




More information about the Libvirt-cim mailing list