[Libvirt-cim] [PATCH 2 of 2] [TEST] Adding new test RPCS/10_create_storagevolume.py

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Fri Aug 21 09:49:57 UTC 2009


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1250848107 25200
# Node ID 91a6bc7e18e997c0b3dc28e7677ec5377d114653
# Parent  4b9d9b5b54d1781fe35f24008aeb0fd14a5b10ac
[TEST] Adding new test RPCS/10_create_storagevolume.py

This test verifies the creation of StorageVol in the dir pool.
Tested with KVM on F11 with current sources.
Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 4b9d9b5b54d1 -r 91a6bc7e18e9 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/10_create_storagevolume.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/10_create_storagevolume.py	Fri Aug 21 02:48:27 2009 -0700
@@ -0,0 +1,190 @@
+#!/usr/bin/python
+#
+# Copyright 2009 IBM Corp.
+#
+# Authors:
+#    Deepti B. Kalakeri<dkalaker at in.ibm.com> 
+#    
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+#
+#
+# This test case verifies the creation of the StorageVol using the 
+# CreateResourceInPool method of RPCS.
+#
+#                                                   -Date: 21-08-2009
+
+import sys
+import os
+from VirtLib import utils
+from CimTest.Globals import logger
+from CimTest.ReturnCodes import FAIL, PASS, SKIP
+from XenKvmLib.const import do_main, platform_sup
+from XenKvmLib.const import get_provider_version
+from XenKvmLib.vsms import RASD_TYPE_STOREVOL
+from XenKvmLib.rasd import libvirt_rasd_storagepool_changes
+from XenKvmLib import rpcs_service
+from XenKvmLib.assoc import Associators
+from XenKvmLib.enumclass import GetInstance, EnumNames
+from XenKvmLib.xm_virt_util import virsh_version, vol_list
+from XenKvmLib.classes import get_typed_class, inst_to_mof
+from XenKvmLib.common_util import destroy_diskpool
+from XenKvmLib.pool import create_pool, undefine_diskpool, DIR_POOL
+
+pool_attr = { 'Path' : "/tmp" }
+vol_name = "cimtest-vol.img"
+
+def get_stovol_settings(server, virt, dp_id, pool_name):
+    ac_cn = get_typed_class(virt, "AllocationCapabilities")
+    an_cn = get_typed_class(virt, "SettingsDefineCapabilities")
+    key_list = {"InstanceID" : dp_id }
+    
+    try:
+        inst = GetInstance(server, ac_cn, key_list)
+        dp_rasds = Associators(server, an_cn, ac_cn,
+                               InstanceID=inst.InstanceID)
+    except Exception, detail:
+        logger.error("Exception: %s", detail)
+        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_id
+            dpool_rasd['Path'] = pool_attr['Path']
+            dpool_rasd['VolumeName'] = vol_name
+            break
+
+    if not pool_name in dpool_rasd['PoolID']:
+        return None
+
+    stovol_settings = inst_to_mof(dpool_rasd)
+
+    return stovol_settings
+    
+def get_diskpool(server, virt, dp_cn, dp_inst_id):
+    disk_pool_inst = None
+    dpool_cn = get_typed_class(virt, dp_cn)
+    pools = EnumNames(server, dpool_cn)
+    for pool in pools:
+        if pool['InstanceID'] == dp_inst_id:
+            disk_pool_inst = pool
+
+    return disk_pool_inst
+
+def verify_vol(server, virt, pool_name, exp_vol_path, found):
+    vols = vol_list(server, virt, pool_name)
+    if vols == None:
+        raise Exception("Failed to get the volume information")
+    
+    for vol in vols.split('\n'):
+        res_vol_name, res_vol_path = vol.split()
+        if res_vol_name != vol_name and res_vol_path != exp_vol_path:
+            continue
+        else:
+            found += 1
+
+    if found != 1:
+        logger.error("Failed to get the vol information")
+
+    return found 
+
+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)
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        return FAIL
+
+    if os.path.exists(exp_vol_path):
+        cmd = "rm -rf %s" % exp_vol_path
+        ret, out = utils.run_remote(server, cmd)
+        if ret != 0:
+            logger.info("'%s' was not removed, please remove it manually", 
+                        exp_vol_path)
+    return PASS
+
+ at do_main(platform_sup)
+def main():
+    options = main.options
+    server = options.ip
+    virt = options.virt
+
+    libvirt_version = virsh_version(server, virt)
+    cim_rev, changeset = get_provider_version(virt, server)
+    if libvirt_version < "0.4.1" and cim_rev < libvirt_rasd_storagepool_changes:
+        logger.info("Storage Volume creation support is available with Libvirt" 
+                    "version >= 0.4.1 and Libvirt-CIM rev '%s'", 
+                    libvirt_rasd_storagepool_changes)
+        return SKIP
+
+    dp_cn = "DiskPool"
+    exp_vol_path = "%s/%s" % (pool_attr['Path'], vol_name)
+
+    # For now the test case support only the creation of dir type based 
+    # vol creation, we can extend dp_types to include netfs etc 
+    dp_types = { "DISK_POOL_DIR" : DIR_POOL }
+
+    for pool_name, pool_type in dp_types.iteritems():    
+        status = FAIL     
+        res = [FAIL]
+        found = 0
+        try:
+            status = create_pool(server, virt, pool_name, pool_attr, 
+                                 mode_type=pool_type, pool_type="DiskPool")
+
+            if status != PASS:
+                logger.error("Failed to create pool '%s'", pool_name)
+                return status
+
+            dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+            stovol_settings = get_stovol_settings(server, virt, 
+                                                  dp_inst_id, pool_name)
+            if stovol_settings == None:
+                raise Exception("Failed to get the defualt StorageVolRASD info")
+
+            disk_pool_inst = get_diskpool(server, virt, dp_cn, dp_inst_id)
+            if disk_pool_inst == None:
+                raise Exception("DiskPool instance for '%s' not found!" \
+                                % pool_name)
+  
+            rpcs = get_typed_class(virt, "ResourcePoolConfigurationService")
+            rpcs_conn = eval("rpcs_service." + rpcs)(server)
+            res = rpcs_conn.CreateResourceInPool(Settings=stovol_settings, 
+                                                 Pool=disk_pool_inst)
+            found = verify_vol(server, virt, pool_name, exp_vol_path, found)
+        
+        except Exception, details:
+            logger.error("Exception details: %s", details)
+            status = FAIL
+
+        ret = cleanup_pool_vol(server, virt, pool_name, exp_vol_path)
+        if res[0] == PASS and found == 1 and ret == PASS:
+            status = PASS
+        else:
+            return FAIL
+        
+    return status
+if __name__ == "__main__":
+    sys.exit(main())




More information about the Libvirt-cim mailing list