[Libvirt-cim] [PATCH 3 of 3] [TEST] Add new tc to verify the err values for RPCS DeleteResourceInPool()

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Tue Sep 8 19:24:36 UTC 2009


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1252437748 25200
# Node ID 616c8e4217a138a001a9223363c3fdd2bb448f13
# Parent  c127b5047569b1a7fbb7e2a266e8e8fea71e762e
[TEST] Add new tc to verify the err values for RPCS DeleteResourceInPool()

Tested with KVM and current sources on SLES11.
Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r c127b5047569 -r 616c8e4217a1 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume_errs.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume_errs.py	Tue Sep 08 12:22:28 2009 -0700
@@ -0,0 +1,191 @@
+#!/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 deletion of the StorageVol using the 
+# DeleteResourceInPool method of RPCS returns error when invalid values are 
+# passed.
+#
+#                                                   -Date: 08-09-2009
+
+import sys
+import os
+from VirtLib import utils
+from CimTest.Globals import logger
+from pywbem import CIM_ERR_FAILED, CIM_ERR_INVALID_PARAMETER, CIMError
+from CimTest.ReturnCodes import FAIL, PASS, SKIP
+from XenKvmLib.xm_virt_util import virsh_version
+from XenKvmLib.const import do_main, platform_sup, default_pool_name, \
+                            get_provider_version
+from XenKvmLib import rpcs_service
+from XenKvmLib.assoc import Associators
+from XenKvmLib.enumclass import GetInstance, EnumNames
+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, \
+                           libvirt_rasd_spool_del_changes, get_diskpool, \
+                           get_stovol_default_settings, \
+                           get_stovol_rasd_from_sdc
+
+pool_attr = { 'Path' : "/tmp" }
+vol_name = "cimtest-vol.img"
+invalid_scen = { "INVALID_ADDRESS"  : { 'val' : 'Junkvol_path',
+                                        'msg' : 'no storage vol with '\
+                                                'matching path' },
+                 "NO_ADDRESS"        : { 'msg' :'Missing Address in '\
+                                                'resource RASD' },
+                 "MISSING_RESOURCE"  : { 'msg' :"Missing argument `Resource'"},
+                 "MISSING_POOL"      : { 'msg' :"Missing argument `Pool'"}
+               }
+                                           
+
+def get_sto_vol_rasd(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 verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, 
+                        exp_vol_path, dp_inst):
+    for err_scen in invalid_scen.keys():    
+        logger.info("Verifying errors for '%s'....", err_scen)
+        status = FAIL
+        del_res = [FAIL] 
+        try:
+            res_settings = get_sto_vol_rasd(virt, server, dp_cn, 
+                                            pool_name, exp_vol_path)
+            if res_settings == None:
+                raise Exception("Failed to get the resource settings for '%s'" \
+                                " Vol" % vol_name)
+            if not "MISSING" in err_scen:
+                exp_err_no = CIM_ERR_FAILED
+                if "NO_ADDRESS" in err_scen:
+                    del res_settings['Address'] 
+                elif "INVALID_ADDRESS" in err_scen:
+                    res_settings['Address'] = invalid_scen[err_scen]['val']
+
+                resource = inst_to_mof(res_settings) 
+                del_res = rpcs_conn.DeleteResourceInPool(Resource=resource,
+                                                         Pool=dp_inst)
+            else:
+                exp_err_no = CIM_ERR_INVALID_PARAMETER
+                if err_scen == "MISSING_RESOURCE":
+                    del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst)
+                elif err_scen == "MISSING_POOL":
+                    del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
+
+        except CIMError, (err_no, err_desc):
+            if invalid_scen[err_scen]['msg'] in err_desc \
+               and exp_err_no == err_no:
+                logger.error("Got the expected error message: '%s' for '%s'", 
+                              err_desc, err_scen)
+                status=PASS
+            else:
+                logger.error("Failed to get the error message '%s'", 
+                             invalid_scen[err_scen]['msg'])
+
+        if del_res[0] == PASS:
+            logger.error("Should not have been able to delete Vol %s", vol_name)
+            return FAIL
+
+    return status
+
+def cleanup_pool_vol(server, exp_vol_path):
+    try:
+        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
+
+
+ at do_main(platform_sup)
+def main():
+    options = main.options
+    server = options.ip
+    virt = options.virt
+
+    libvirt_ver = virsh_version(server, virt)
+    cim_rev, changeset = get_provider_version(virt, server)
+    if libvirt_ver < "0.4.1" and cim_rev < libvirt_rasd_spool_del_changes:
+        logger.info("Storage Volume deletion support is available with Libvirt"
+                    "version >= 0.4.1 and Libvirt-CIM rev '%s'", 
+                    libvirt_rasd_spool_del_changes)
+        return SKIP
+
+    dp_cn = "DiskPool"
+    exp_vol_path = "%s/%s" % (pool_attr['Path'], vol_name)
+
+    pool_name = default_pool_name
+    pool_type =  DIR_POOL 
+    status = FAIL     
+    res = del_res = [FAIL]
+    try:
+        sv_rasd = get_stovol_default_settings(virt, server, dp_cn, pool_name, 
+                                              exp_vol_path, vol_name)
+        if sv_rasd == None:
+            raise Exception("Failed to get the defualt StorageVolRASD info")
+
+        sv_settings = inst_to_mof(sv_rasd)
+
+        dp_inst = get_diskpool(server, virt, dp_cn, pool_name)
+        if dp_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=sv_settings, 
+                                             Pool=dp_inst)
+        if res[0] != PASS:
+            raise Exception("Failed to create the Vol %s" % vol_name)
+
+        status = verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, 
+                                     pool_name, exp_vol_path, dp_inst)
+        if status != PASS :
+            raise Exception("Failed to verify the error")
+
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        status = FAIL
+
+    ret = cleanup_pool_vol(server, exp_vol_path)
+        
+    return status
+if __name__ == "__main__":
+    sys.exit(main())




More information about the Libvirt-cim mailing list