diff options
3 files changed, 51 insertions, 216 deletions
diff --git a/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/gluster_base_class.py b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/gluster_base_class.py index dbbe02de7de..128288bb10f 100644 --- a/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/gluster_base_class.py +++ b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/gluster_base_class.py @@ -19,7 +19,6 @@ from distaf.util import tc from distaflibs.gluster.volume_ops import (setup_vol, get_volume_info, cleanup_volume) -from distaflibs.gluster.mount_ops import GlusterMount class GlusterBaseClass(): @@ -33,49 +32,26 @@ class GlusterBaseClass(): """ Initialise the class with the config values """ - if config_data['gluster']['global_mode']: - self.volname = config_data['gluster']['volumes'][0]['name'] - self.voltype = (config_data['gluster']['volumes'][0]['voltype'] - ['type']) - self.servers = [] - for server in config_data['gluster']['volumes'][0]['servers']: - self.servers.append(server['host']) - self.peers = config_data['gluster']['volumes'][0]['peers'] - self.mounts = [] - for mount in config_data['gluster']['mounts']: - mount['client'] = mount['client']['host'] - mount['server'] = mount['server']['host'] - self.mounts.append(GlusterMount(mount)) - self.clients = [] - for mount_obj in self.mounts: - self.clients.append(mount_obj.client_system) - self.clients = filter(None, self.clients) - + if config_data['global_mode']: + self.volname = config_data['volumes'].keys()[0] + self.voltype = config_data['volumes'][self.volname]['voltype'] + self.servers = config_data['volumes'][self.volname]['servers'] + self.peers = config_data['volumes'][self.volname]['peers'] + self.clients = config_data['volumes'][self.volname]['clients'] + self.mount_proto = (config_data['volumes'][self.volname] + ['mount_proto']) + self.mountpoint = (config_data['volumes'][self.volname] + ['mountpoint']) else: self.voltype = config_data['voltype'] self.volname = "%s-testvol" % self.voltype - self.servers = [] - for server in config_data['servers']: - self.servers.append(server['host']) - self.clients = [] - for client in config_data['clients']: - self.clients.append(client['host']) + self.servers = config_data['servers'].keys() + self.clients = config_data['clients'].keys() self.peers = [] if config_data['peers'] is not None: - for peer in config_data['peers']: - self.peers.append(peers['host']) - self.mounts = [] + self.peers = config_data['peers'].keys() self.mount_proto = config_data['mount_proto'] self.mountpoint = "/mnt/%s_mount" % self.mount_proto - for client in self.clients: - mount = {} - mount['protocol'] = config_data['mount_proto'] - mount['mountpoint'] = "/mnt/%s_mount" % self.mount_proto - mount['server'] = self.servers[0] - mount['client'] = client - mount['volname'] = self.volname - mount['options'] = "" - self.mounts.append(GlusterMount(mount)) self.mnode = self.servers[0] self.config_data = config_data @@ -86,33 +62,23 @@ class GlusterBaseClass(): dist = rep = dispd = red = stripe = 1 trans = '' if self.voltype == 'distribute': - dist = (self.config_data['gluster']['volume_types'][self.voltype] - ['dist_count']) - trans = (self.config_data['gluster']['volume_types'][self.voltype] - ['transport']) + dist = self.config_data[self.voltype]['dist_count'] + trans = self.config_data[self.voltype]['transport'] elif self.voltype == 'replicate': - rep = (self.config_data['gluster']['volume_types'][self.voltype] - ['replica_count']) - trans = (self.config_data['gluster']['volume_types'][self.voltype] - ['transport']) + rep = self.config_data[self.voltype]['replica'] + trans = self.config_data[self.voltype]['transport'] elif self.voltype == 'dist_rep': - dist = (self.config_data['gluster']['volume_types'][self.voltype] - ['dist_count']) - rep = (self.config_data['gluster']['volume_types'][self.voltype] - ['replica_count']) - trans = (self.config_data['gluster']['volume_types'][self.voltype] - ['transport']) + dist = self.config_data[self.voltype]['dist_count'] + rep = self.config_data[self.voltype]['replica'] + trans = self.config_data[self.voltype]['transport'] elif self.voltype == 'disperse': - dispd = (self.config_data['gluster']['volume_types'][self.voltype] - ['disperse_count']) - red = (self.config_data['gluster']['volume_types'][self.voltype] - ['redundancy_count']) - trans = (self.config_data['gluster']['volume_types'][self.voltype] - ['transport']) + dispd = self.config_data[self.voltype]['disperse'] + red = self.config_data[self.voltype]['redundancy'] + trans = self.config_data[self.voltype]['transport'] elif self.voltype == 'dist_disperse': dist = self.config_data[self.voltype]['dist_count'] - dispd = self.config_data[self.voltype]['disperse_count'] - red = self.config_data[self.voltype]['redundancy_count'] + dispd = self.config_data[self.voltype]['disperse'] + red = self.config_data[self.voltype]['redundancy'] trans = self.config_data[self.voltype]['transport'] else: tc.logger.error("The volume type is not present") 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 2ee5b815c53..2d435f40d53 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,139 +18,15 @@ from distaf.util import tc -class GlusterMount(): - """Gluster Mount class - 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. +def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', \ + mserver='', mclient='', options=''): """ - # 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. + Mount the gluster volume with specified options + Takes the volume name as mandatory argument - 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. + Returns a tuple of (returncode, stdout, stderr) + Returns (0, '', '') if already mounted """ global tc if mserver == '': @@ -163,30 +39,24 @@ def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', options = "%s" % options elif mtype == 'nfs' and options == '': options = '-o vers=3' - - if is_mounted(volname, mpoint, mserver, mclient): - tc.logger.debug("Volume %s is already mounted at %s" % - (volname, mpoint)) + 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)) 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(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. +def umount_volume(client, mountpoint): + """ + unmounts the mountpoint + Returns the output of umount command """ - cmd = ("umount %s || umount -f %s || umount -l %s" % - (mpoint, mpoint, mpoint)) - return tc.run(mclient, cmd) + cmd = "umount %s || umount -f %s || umount -l %s" \ + % (mountpoint, mountpoint, mountpoint) + return tc.run(client, cmd) diff --git a/tests/distaf/tests_d/distaf_gluster_config.yml b/tests/distaf/tests_d/distaf_gluster_config.yml index 45b52c2490d..28ae6e2894e 100644 --- a/tests/distaf/tests_d/distaf_gluster_config.yml +++ b/tests/distaf/tests_d/distaf_gluster_config.yml @@ -81,25 +81,24 @@ gluster: volume_types: distribute: &distribute - type: distribute dist_count: 4 transport: tcp + replicate: &replicate - type: replicate replica_count: 3 transport: tcp + dist_rep: &dist_rep - type: dist_rep dist_count: 2 replica_count: 2 transport: tcp + disperse: &disperse - type: disperse disperse_count: 4 redundancy_count: 2 transport: tcp + dist_disperse: &dist_disperse - type: dist_disperse dist_count: 2 disperse_count: 4 redundancy_count: 2 |