# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1253007574 25200
# Node ID e609ddcebda460ccf547ccae0bca195c52804f66
# Parent e19295361dd7f52fbd9a56dd33e0306b1b71b245
[TEST] #2 Add new tc to verify the DeleteResourceInPool().
Patch2:
------
1) Added the missing test case.
2) Included get_sto_vol_rasd_for_pool() from pool.py
Tested with KVM and current sources on SLES11.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r e19295361dd7 -r e609ddcebda4
suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume.py Tue
Sep 15 02:39:34 2009 -0700
@@ -0,0 +1,160 @@
+#!/usr/bin/python
+#
+# Copyright 2009 IBM Corp.
+#
+# Authors:
+# Deepti B. Kalakeri<dkalaker(a)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.
+#
+# -Date: 08-09-2009
+
+import sys
+import os
+from VirtLib import utils
+from CimTest.Globals import logger
+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.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, get_sto_vol_rasd_for_pool
+
+pool_attr = { 'Path' : "/tmp" }
+vol_name = "cimtest-vol.img"
+
+def cleanup_pool_vol(server, virt, pool_name, clean_vol, exp_vol_path):
+ try:
+ if clean_vol == True:
+ 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
+
+
+@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)
+
+ # For now the test case support only the deletion of dir type based
+ # vol, 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 = del_res = [FAIL]
+ clean_pool = True
+ try:
+ if pool_type == DIR_POOL:
+ pool_name = default_pool_name
+ clean_pool = False
+ else:
+ 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
+
+ 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)
+
+ res_settings = get_sto_vol_rasd_for_pool(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)
+
+ resource_setting = inst_to_mof(res_settings)
+ del_res = rpcs_conn.DeleteResourceInPool(Resource=resource_setting,
+ Pool=dp_inst)
+
+ res_settings = get_sto_vol_rasd_for_pool(virt, server, dp_cn,
+ pool_name, exp_vol_path)
+ if res_settings != None:
+ raise Exception("'%s' vol of '%s' pool was not
deleted" \
+ % (vol_name, pool_name))
+ else:
+ logger.info("Vol '%s' of '%s' pool deleted
successfully by "
+ "DeleteResourceInPool()", vol_name, pool_name)
+
+ except Exception, details:
+ logger.error("Exception details: %s", details)
+ status = FAIL
+
+ ret = cleanup_pool_vol(server, virt, pool_name,
+ clean_pool, exp_vol_path)
+ if del_res[0] == PASS and ret == PASS :
+ status = PASS
+ else:
+ return FAIL
+
+ return status
+if __name__ == "__main__":
+ sys.exit(main())