[PATCH 0 of 3] [TEST] Adding netfs diskpool creation to RPCS/08_CreateDiskResourcePool.py tc

# HG changeset patch # User Deepti B. Kalakeri<deeptik@linux.vnet.com> # Date 1245324295 25200 # Node ID b475307a2b5511de4d795a27377a40618eafa188 # Parent 9a2db4596db33348b860a0e2337e377f237b0692 [TEST] Modifying vxml.py to include netfs related info. Tested on F10 with KVM and current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 9a2db4596db3 -r b475307a2b55 suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Jun 03 13:00:09 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Jun 18 04:24:55 2009 -0700 @@ -331,10 +331,15 @@ dpoolname = self.get_value_xpath('/pool/name') return dpoolname - def xml_get_pool_attr_list(self): + def xml_get_pool_attr_list(self, mode_type=1): pool_attr_list = [] poolpath = self.get_value_xpath('/pool/target/path') pool_attr_list.append(poolpath) + if mode_type == 3: #Netfs + host = self.get_value_xpath('/pool/source/host/@name') + pool_attr_list.append(host) + src_dir = self.get_value_xpath('/pool/source/dir/@path') + pool_attr_list.append(src_dir) return pool_attr_list

# HG changeset patch # User Deepti B. Kalakeri<deeptik@linux.vnet.com> # Date 1245326842 25200 # Node ID 8510887c62ad37e1a96caff666d2ca5a94921e99 # Parent b475307a2b5511de4d795a27377a40618eafa188 [TEST] #2 Adding nfs_netfs_setup() to configure nfs server setup... Updates: -------- Patch 2: -------- 1) Removed the mount command 2) Rearranged the nfs_config steps to check the nfs bin existence first 3) Added code to backup the original /etc/exports file 4) Modified netfs_cleanup to restore the backed up /etc/exports Patch 1: -------- 1) nfs_netfs_setup() configures the nfs server and makes necessary arrangements for netfs pool creation. 2) nfs_config() setups nfs server 3) netfs_config() makes necessary arrangements for netfs pool creation. 4) get_nfs_bin() gets proper nfs server binary 5) clean_temp_files() cleans the temp dir created for nfs mount 6) netfs_cleanup() cleans up removes the dir created, restarts the nfs server.. Tested on F10 with KVM and current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r b475307a2b55 -r 8510887c62ad suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jun 18 04:24:55 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jun 18 05:07:22 2009 -0700 @@ -24,6 +24,7 @@ import pywbem import random from time import sleep +from tempfile import mkdtemp from distutils.file_util import move_file from XenKvmLib.test_xml import * from XenKvmLib.test_doms import * @@ -34,7 +35,7 @@ from XenKvmLib.classes import get_typed_class from CimTest.Globals import logger, CIM_ERROR_ENUMERATE, \ CIM_ERROR_GETINSTANCE -from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC +from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC, SKIP from XenKvmLib.xm_virt_util import diskpool_list, virsh_version, net_list,\ domain_list, virt2uri, net_destroy from XenKvmLib.vxml import PoolXML, NetXML @@ -42,8 +43,9 @@ from XenKvmLib.const import default_pool_name, default_network_name disk_file = '/etc/libvirt/diskpool.conf' - +exports_file = '/etc/exports' back_disk_file = disk_file + "." + "backup" +back_exports_file = exports_file + "." + "backup" def print_field_error(fieldname, ret_value, exp_value): logger.error("%s Mismatch", fieldname) @@ -435,3 +437,111 @@ return guest_name, devid, PASS + +def get_nfs_bin(server): + cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'" + rc, out = utils.run_remote(server, cmd) + if rc != 0: + #SLES + nfs_server_bin = "/etc/init.d/nfsserver" + else: + nfs_server_bin = "/etc/init.d/nfs" + + return nfs_server_bin + +def nfs_config(server, nfs_server_bin): + cmd = "ps aux | grep -v -e nfsiod -e grep | grep nfsd" + rc, out = utils.run_remote(server, cmd) + # if NFS services is not found on the machine, start it.. + if rc != PASS : + # Check if NFS server is installed ... + if not os.path.exists(nfs_server_bin): + logger.error("NFS server '%s' does not seem to be installed "\ + "on '%s'", nfs_server_bin, server) + return SKIP + + # Start the nfs server ... + nfs_server_cmd = "%s start" % nfs_server_bin + rc, out = utils.run_remote(server, nfs_server_cmd) + if rc != PASS: + logger.error("Could not start the nfsserver on '%s'", server) + logger.error("NFS server seems to have problem on '%s'", server) + return FAIL + + return PASS + +def clean_temp_files(server, src_dir_for_mnt, dest_dir_to_mnt): + cmd = "rm -rf %s %s" % (src_dir_for_mnt, dest_dir_to_mnt) + rc, out = utils.run_remote(server, cmd) + if rc != PASS: + logger.error("Please delete %s %s if present on %s", + src_dir_for_mnt, dest_dir_to_mnt, server) + + +def netfs_cleanup(server, pool_attr): + src_dir = os.path.basename(pool_attr['SourceDirectory']) + dst_dir = pool_attr['Path'] + + # Remove the temp dir created . + clean_temp_files(server, src_dir, dst_dir) + + # Restore the original exports file. + if os.path.exists(back_exports_file): + os.remove(exports_file) + move_file(back_exports_file, exports_file) + + # restart the nfs server + nfs_server_bin = get_nfs_bin(server) + nfs_server_cmd = "%s restart" % nfs_server_bin + rc, out = utils.run_remote(server, nfs_server_cmd) + if rc != PASS: + logger.error("Could not restart NFS server on '%s'" % server) + +def netfs_config(server, nfs_server_bin): + src_dir_for_mnt = mkdtemp() + dest_dir_to_mnt = mkdtemp() + + try: + # Backup the original exports file. + if (os.path.exists(exports_file)): + move_file(exports_file, back_exports_file) + fd = open(exports_file, "w") + line = "\n %s %s(rw)" %(src_dir_for_mnt, server) + fd.write(line) + fd.close() + + # Need to give suitable perm, otherwise netfs pool-create fails + cmd = "chmod go+rx %s %s" % (src_dir_for_mnt, dest_dir_to_mnt) + rc, out = utils.run_remote(server, cmd) + if rc != 0: + raise Exception("Failed to chmod on %s %s" \ + % (src_dir_for_mnt, dest_dir_to_mnt)) + + # Restart the nfs server.... + nfs_server_cmd = "%s restart" % nfs_server_bin + rc, out = utils.run_remote(server, nfs_server_cmd) + if rc != PASS: + raise Exception("Could not restart NFS server on '%s'" % server) + + except Exception, detail: + logger.error("Exception details : %s", detail) + clean_temp_files(server, src_dir_for_mnt, dest_dir_to_mnt) + return FAIL, None, None + + return PASS, src_dir_for_mnt, dest_dir_to_mnt + +def nfs_netfs_setup(server): + nfs_server_bin = get_nfs_bin(server) + + # Before going ahead verify that nfs server is available on machine.. + ret = nfs_config(server, nfs_server_bin) + if ret != PASS: + logger.error("Failed to configure NFS on '%s'", server) + return FAIL, None, None + + ret, src_dir, destr_dir = netfs_config(server, nfs_server_bin) + if ret != PASS: + logger.error("Failed to configure netfs on '%s'", server) + return FAIL, None, None + + return PASS, src_dir, destr_dir

# HG changeset patch # User Deepti B. Kalakeri<deeptik@linux.vnet.com> # Date 1245329707 25200 # Node ID d0a02ab76e76bcfe1d230c3b4c1960b86f060077 # Parent 8510887c62ad37e1a96caff666d2ca5a94921e99 [TEST] #2 Adding netfs diskpool creation to RPCS/08_CreateDiskResourcePool.py tc.. Updates: -------- Patch 2: -------- 1) updated the tc to verify if the support for dir and netfs support pool creation exist in the providers. 2) Updated the test to verify if Libvirt version on machine has capability to support storage pool. Tested on F10 with KVM, Xen with current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 8510887c62ad -r d0a02ab76e76 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py Thu Jun 18 05:07:22 2009 -0700 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py Thu Jun 18 05:55:07 2009 -0700 @@ -49,52 +49,102 @@ import sys from CimTest.Globals import logger -from CimTest.ReturnCodes import FAIL, PASS +from XenKvmLib.xm_virt_util import virsh_version +from CimTest.ReturnCodes import FAIL, PASS, SKIP from XenKvmLib.const import do_main, platform_sup from XenKvmLib.classes import get_typed_class -from XenKvmLib.common_util import destroy_diskpool +from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \ + netfs_cleanup from XenKvmLib.pool import create_pool, verify_pool, undefine_diskpool +from XenKvmLib.const import get_provider_version -test_pool = "diskpool" -dp_types = { "DISK_POOL_DIR" : 1 } - +libvirt_disk_pool_support=837 +libvirt_netfs_pool_support=869 + +def get_pool_attr(server, pool_type, dp_types): + pool_attr = { "Path" : "/tmp" } + if pool_type == dp_types['DISK_POOL_NETFS']: + status , 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 FAIL, pool_attr + + pool_attr['SourceDirectory'] = src_mnt_dir + pool_attr['Host'] = server + pool_attr['Path'] = dir_mnt_dir + + return PASS, pool_attr + @do_main(platform_sup) def main(): options = main.options server = options.ip virt = options.virt - pool_attr = { "Path" : "/tmp" } + dp_types = { } + + libvirt_version = virsh_version(server, virt) + if libvirt_version < "0.4.1": + logger.info("Storage pool creation support is available in Libvirt " + "version >= 0.4.1 , hence skipping the test....") + return SKIP + + curr_cim_rev, changeset = get_provider_version(virt, server) + if curr_cim_rev >= libvirt_disk_pool_support: + dp_types["DISK_POOL_DIR"] = 1 + if curr_cim_rev >= libvirt_netfs_pool_support: + dp_types["DISK_POOL_NETFS"] = 3 + + if len(dp_types) == 0 : + logger.info("No disk pool types in list , hence skipping the test...") + return SKIP + + status = FAIL # For now the test case support only the creation of - # dir type disk pool, later change to fs and netfs etc + # dir type disk pool, netfs later change to fs and disk pooltypes etc for key, value in dp_types.iteritems(): - status = create_pool(server, virt, test_pool, pool_attr, - mode_type=value, pool_type= "DiskPool") - if status != PASS: - logger.error("Failed to create '%s' type diskpool '%s'", - key, test_pool) + try: + logger.info("Verifying '%s'.....", key) + test_pool = key + status, pool_attr = get_pool_attr(server, value, dp_types) + if status != PASS: + return FAIL + + status = create_pool(server, virt, test_pool, pool_attr, + mode_type=value, pool_type= "DiskPool") + + if status != PASS: + raise Exception("Failed to create '%s' type diskpool '%s'" \ + % (key, test_pool)) + + status = verify_pool(server, virt, test_pool, pool_attr, + mode_type=value, pool_type="DiskPool") + if status != PASS: + destroy_diskpool(server, virt, test_pool) + undefine_diskpool(server, virt, test_pool) + raise Exception("Error in diskpool verification") + + status = destroy_diskpool(server, virt, test_pool) + if status != PASS: + raise Exception("Unable to destroy diskpool '%s'" \ + % test_pool) + + status = undefine_diskpool(server, virt, test_pool) + if status != PASS: + raise Exception("Unable to undefine diskpool '%s'" \ + % test_pool) + + if key == 'DISK_POOL_NETFS': + netfs_cleanup(server, pool_attr) + + status = PASS + + except Exception, details: + logger.error("Exception details: %s", details) + if key == 'DISK_POOL_NETFS': + netfs_cleanup(server, pool_attr) return FAIL - - status = verify_pool(server, virt, test_pool, pool_attr, - mode_type=value, pool_type="DiskPool") - if status != PASS: - logger.error("Error in diskpool verification") - destroy_diskpool(server, virt, test_pool) - undefine_diskpool(server, virt, test_pool) - return FAIL - - status = destroy_diskpool(server, virt, test_pool) - if status != PASS: - logger.error("Unable to destroy diskpool '%s'", test_pool) - return FAIL - - status = undefine_diskpool(server, virt, test_pool) - if status != PASS: - logger.error("Unable to undefine diskpool '%s'", test_pool) - return FAIL - - status = PASS return status
participants (1)
-
Deepti B. Kalakeri