# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)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(a)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