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

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

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1245155432 25200 # Node ID f5e5d4436bff6320c18bb59b0d307969cd5c4545 # Parent 9a2db4596db33348b860a0e2337e377f237b0692 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 f5e5d4436bff 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 Tue Jun 16 05:30:32 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.ibm.com> # Date 1245155523 25200 # Node ID 4eb38964b6e6bdd757904d51b83ff115b02dd29a # Parent f5e5d4436bff6320c18bb59b0d307969cd5c4545 Adding nfs_netfs_setup() to configure nfs server setup... 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 f5e5d4436bff -r 4eb38964b6e6 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Jun 16 05:30:32 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Jun 16 05:32:03 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 @@ -435,3 +436,113 @@ 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 : + 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) + 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 + 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 dir created .. + clean_temp_files(server, src_dir, dst_dir) + + # Remove the entry from the /etc/exports + ifile = "/etc/exports" + cmd = "sed -i '/%s/d' %s" % (src_dir, ifile) + rc, out = utils.run_remote(server, cmd) + if rc != PASS: + logger.error("Unable to delete the line containing '%s' from '%s'", + src_dir, ifile) + else: + # 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() + fd = open("/etc/exports", "a") + fd.seek(0) + line = "\n %s %s(rw)" %(src_dir_for_mnt, server) + fd.write(line) + fd.close() + + try: + # 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) + + # NFS mount src_dir_for_mnt + cmd = "mount -t nfs %s:%s %s" %(server, src_dir_for_mnt, dest_dir_to_mnt) + rc, out = utils.run_remote(server, cmd) + if rc != 0: + raise Exception("Failed to NFS mount %s on %s:%s " \ + % (dest_dir_to_mnt, server, src_dir_for_mnt)) + + 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

+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 : + 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) + 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
I would check to see if the nfs binary exists before attempting to run it.
+def netfs_config(server, nfs_server_bin): + src_dir_for_mnt = mkdtemp() + dest_dir_to_mnt = mkdtemp() + fd = open("/etc/exports", "a")
I would create a backup of /etc/exports just incase. Something like /etc/exports.cimtest.bk - that way the user can restore it if we accidentally mess the file up. Also, what is /etc/exports doesn't exist on the system?
+ fd.seek(0) + line = "\n %s %s(rw)" %(src_dir_for_mnt, server) + fd.write(line) + fd.close() + + try: + # 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) + + # NFS mount src_dir_for_mnt + cmd = "mount -t nfs %s:%s %s" %(server, src_dir_for_mnt, dest_dir_to_mnt)
No need to do this.. libvirt should handle mounting for you. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1245155631 25200 # Node ID 775f81388994fa3ddb72b2740389b1eeec8c0b13 # Parent 4eb38964b6e6bdd757904d51b83ff115b02dd29a Adding netfs diskpool creation to RPCS/08_CreateDiskResourcePool.py tc.. Tested on F10 with KVM and current sources. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 4eb38964b6e6 -r 775f81388994 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py Tue Jun 16 05:32:03 2009 -0700 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py Tue Jun 16 05:33:51 2009 -0700 @@ -52,49 +52,78 @@ from CimTest.ReturnCodes import FAIL, PASS 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 -test_pool = "diskpool" -dp_types = { "DISK_POOL_DIR" : 1 } - +dp_types = { "DISK_POOL_DIR" : 1, "DISK_POOL_NETFS" : 3} + +def get_pool_attr(server, pool_type): + 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 '%s' diskpool type", + pool_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" } # 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) + if status != PASS: + return FAIL + + status = create_pool(server, virt, test_pool, pool_attr, + mode_type=value, pool_type= "DiskPool") + + if status != PASS: + raise Excpetion("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

Deepti B. Kalakeri wrote:
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1245155631 25200 # Node ID 775f81388994fa3ddb72b2740389b1eeec8c0b13 # Parent 4eb38964b6e6bdd757904d51b83ff115b02dd29a Adding netfs diskpool creation to RPCS/08_CreateDiskResourcePool.py tc..
Tested on F10 with KVM and current sources.
You'll want to make sure you branch the test. Otherwise, it fails with the following on older versions of libvirt: ERROR - Exception in create_pool() ERROR - Exception details: (1, u'CIM_ERR_FAILED: Settings Error: Storage pool creation not supported in this version of libvirt') ERROR - Exception details: global name 'Excpetion' is not defined ERROR - Please delete tmp6NHsxD /tmp/tmphzHNuK if present on localhost InvokeMethod(CreateChildResourcePool): CIM_ERR_FAILED: Settings Error: Storage pool creation not supported in this version of libvirt
diff -r 4eb38964b6e6 -r 775f81388994 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py
@do_main(platform_sup) def main(): options = main.options server = options.ip virt = options.virt - pool_attr = { "Path" : "/tmp" }
# 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():
You'll want to make sure the version of libvirt your testing with supports the given pool type. This test should be skipped entirely if the version of libvirt doesn't support storage pool creation at all. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B. Kalakeri
-
Kaitlin Rupert