Modifying gluster_base_class and mount_ops to suit the config file changes made
Change-Id: Ic551724dd27fcc2cc618e8de04110752bf5a8786 BUG: 1350017 Signed-off-by: Shwetha Panduranga <spandura@redhat.com> Reviewed-on: http://review.gluster.org/14808 Tested-by: ShwethaHPanduranga NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jonathan Holloway <jholloway@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org>
This commit is contained in:
parent
eaadde082e
commit
d2842f1b58
@ -19,6 +19,8 @@
|
|||||||
from distaf.util import tc
|
from distaf.util import tc
|
||||||
from distaflibs.gluster.volume_ops import (setup_vol, get_volume_info,
|
from distaflibs.gluster.volume_ops import (setup_vol, get_volume_info,
|
||||||
cleanup_volume)
|
cleanup_volume)
|
||||||
|
from distaflibs.gluster.mount_ops import GlusterMount
|
||||||
|
from distaflibs.gluster.gluster_init import env_setup_servers
|
||||||
|
|
||||||
|
|
||||||
class GlusterBaseClass():
|
class GlusterBaseClass():
|
||||||
@ -33,25 +35,48 @@ class GlusterBaseClass():
|
|||||||
Initialise the class with the config values
|
Initialise the class with the config values
|
||||||
"""
|
"""
|
||||||
if config_data['global_mode']:
|
if config_data['global_mode']:
|
||||||
self.volname = config_data['volumes'].keys()[0]
|
self.volname = config_data['gluster']['volumes'][0]['name']
|
||||||
self.voltype = config_data['volumes'][self.volname]['voltype']
|
self.voltype = (config_data['gluster']['volumes'][0]['voltype']
|
||||||
self.servers = config_data['volumes'][self.volname]['servers']
|
['type'])
|
||||||
self.peers = config_data['volumes'][self.volname]['peers']
|
self.servers = []
|
||||||
self.clients = config_data['volumes'][self.volname]['clients']
|
for server in config_data['gluster']['volumes'][0]['servers']:
|
||||||
self.mount_proto = (config_data['volumes'][self.volname]
|
self.servers.append(server['host'])
|
||||||
['mount_proto'])
|
self.peers = config_data['gluster']['volumes'][0]['peers']
|
||||||
self.mountpoint = (config_data['volumes'][self.volname]
|
self.mounts = []
|
||||||
['mountpoint'])
|
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)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.voltype = config_data['voltype']
|
self.voltype = config_data['voltype']
|
||||||
self.volname = "%s-testvol" % self.voltype
|
self.volname = "%s-testvol" % self.voltype
|
||||||
self.servers = config_data['servers'].keys()
|
self.servers = []
|
||||||
self.clients = config_data['clients'].keys()
|
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.peers = []
|
self.peers = []
|
||||||
if config_data['peers'] is not None:
|
if config_data['peers'] is not None:
|
||||||
self.peers = config_data['peers'].keys()
|
for peer in config_data['peers']:
|
||||||
|
self.peers.append(peers['host'])
|
||||||
|
self.mounts = []
|
||||||
self.mount_proto = config_data['mount_proto']
|
self.mount_proto = config_data['mount_proto']
|
||||||
self.mountpoint = "/mnt/%s_mount" % self.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.mnode = self.servers[0]
|
||||||
self.config_data = config_data
|
self.config_data = config_data
|
||||||
|
|
||||||
@ -62,29 +87,39 @@ class GlusterBaseClass():
|
|||||||
dist = rep = dispd = red = stripe = 1
|
dist = rep = dispd = red = stripe = 1
|
||||||
trans = ''
|
trans = ''
|
||||||
if self.voltype == 'distribute':
|
if self.voltype == 'distribute':
|
||||||
dist = self.config_data[self.voltype]['dist_count']
|
dist = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
trans = self.config_data[self.voltype]['transport']
|
['dist_count'])
|
||||||
|
trans = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['transport'])
|
||||||
elif self.voltype == 'replicate':
|
elif self.voltype == 'replicate':
|
||||||
rep = self.config_data[self.voltype]['replica']
|
rep = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
trans = self.config_data[self.voltype]['transport']
|
['replica_count'])
|
||||||
|
trans = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['transport'])
|
||||||
elif self.voltype == 'dist_rep':
|
elif self.voltype == 'dist_rep':
|
||||||
dist = self.config_data[self.voltype]['dist_count']
|
dist = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
rep = self.config_data[self.voltype]['replica']
|
['dist_count'])
|
||||||
trans = self.config_data[self.voltype]['transport']
|
rep = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['replica_count'])
|
||||||
|
trans = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['transport'])
|
||||||
elif self.voltype == 'disperse':
|
elif self.voltype == 'disperse':
|
||||||
dispd = self.config_data[self.voltype]['disperse']
|
dispd = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
red = self.config_data[self.voltype]['redundancy']
|
['disperse_count'])
|
||||||
trans = self.config_data[self.voltype]['transport']
|
red = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['redundancy_count'])
|
||||||
|
trans = (self.config_data['gluster']['volume_types'][self.voltype]
|
||||||
|
['transport'])
|
||||||
elif self.voltype == 'dist_disperse':
|
elif self.voltype == 'dist_disperse':
|
||||||
dist = self.config_data[self.voltype]['dist_count']
|
dist = self.config_data[self.voltype]['dist_count']
|
||||||
dispd = self.config_data[self.voltype]['disperse']
|
dispd = self.config_data[self.voltype]['disperse_count']
|
||||||
red = self.config_data[self.voltype]['redundancy']
|
red = self.config_data[self.voltype]['redundancy_count']
|
||||||
trans = self.config_data[self.voltype]['transport']
|
trans = self.config_data[self.voltype]['transport']
|
||||||
else:
|
else:
|
||||||
tc.logger.error("The volume type is not present")
|
tc.logger.error("The volume type is not present")
|
||||||
return False
|
return False
|
||||||
ret = setup_vol(self.volname, dist, rep, dispd, red, stripe, trans,
|
ret = setup_vol(self.volname, self.mnode, dist, rep, dispd, red,
|
||||||
servers=self.servers)
|
stripe, trans, servers=self.servers)
|
||||||
if not ret:
|
if not ret:
|
||||||
tc.logger.error("Unable to setup volume %s", self.volname)
|
tc.logger.error("Unable to setup volume %s", self.volname)
|
||||||
return False
|
return False
|
||||||
@ -94,7 +129,11 @@ class GlusterBaseClass():
|
|||||||
"""
|
"""
|
||||||
Function to setup the volume for testing.
|
Function to setup the volume for testing.
|
||||||
"""
|
"""
|
||||||
volinfo = get_volume_info(server=self.servers[0])
|
if not env_setup_servers():
|
||||||
|
tc.logger.error("Unable to setup testenv")
|
||||||
|
return False
|
||||||
|
|
||||||
|
volinfo = get_volume_info(mnode=self.servers[0])
|
||||||
if volinfo is not None and self.volname in volinfo.keys():
|
if volinfo is not None and self.volname in volinfo.keys():
|
||||||
tc.logger.debug("The volume %s is already present in %s",
|
tc.logger.debug("The volume %s is already present in %s",
|
||||||
self.volname, self.mnode)
|
self.volname, self.mnode)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
from distaf.util import tc
|
from distaf.util import tc
|
||||||
|
import re
|
||||||
"""
|
"""
|
||||||
This file contains the glusterd and other initial gluster
|
This file contains the glusterd and other initial gluster
|
||||||
options like start/stop glusterd and env_setup_servers for
|
options like start/stop glusterd and env_setup_servers for
|
||||||
@ -67,4 +67,11 @@ def env_setup_servers(snap=True, servers=''):
|
|||||||
"""
|
"""
|
||||||
tc.logger.info("The function isn't implemented yet")
|
tc.logger.info("The function isn't implemented yet")
|
||||||
tc.logger.info("Please setup the bricks manually.")
|
tc.logger.info("Please setup the bricks manually.")
|
||||||
|
|
||||||
|
if servers == '':
|
||||||
|
servers = tc.servers
|
||||||
|
|
||||||
|
if not start_glusterd(servers):
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -18,15 +18,140 @@
|
|||||||
|
|
||||||
from distaf.util import tc
|
from distaf.util import tc
|
||||||
|
|
||||||
|
class GlusterMount():
|
||||||
|
"""Gluster Mount class
|
||||||
|
|
||||||
def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', \
|
Args:
|
||||||
mserver='', mclient='', options=''):
|
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
|
# python will error on missing arg, so just checking for empty args here
|
||||||
Takes the volume name as mandatory argument
|
if not volname or not mpoint or not mserver or not mclient:
|
||||||
|
tc.logger.error("Missing arguments for mount.")
|
||||||
|
return False
|
||||||
|
|
||||||
Returns a tuple of (returncode, stdout, stderr)
|
ret, _, _ = tc.run(mclient, "mount | grep %s | grep %s | grep \"%s\""
|
||||||
Returns (0, '', '') if already mounted
|
% (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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
(1, '', '') if setup_samba_service fails in case of smb.
|
||||||
|
(ret, out, err) of mount commnd execution otherwise.
|
||||||
"""
|
"""
|
||||||
global tc
|
global tc
|
||||||
if mserver == '':
|
if mserver == '':
|
||||||
@ -39,24 +164,47 @@ def mount_volume(volname, mtype='glusterfs', mpoint='/mnt/glusterfs', \
|
|||||||
options = "%s" % options
|
options = "%s" % options
|
||||||
elif mtype == 'nfs' and options == '':
|
elif mtype == 'nfs' and options == '':
|
||||||
options = '-o vers=3'
|
options = '-o vers=3'
|
||||||
ret, _, _ = tc.run(mclient, "mount | grep %s | grep %s | grep \"%s\"" \
|
|
||||||
% (volname, mpoint, mserver), verbose=False)
|
if is_mounted(volname, mpoint, mserver, mclient):
|
||||||
if ret == 0:
|
tc.logger.debug("Volume %s is already mounted at %s" %
|
||||||
tc.logger.debug("Volume %s is already mounted at %s" \
|
(volname, mpoint))
|
||||||
% (volname, mpoint))
|
|
||||||
return (0, '', '')
|
return (0, '', '')
|
||||||
mcmd = "mount -t %s %s %s:/%s %s" % \
|
|
||||||
(mtype, options, mserver, volname, mpoint)
|
mcmd = ("mount -t %s %s %s:/%s %s" %
|
||||||
tc.run(mclient, "test -d %s || mkdir -p %s" % (mpoint, mpoint), \
|
(mtype, options, mserver, volname, mpoint))
|
||||||
verbose=False)
|
|
||||||
|
if mtype == 'cifs':
|
||||||
|
from distaflibs.gluster.samba_ops import setup_samba_service
|
||||||
|
smbuser = tc.global_config['gluster']['cluster_config']['smb']['user']
|
||||||
|
smbpasswd = (tc.global_config['gluster']['cluster_config']['smb']
|
||||||
|
['passwd'])
|
||||||
|
|
||||||
|
if not setup_samba_service(volname, mserver, smbuser, smbpasswd):
|
||||||
|
tc.logger.error("Failed to setup samba service %s" % mserver)
|
||||||
|
return (1, '', '')
|
||||||
|
|
||||||
|
mcmd = ("mount -t cifs -o username=root,password=%s "
|
||||||
|
"\\\\\\\\%s\\\\gluster-%s %s" % (smbpasswd, mserver,
|
||||||
|
volname, mpoint))
|
||||||
|
# Create mount dir
|
||||||
|
_, _, _ = tc.run(mclient, "test -d %s || mkdir -p %s" % (mpoint, mpoint),
|
||||||
|
verbose=False)
|
||||||
|
|
||||||
|
# Create mount
|
||||||
return tc.run(mclient, mcmd)
|
return tc.run(mclient, mcmd)
|
||||||
|
|
||||||
|
|
||||||
def umount_volume(client, mountpoint):
|
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.
|
||||||
"""
|
"""
|
||||||
unmounts the mountpoint
|
cmd = ("umount %s || umount -f %s || umount -l %s" %
|
||||||
Returns the output of umount command
|
(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)
|
|
||||||
|
@ -68,10 +68,10 @@ gluster:
|
|||||||
ctdb_vips:
|
ctdb_vips:
|
||||||
- vip: vip1
|
- vip: vip1
|
||||||
routing_prefix: '23'
|
routing_prefix: '23'
|
||||||
interfaces: 'eth0'
|
interface: 'eth0'
|
||||||
- vip: vip2
|
- vip: vip2
|
||||||
routing_prefix: '22'
|
routing_prefix: '22'
|
||||||
interfaces: 'eth0'
|
interface: 'eth0'
|
||||||
ctdb_metavol_brick_path: ''
|
ctdb_metavol_brick_path: ''
|
||||||
|
|
||||||
nfs_ganesha:
|
nfs_ganesha:
|
||||||
@ -81,24 +81,25 @@ gluster:
|
|||||||
|
|
||||||
volume_types:
|
volume_types:
|
||||||
distribute: &distribute
|
distribute: &distribute
|
||||||
|
type: distribute
|
||||||
dist_count: 4
|
dist_count: 4
|
||||||
transport: tcp
|
transport: tcp
|
||||||
|
|
||||||
replicate: &replicate
|
replicate: &replicate
|
||||||
|
type: replicate
|
||||||
replica_count: 3
|
replica_count: 3
|
||||||
transport: tcp
|
transport: tcp
|
||||||
|
|
||||||
dist_rep: &dist_rep
|
dist_rep: &dist_rep
|
||||||
|
type: dist_rep
|
||||||
dist_count: 2
|
dist_count: 2
|
||||||
replica_count: 2
|
replica_count: 2
|
||||||
transport: tcp
|
transport: tcp
|
||||||
|
|
||||||
disperse: &disperse
|
disperse: &disperse
|
||||||
|
type: disperse
|
||||||
disperse_count: 4
|
disperse_count: 4
|
||||||
redundancy_count: 2
|
redundancy_count: 2
|
||||||
transport: tcp
|
transport: tcp
|
||||||
|
|
||||||
dist_disperse: &dist_disperse
|
dist_disperse: &dist_disperse
|
||||||
|
type: dist_disperse
|
||||||
dist_count: 2
|
dist_count: 2
|
||||||
disperse_count: 4
|
disperse_count: 4
|
||||||
redundancy_count: 2
|
redundancy_count: 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user