diff options
author | Shwetha Panduranga <spandura@redhat.com> | 2016-06-25 02:06:38 +0530 |
---|---|---|
committer | M S Vishwanath Bhat <msvbhat@gmail.com> | 2016-06-26 11:31:07 -0700 |
commit | 09c0b2f3c2534f365bee5a738d1699af36413a25 (patch) | |
tree | 0642746e04b3939d0d1591f93efcddcdd4924829 /tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py | |
parent | 8b53bfab1e86b7c110e5f2bab464678c4c99758a (diff) |
Modifying gluster_base_class and mount_ops to suit the config file changes made
Change-Id: I61481c029fdbdd9c966867f195b9dc9046550392
BUG: 1350017
Signed-off-by: Shwetha Panduranga <spandura@redhat.com>
Reviewed-on: http://review.gluster.org/14793
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: M S Vishwanath Bhat <msvbhat@gmail.com>
Tested-by: M S Vishwanath Bhat <msvbhat@gmail.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py')
-rw-r--r-- | tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py | 174 |
1 files changed, 152 insertions, 22 deletions
diff --git a/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py index 2d435f40d53..2ee5b815c53 100644 --- a/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py +++ b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/mount_ops.py @@ -18,15 +18,139 @@ from distaf.util import tc +class GlusterMount(): + """Gluster Mount class -def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', \ - mserver='', mclient='', options=''): + Args: + mount (dict): Mount dict with 'mount_protocol', 'mountpoint', + 'server', 'client', 'volname', 'options' as keys + + Returns: + Instance of GlusterMount class + """ + client_register = 0 + + def __init__(self, mount): + if mount['protocol']: + self.mounttype = mount['protocol'] + else: + self.mounttype = "glusterfs" + + if mount['mountpoint']: + self.mountpoint = mount['mountpoint'] + else: + self.mountpoint = "/mnt/%s" % self.mounttype + + self.server_system = mount['server'] + self.client_system = mount['client'] + self.volname = mount['volname'] + self.options = mount['options'] + + def mount(self): + """Mounts the volume + + Args: + uses instance args passed at init + + Returns: + bool: True on success and False on failure. + """ + (_retcode, _, _) = mount_volume(self.volname, + mtype=self.mounttype, + mpoint=self.mountpoint, + mserver=self.server_system, + mclient=self.client_system, + options=self.options) + + if _retcode == 0: + return True + else: + return False + + def is_mounted(self): + """Tests for mount on client + + Args: + uses instance args passed at init + + Returns: + bool: True on success and False on failure. + """ + _retcode = is_mounted(self.volname, + mpoint=self.mountpoint, + mserver=self.server_system, + mclient=self.client_system) + + if _retcode: + return True + else: + return False + + def unmount(self): + """Unmounts the volume + + Args: + uses instance args passed at init + + Returns: + bool: True on success and False on failure. + """ + (_retcode, _, _) = umount_volume(self.client_system, + self.mountpoint) + + if _retcode == 0: + return True + else: + return False + +def is_mounted(volname, mpoint, mserver, mclient): + """Check if mount exist. + + Args: + volname (str): Name of the volume + mpoint (str): Mountpoint dir + mserver (str): Server to which it is mounted to + mclient (str): Client from which it is mounted. + + Returns: + bool: True if mounted and False otherwise. """ - Mount the gluster volume with specified options - Takes the volume name as mandatory argument + # python will error on missing arg, so just checking for empty args here + if not volname or not mpoint or not mserver or not mclient: + tc.logger.error("Missing arguments for mount.") + return False + + ret, _, _ = tc.run(mclient, "mount | grep %s | grep %s | grep \"%s\"" + % (volname, mpoint, mserver), verbose=False) + if ret == 0: + tc.logger.debug("Volume %s is mounted at %s:%s" % (volname, + mclient, + mpoint)) + return True + else: + tc.logger.error("Volume %s is not mounted at %s:%s" % (volname, + mclient, + mpoint)) + return False + +def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', + mserver='', mclient='', options=''): + """Mount the gluster volume with specified options. + + Args: + volname (str): Name of the volume to mount. - Returns a tuple of (returncode, stdout, stderr) - Returns (0, '', '') if already mounted + Kwargs: + mtype (str): Protocol to be used to mount. + mpoint (str): Mountpoint dir. + mserver (str): Server to mount. + mclient (str): Client from which it has to be mounted. + option (str): Options for the mount command. + + Returns: + tuple: Tuple containing three elements (ret, out, err). + (0, '', '') if already mounted. + (ret, out, err) of mount commnd execution otherwise. """ global tc if mserver == '': @@ -39,24 +163,30 @@ def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', \ options = "%s" % options elif mtype == 'nfs' and options == '': options = '-o vers=3' - ret, _, _ = tc.run(mclient, "mount | grep %s | grep %s | grep \"%s\"" \ - % (volname, mpoint, mserver), verbose=False) - if ret == 0: - tc.logger.debug("Volume %s is already mounted at %s" \ - % (volname, mpoint)) + + if is_mounted(volname, mpoint, mserver, mclient): + tc.logger.debug("Volume %s is already mounted at %s" % + (volname, mpoint)) return (0, '', '') - mcmd = "mount -t %s %s %s:/%s %s" % \ - (mtype, options, mserver, volname, mpoint) - tc.run(mclient, "test -d %s || mkdir -p %s" % (mpoint, mpoint), \ - verbose=False) + + mcmd = ("mount -t %s %s %s:/%s %s" % + (mtype, options, mserver, volname, mpoint)) + _, _, _ = tc.run(mclient, "test -d %s || mkdir -p %s" % (mpoint, mpoint), + verbose=False) return tc.run(mclient, mcmd) -def umount_volume(client, mountpoint): - """ - unmounts the mountpoint - Returns the output of umount command +def umount_volume(mclient, mpoint): + """Unmounts the mountpoint. + + Args: + mclient (str): Client from which it has to be mounted. + mpoint (str): Mountpoint dir. + + Returns: + tuple: Tuple containing three elements (ret, out, err) as returned by + umount command execution. """ - cmd = "umount %s || umount -f %s || umount -l %s" \ - % (mountpoint, mountpoint, mountpoint) - return tc.run(client, cmd) + cmd = ("umount %s || umount -f %s || umount -l %s" % + (mpoint, mpoint, mpoint)) + return tc.run(mclient, cmd) |