[Libvirt-cim] [PATCH 3 of 5] [TEST] Added new tc to verify the RPCS error values for netfs pool

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Mon Sep 14 17:55:04 UTC 2009


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1252950136 25200
# Node ID dec604e54eceb2c28f9dce3c9b22d87b152eb614
# Parent  10f8d110cd079ed7be6875efa0c65ea47e810cb5
[TEST] Added new tc to verify the RPCS error values for netfs pool.

 This test case verifies the creation of the StorageVol using the
 CreateResourceInPool method of RPCS returns an error when invalid values
 are passed.
 The test case checks for the errors when, Trying to create a Vol in a netfs storage pool.

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

diff -r 10f8d110cd07 -r dec604e54ece suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/12_create_netfs_storagevolume_errs.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/12_create_netfs_storagevolume_errs.py	Mon Sep 14 10:42:16 2009 -0700
@@ -0,0 +1,193 @@
+#!/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 returns an error when invalid values
+# are passed.
+# The test case checks for the errors when,
+# Trying to create a Vol in a netfs storage pool
+#
+#                                                   -Date: 04-09-2009
+
+import sys
+import os
+from VirtLib import utils
+from pywbem import CIM_ERR_FAILED, CIMError
+from CimTest.Globals import logger
+from CimTest.ReturnCodes import FAIL, PASS, SKIP
+from XenKvmLib.const import do_main, platform_sup, get_provider_version
+from XenKvmLib.rasd import libvirt_rasd_storagepool_changes
+from XenKvmLib import rpcs_service
+from XenKvmLib.xm_virt_util import virsh_version
+from XenKvmLib.classes import get_typed_class, inst_to_mof
+from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \
+                                  netfs_cleanup
+from XenKvmLib.pool import create_pool, undefine_diskpool, NETFS_POOL, \
+                           get_diskpool, get_stovol_rasd_from_sdc, \
+                           get_stovol_default_settings
+
+vol_name = "cimtest-vol.img"
+vol_path = "/tmp/"
+
+exp_err_no = CIM_ERR_FAILED
+exp_err_values = { 'NETFS_POOL'   : { 'msg'   : "This function does not "\
+                                                "support this resource type"}
+                 }
+
+def get_pool_attr(server, pool_type):
+    pool_attr = { }
+    status , host_addr, src_mnt_dir, dir_mnt_dir = nfs_netfs_setup(server)
+    if status != PASS:
+        logger.error("Failed to get pool_attr for NETFS diskpool type")
+        return status, pool_attr
+
+    pool_attr['Host'] = host_addr
+    pool_attr['SourceDirectory'] = src_mnt_dir
+    pool_attr['Path'] = dir_mnt_dir
+
+    return PASS, pool_attr
+
+def get_inputs(virt, server, dp_cn, pool_name, exp_vol_path):
+    sv_rasd = dp_inst = None
+    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)
+
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        return FAIL, sv_rasd, dp_inst
+
+    return PASS, sv_settings, dp_inst
+
+def verify_vol_err(server, virt, dp_cn, pool_name, exp_vol_path): 
+
+    status, sv_settings, dp_inst = get_inputs(virt, server, dp_cn, 
+                                              pool_name, exp_vol_path)
+    if status != PASS:
+        return status
+     
+    status = FAIL
+    res = [FAIL] 
+    try:
+        rpcs = get_typed_class(virt, "ResourcePoolConfigurationService")
+        rpcs_conn = eval("rpcs_service." + rpcs)(server)
+        res = rpcs_conn.CreateResourceInPool(Settings=sv_settings, 
+                                             Pool=dp_inst)
+
+    except CIMError, (err_no, err_desc):
+        if res[0] != PASS and exp_err_values[pool_name]['msg'] in err_desc \
+           and exp_err_no == err_no:
+            logger.error("Got the expected error message: '%s' with '%s'", 
+                          err_desc, pool_name)
+            return PASS
+        else:
+            logger.error("Failed to get the error message '%s'", 
+                         exp_err_values[pool_name]['msg'])
+    if res[0] == PASS:
+        logger.error("Should not have been able to create the StorageVol '%s'", 
+                      vol_name)
+
+    return FAIL
+
+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
+
+ 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_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
+
+    pool_name =  "NETFS_POOL"
+    pool_type = NETFS_POOL
+    exp_vol_path = "%s/%s" % (vol_path, vol_name)
+    dp_cn = "DiskPool"
+    
+    try:
+        status = FAIL     
+        status, pool_attr = get_pool_attr(server, pool_type)
+        if status != PASS:
+            return status
+
+        # Creating NETFS pool to verify RPCS error
+        status = create_pool(server, virt, pool_name, pool_attr, 
+                             mode_type=pool_type, pool_type=dp_cn)
+
+        if status != PASS:
+            logger.error("Failed to create pool '%s'", pool_name)
+            return status
+
+        status = verify_vol_err(server, virt, dp_cn, pool_name, exp_vol_path)
+        if status != PASS :
+            raise Exception("Failed to verify the Invlaid '%s' " % pool_name)
+
+        
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        status = FAIL
+
+    netfs_cleanup(server, pool_attr)
+    ret = cleanup_pool_vol(server, virt, pool_name, exp_vol_path)
+    if status != PASS or ret != PASS :
+        return FAIL
+        
+    return PASS
+if __name__ == "__main__":
+    sys.exit(main())




More information about the Libvirt-cim mailing list