
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1253186627 14400 # Node ID 0387cadda7d381253e2645a0bd9ff8bfd9990fa6 # Parent 26357e57d207c3437a06a0730e99c942111901f3 [TEST] Adding vol_delete and modifying RPCS/10_create_storagevolume.py 1) Adding vol_delete() to xm_virt_util.py to delete a volume of a pool. 2) Updating RPCS/10_create_storagevolume.py to include vol_delete. Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 26357e57d207 -r 0387cadda7d3 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/10_create_storagevolume.py --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/10_create_storagevolume.py Wed Sep 16 09:03:39 2009 -0400 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/10_create_storagevolume.py Thu Sep 17 07:23:47 2009 -0400 @@ -38,7 +38,7 @@ 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.xm_virt_util import virsh_version, vol_list, vol_delete 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 @@ -129,9 +129,22 @@ return PASS -def cleanup_pool_vol(server, virt, pool_name, clean_vol, exp_vol_path): +def cleanup_pool_vol(server, virt, pool_name, clean_pool, vol_path): + status = res = FAIL + ret = None try: - if clean_vol == True: + ret = vol_delete(server, virt, vol_name, pool_name) + if ret == None: + logger.error("Failed to delete the volume '%s'", vol_name) + + if os.path.exists(vol_path): + cmd = "rm -rf %s" % vol_path + res, out = utils.run_remote(server, cmd) + if res != 0: + logger.error("'%s' was not removed, please remove it " + "manually", vol_path) + + if clean_pool == True: status = destroy_diskpool(server, virt, pool_name) if status != PASS: raise Exception("Unable to destroy diskpool '%s'" % pool_name) @@ -140,16 +153,16 @@ if status != PASS: raise Exception("Unable to undefine diskpool '%s'" \ % pool_name) + + except Exception, details: logger.error("Exception details: %s", details) + status = FAIL + + if (ret == None and res != PASS) or (clean_pool == True and status != PASS): + logger.error("Failed to clean the env.....") 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 @do_main(platform_sup) @@ -211,18 +224,19 @@ found = verify_vol(server, virt, pool_name, exp_vol_path, found) stovol_status = verify_sto_vol_rasd(virt, server, dp_inst_id, exp_vol_path) + + ret = cleanup_pool_vol(server, virt, pool_name, + clean_pool, exp_vol_path) + if res[0] == PASS and found == 1 and \ + ret == PASS and stovol_status == PASS: + status = PASS + else: + return FAIL 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 res[0] == PASS and found == 1 and \ - ret == PASS and stovol_status == PASS: - status = PASS - else: - return FAIL return status if __name__ == "__main__": diff -r 26357e57d207 -r 0387cadda7d3 suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Wed Sep 16 09:03:39 2009 -0400 +++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Thu Sep 17 07:23:47 2009 -0400 @@ -238,9 +238,9 @@ return names def vol_list(server, virt="KVM", pool_name=None): - """ Function to list the volumes part of a pool""" + """ Function to list the volumes of a pool""" - cmd = " virsh -c %s vol-list %s | sed -e '1,2 d' -e '$ d'" \ + cmd = "virsh -c %s vol-list %s | sed -e '1,2 d' -e '$ d'" \ % (virt2uri(virt), pool_name) ret, out = utils.run_remote(server, cmd) if ret != 0: @@ -248,6 +248,18 @@ return out +def vol_delete(server, virt="KVM", vol_name=None, pool_name=None): + """ Function to delete the volume of a pool""" + + cmd = "virsh -c %s vol-delete %s --pool %s"\ + % (virt2uri(virt), vol_name, pool_name) + ret, out = utils.run_remote(server, cmd) + if ret != 0: + return None + + return out + + def virsh_vcpuinfo(server, dom, virt="Xen"): cmd = "virsh -c %s vcpuinfo %s | grep VCPU | wc -l" % (virt2uri(virt), dom)