summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rwxr-xr-xlibs/connect/ssh.py27
-rw-r--r--libs/globals/testenv.py79
-rw-r--r--libs/parser/parser.py73
-rw-r--r--libs/utils/glusterinstall.py498
-rw-r--r--libs/utils/glusterutils.py149
-rw-r--r--libs/utils/hostutils.py333
-rw-r--r--libs/utils/managerutils.py10
7 files changed, 765 insertions, 404 deletions
diff --git a/libs/connect/ssh.py b/libs/connect/ssh.py
index e4540d5..c2d5613 100755
--- a/libs/connect/ssh.py
+++ b/libs/connect/ssh.py
@@ -78,32 +78,13 @@ class SshConnection():
transport = self._connection.get_transport()
channel = transport.open_session()
channel.exec_command(command)
- # Adding sleep to get the correct exit_status.
- timeout = 60
- sleeptime = 5
- while timeout:
- time.sleep(sleeptime)
- exit_status_ready_flag = channel.exit_status_ready()
- if not exit_status_ready_flag:
- timeout -=1
- continue
- else:
- break
-
- if not exit_status_ready_flag:
- stdin = channel.makefile("wb")
-
- if commandInput:
- stdin.write(commandInput)
- else:
- logger.error("This command requirs Command Input \
- after executing comamnd for command completion")
- stdin.write("\n")
- return output
+ stdin = channel.makefile("wb")
+ if commandInput:
+ stdin.write(commandInput)
+ exit_status = channel.recv_exit_status()
stdout = channel.makefile("rb")
stderr = channel.makefile_stderr("rb")
- exit_status = channel.recv_exit_status()
output["exitstatus"] = exit_status
output["stdoutdata"] = stdout.readlines()
diff --git a/libs/globals/testenv.py b/libs/globals/testenv.py
index e5d1b6b..68e27c3 100644
--- a/libs/globals/testenv.py
+++ b/libs/globals/testenv.py
@@ -19,6 +19,7 @@ class TestEnv():
self._clients = {}
self._mountdevices = {}
self._mounts = {}
+ self._slaves = {}
self._gluster_download_paths = []
self._active_volume = None
@@ -47,6 +48,9 @@ class TestEnv():
['client', 'dir', 'device',
'type', 'logfile', 'options'])
+ self._slave_tuple = namedtuple('slave',
+ ['hostname','path','volumename'])
+
def addExportdir(self, key, dir_, **arguments):
"""
"""
@@ -162,6 +166,7 @@ class TestEnv():
else:
return return_brick_obj
+
hostname_value = brick_obj.hostname
serverkey = re.split("\.", hostname_value, maxsplit=1)[0]
server_obj = self.getServer(serverkey)
@@ -484,3 +489,77 @@ class TestEnv():
else:
host_obj = self.getClient(hostkey)
return host_obj
+
+ def addSlave(self, key, hostname, path, **arguments):
+ """
+ To add slaves for geo-replication defined
+ config file
+ """
+ volumename = None
+ if(arguments.has_key('volumename') and arguments['volumename']):
+ volumename = arguments['volumename']
+
+ slave_obj = self._slave_tuple(hostname, path, volumename)
+ self._slaves[key] = slave_obj
+
+ def getSlave(self, slavekey):
+ """
+ to getback the slave object for the
+ required slave
+ """
+ return_slave_obj = None
+ newhostname = newpath = ''
+
+ if self._slaves.has_key(slavekey):
+ slave_obj = self._slaves[slavekey]
+ else:
+ return return_slave_obj
+
+ hostname_value = slave_obj.hostname
+ serverkey = re.split("\.", hostname_value, maxsplit=1)[0]
+ server_obj = self.getServer(serverkey)
+ if server_obj:
+ newhostname = server_obj.hostname
+ else:
+ return return_brick_obj
+
+ path_value = slave_obj.path
+ if re.match("^\/", path_value):
+ newpath = path_value
+ else:
+ exportdir_obj = self.getExportdir(path_value)
+ if exportdir_obj:
+ newpath = exportdir_obj.dir
+ else:
+ slave_obj = None
+ return return_slave_obj
+
+ return_slave_obj = slave_obj._replace(hostname=newhostname,
+ path=newpath)
+
+ return return_slave_obj
+
+ def getSlaves(self):
+ """
+ To get the slave objects of all the slaves defined in
+ configuration file
+ """
+ return_slaves = {}
+
+ for slavekey in self._slaves.keys():
+ return_slaves[slavekey] = self.getslave(slavekey)
+
+ return return_slaves
+
+ def getRawSlave(self, slavekey):
+ slave_obj = None
+ if self._slaves.has_key(slavekey):
+ slave_obj = self._slaves[slavekey]
+ return slave_obj
+
+ def getSlaveKeys(self):
+ """
+ """
+ slave_keys = []
+ slave_keys.extend(self._slaves.keys())
+ return slave_keys
diff --git a/libs/parser/parser.py b/libs/parser/parser.py
index 6695b19..8d9f32c 100644
--- a/libs/parser/parser.py
+++ b/libs/parser/parser.py
@@ -1,7 +1,7 @@
""" Parser module contains parsers for parsing:
*) TestrunInfo file
*) TestEnvironment file
-*) Testcaselist file.
+*) Testcaselist file.
"""
import ConfigParser
@@ -9,6 +9,7 @@ import re
from collections import OrderedDict
import os
from atfglobals import GlobalObj
+import pdb
def verify_necessary_options(cp, section, necessary_options):
"""Helper function for all parsers to verify necessary options
@@ -32,7 +33,7 @@ def verify_necessary_options(cp, section, necessary_options):
(option, section))
all_options_found = False
return all_options_found
-
+
def parse_testrun_info_file(filename):
"""
@@ -60,20 +61,20 @@ def parse_testrun_info_file(filename):
unmatched_sections.append(section)
else:
matched_sections.append(matched_obj.group(0))
-
+
if not found_all_sections:
for section in unmatched_sections:
logger.error("Section %s Not Found" % section)
logger.error("Please define the above sections in TestRunInfo File")
return 1
-
+
else:
for section in matched_sections:
Map = {}
if re.match("keywords", section, re.IGNORECASE):
Map = dict(cp.items(section))
testruninfo_obj.addKeywords(Map['keywords'])
-
+
elif re.match("testunits", section, re.IGNORECASE):
Map = dict(cp.items(section))
testunits = Map.values()
@@ -100,7 +101,7 @@ def parse_testcaseslist_file(filename):
return_status = 1
testcaseslist = []
logger = GlobalObj.getLoggerObj()
-
+
if not os.path.exists(filename):
logger.error("%s file not found." % filename)
return return_status
@@ -132,7 +133,7 @@ def parse_testcaseslist_file(filename):
if re.match("^(<|>|=|<=|>=)", testcase['version']):
condition, version = (x.strip() for x in
testcase['version'].split())
-
+
if ((condition == "<=" and glusterversion <= version) or
(condition == ">=" and glusterversion >= version) or
(condition == "<" and glusterversion < version) or
@@ -148,8 +149,8 @@ def parse_testcaseslist_file(filename):
selected_testcases.append(testcase['testcaseid'])
return selected_testcases
-
-
+
+
def parse_testenv_configfile(filename):
"""
parse testenv.cfg file
@@ -165,10 +166,11 @@ def parse_testenv_configfile(filename):
"client" : "addClient",
"mountdevice" : "addMountDevice",
"mount" : "addMount",
+ "slave" : "addSlave",
"defaults" : "addDefaults"}
- section_pattern = re.compile('(export|server|brick|volume|client|mountdevice|mount)*')
+ section_pattern = re.compile('(export|server|brick|volume|client|mountdevice|mount|slave)*')
logger = GlobalObj.getLoggerObj()
-
+
if not cp.read(filename):
logger.error("Error reading file ' %s '.File Not found " % filename)
return 1
@@ -187,12 +189,12 @@ def parse_testenv_configfile(filename):
funcname = sections_to_functions_mapping[result]
function = getattr(env, funcname)
necessary_options = []
-
+
if re.match('export', result):
necessary_options = ["dir"]
if verify_necessary_options(cp, section, necessary_options):
dir_ = items.pop('dir')
- function(section, dir_, **items)
+ function(section, dir_, **items)
else:
return 1
@@ -220,7 +222,7 @@ def parse_testenv_configfile(filename):
function(section, hostname, user, password,
glusterversion, **items)
else:
- return 1
+ return 1
elif re.match('brick', result):
necessary_options = ["hostname", "path"]
@@ -240,18 +242,18 @@ def parse_testenv_configfile(filename):
replica = items.pop('replica')
else:
replica = None
-
+
if (items.has_key('stripe') and items['stripe']):
stripe = items.pop('stripe')
else:
stripe = None
-
+
if (items.has_key('transporttype') and
items['transporttype']):
transporttype = items.pop('transporttype')
else:
transporttype = None
-
+
function(section, volumename, replica,
stripe, transporttype, bricks)
else:
@@ -271,35 +273,20 @@ def parse_testenv_configfile(filename):
dir_ = items.pop('dir')
device = items.pop('device')
function(section, client, dir_, device, **items)
+ else:
+ return 1
+ elif re.match('slave', result):
+ necessary_options = ["hostname","path"]
+ if verify_necessary_options(cp, section, necessary_options):
+ path = items.pop('path')
+ hostname = items.pop('hostname')
+ function(section, hostname, path, **items)
else:
return 1
- return 0
-
-
+ return 0
+
+
__all__ = ['parse_testrun_info_file',
'parse_testcaseslist_file',
'parse_testenv_configfile']
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/utils/glusterinstall.py b/libs/utils/glusterinstall.py
new file mode 100644
index 0000000..aef42e9
--- /dev/null
+++ b/libs/utils/glusterinstall.py
@@ -0,0 +1,498 @@
+"""
+Install module contains functions required to install
+glusterfs using tar , git or rpm and
+supporting functions
+"""
+import re
+from atfglobals import GlobalObj
+import atfutils
+import os
+import hostutils
+import pdb
+
+system_dirs = re.compile('(/bin|/boot|/dev|/etc|/lib|/mnt|/net|/root|/sbin|\
+/usr|/var|/sys)\/?$')
+
+
+def stop_gluster_processes(hostkey):
+ """
+ stopping all the gluster processes
+ """
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+ kill_command = "killall glusterd ; killall glusterfsd ; killall glusterfs"
+ output = hostutils.execute_command(hostkey, kill_command)
+ return output
+
+def gluster_cleanup(hostkey):
+ """
+ Cleaning /etc/glusterd, usr/local/sbin and /usr/sbin
+ """
+ logger = GlobalObj.getLoggerObj()
+ remove_command = "rm -rf /etc/glusterd/ && rm -rf /usr/local/sbin/gluster* \
+ && rm -rf /usr/sbin/gluster* "
+ output = hostutils.execute_command(hostkey, remove_command)
+ return output
+
+def source_cleanup(hostkey,version,down_path):
+ """
+ Cleaning up the directories of the source if
+ already present
+ """
+ chdir = 'cd ' + down_path + ' && '
+ logger = GlobalObj.getLoggerObj()
+ remove_rep ='rm -rf glusterfs.git && rm -rf glusterfs-' + version + ' && \
+ rm -rf glusterfs-' + version + '.tar.gz && rm -rf glusterfs.rpm.' + version
+ remove_command = chdir + remove_rep
+ output = hostutils.execute_command(hostkey,remove_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to remove source")
+ return output
+ return output
+
+
+def rpm_check(hostkey):
+ """
+ checking for rpm installation of gluster and removing it
+ """
+ logger = GlobalObj.getLoggerObj()
+ cleanup_command = "rpm -qa | grep gluster | xargs rpm -e"
+ output = hostutils.execute_command(hostkey, cleanup_command)
+ return output
+
+def configure(hostkey, chdir, version):
+ """
+ configuring the souce with options simlar to that we use for rpm build
+ """
+ logger = GlobalObj.getLoggerObj()
+
+ configure = "./autogen.sh && ./configure \
+ --build=x86_64-unknown-linux-gnu \
+ --host=x86_64-unknown-linux-gnu \
+ --target=x86_64-redhat-linux-gnu \
+ --program-prefix= \
+ --prefix=/opt/glusterfs/"+ version +"\
+ --exec-prefix=/opt/glusterfs/" + version + "\
+ --bindir=/opt/glusterfs/" + version + "/bin \
+ --sbindir=/opt/glusterfs/" + version + "/sbin \
+ --sysconfdir=/etc \
+ --datadir=/opt/glusterfs/" + version + "/share \
+ --includedir=/opt/glusterfs/" + version + "/include \
+ --libdir=/opt/glusterfs/" + version + "/lib64 \
+ --libexecdir=/usr/local/libexec/ \
+ --localstatedir=/var \
+ --sharedstatedir=/var/lib \
+ --mandir=/usr/share/man \
+ --infodir=/usr/share/info"
+ configure_command = chdir + configure
+ logger.debug('%s: Executing command : %s' %(hostkey, configure_command))
+ output = hostutils.execute_command(hostkey, configure_command)
+ return output
+
+def make(hostkey, chdir):
+ """
+ """
+ logger = GlobalObj.getLoggerObj()
+ make = "make && make install"
+ make_command = chdir + make
+ output = hostutils.execute_command(hostkey, make_command)
+ return output
+
+def symlink(hostkey, install_path):
+ """
+ creating symlinks /usr/sbin/gluster* to /opt/glusterfs/version/sbin/gluster*
+ """
+ logger = GlobalObj.getLoggerObj()
+ symlink_command = "ln -s " + install_path + "sbin/gluster /usr/sbin/gluster\
+ && ln -s " + install_path + "sbin/glusterd /usr/sbin/glusterd && \
+ ln -s " + install_path + "sbin/glusterfsd /usr/sbin/glusterfsd && \
+ ln -s " + install_path + "sbin/glusterfs /usr/sbin/glusterfs"
+ output = hostutils.execute_command(hostkey, symlink_command)
+ return output
+
+def download_scp(version,down_path):
+ """
+ Downloads the tar ball with given version on one machine in the given
+ download path.
+ Then it does scp to all the other machines involved
+ """
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+ download_url = "http://bits.gluster.com/pub/gluster/glusterfs/src/glusterfs-\
+" + version + ".tar.gz"
+ hostkeys = env.getHostsKeys()
+ main_host = hostkeys[0]
+ output = hostutils.mkdir(main_host, down_path)
+ output = source_cleanup(main_host, version, down_path)
+ #changing directory to download path
+ chdir = 'cd ' + down_path + ' && '
+ wget_command = 'wget ' + download_url
+ download_command = chdir + wget_command
+ output = hostutils.execute_command(main_host,download_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to download the tarball")
+ return output
+
+ for hostkey in hostkeys:
+ if not hostkey is main_host:
+ output = hostutils.mkdir(hostkey, down_path)
+ output = source_cleanup(hostkey, version, down_path)
+ chdir = 'cd ' + down_path + ' && '
+ host_obj = env.getHost(hostkey)
+ host_value = 'root@' + host_obj.hostname + ':' + down_path
+ scp = 'scp -o StrictHostKeyChecking=no glusterfs-' + version + '\
+.tar.gz ' + host_value
+ scp_command = chdir + scp
+ output = hostutils.execute_command(main_host, scp_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to scp the tarball")
+ return output
+ return output
+
+def clone_scp(branch, down_path):
+ """
+ It clones the glusterfs git repository on one machine in the download
+ given . Then it checksout to the given branch.
+ It genenrates the tarball from the git and
+ """
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+
+ git_url = "https://github.com/gluster/glusterfs.git"
+ hostkeys = env.getHostsKeys()
+ main_host = hostkeys[0]
+ output = hostutils.mkdir(main_host, down_path)
+ output = source_cleanup(main_host, branch, down_path)
+ #changing directory to download path
+ chdir = 'cd '+down_path+' && '
+
+ git_command = 'git clone' + ' ' + git_url + ' ' + 'glusterfs.git'
+ clone_command = chdir + git_command
+ output = hostutils.execute_command(main_host,clone_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to do git clone")
+ return output
+
+ chdir = 'cd ' + down_path + 'glusterfs.git'+' && '
+
+ if branch is "3.2git":
+ git_command = 'git checkout release-3.2 && git pull '
+ else:
+ git_command = 'git pull'
+ pull_command = chdir + git_command
+ output = hostutils.execute_command(main_host, pull_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to do git checkout or git pull")
+ return output
+
+ tar_command = './autogen.sh && ./configure --enable-fusermount && \
+ make dist && cp glusterfs-' + branch + '.tar.gz ../'
+ command = chdir + tar_command
+ output = hostutils.execute_command(main_host,command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to do git clone")
+ return output
+
+ for hostkey in hostkeys:
+ if not hostkey is main_host:
+ output = hostutils.mkdir(hostkey, down_path)
+ output = source_cleanup(hostkey, branch, down_path)
+ chdir = 'cd ' + down_path + ' && '
+ host_obj = env.getHost(hostkey)
+ host_value = 'root@' + host_obj.hostname + ':' + down_path
+ scp = 'scp -o StrictHostKeyChecking=no glusterfs-' + branch + '\
+.tar.gz ' + host_value
+ scp_command = chdir+scp
+ output = hostutils.execute_command(main_host,scp_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to scp the tarball")
+ return output
+ return output
+
+def gluster_install_tar(version):
+ """
+ Installls the Glusterfs of given version in all the
+ machines defined in the testenv.cfg og testunit.
+ ex: gluster_install_tar('3.3.0qa21')
+ """
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+ install_path = "/opt/glusterfs/" + version + "/"
+
+ down_path = ''.join(env.getGlusterDownloadPaths())
+ output = atfutils.get_new_output_obj()
+ if not down_path.endswith('/'):
+ down_path = down_path + '/'
+
+ if system_dirs.match(down_path):
+ logger.error("System Directiories cannot be created")
+ output['exitstatus'] = 1
+ return output
+
+ output = download_scp(version,down_path)
+ if output['exitstatus']:
+ return output
+
+ host_keys = env.getHostsKeys()
+ for hostkey in host_keys:
+ output = stop_gluster_processes(hostkey)
+ output = rpm_check(hostkey)
+ output = gluster_cleanup(hostkey)
+ if output['exitstatus']:
+ return output
+
+ chdir = 'cd ' + down_path + ' && '
+
+ extract = 'tar -xzf glusterfs-' + version + '.tar.gz'
+ extract_command = chdir + extract
+ output = hostutils.execute_command(hostkey, extract_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to extract from the tar ball")
+ return output
+ #changing directory to the glusterfs director
+
+ chdir = 'cd ' + down_path + 'glusterfs-' + version + ' && '
+ output = configure(hostkey, chdir, version)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to build the source")
+ return output
+
+ output = make(hostkey, chdir)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to build the source")
+ return output
+
+ output = symlink(hostkey, install_path)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error('unable to create symlinks')
+ return output
+ output['exitstatus'] = 0
+ return output
+
+def gluster_install_git(branch):
+ """
+ Installs the Glusterfs with given Branch.
+ ex:gluster_install_git('3git') or
+ gluster_install_git('3.2git')
+ """
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+ install_path = "/opt/glusterfs/" + branch + "/"
+
+ down_path = ''.join(env.getGlusterDownloadPaths())
+ output = atfutils.get_new_output_obj()
+ if not down_path.endswith('/'):
+ down_path = down_path + '/'
+
+ if system_dirs.match(down_path):
+ logger.error("System Directiories cannot be created")
+ output['exitstatus'] = 1
+ return output
+
+ output = clone_scp(branch, down_path)
+ if output['exitstatus']:
+ return output
+
+ host_keys = env.getHostsKeys()
+
+ for hostkey in host_keys:
+ output = stop_gluster_processes(hostkey)
+
+ output = rpm_check(hostkey)
+
+ output = gluster_cleanup(hostkey)
+ if output['exitstatus']:
+ return output
+
+ chdir = 'cd ' + down_path + ' && '
+
+ extract = 'tar -xzf glusterfs-' + branch + '.tar.gz'
+ extract_command = chdir + extract
+ output = hostutils.execute_command(hostkey, extract_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to extract from the tar ball")
+ return output
+ #changing directory to the glusterfs director
+
+ chdir = 'cd ' + down_path + 'glusterfs-' + branch + ' && '
+ output = configure(hostkey, chdir, branch)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to build the source")
+ return output
+
+ output = make(hostkey, chdir)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("unable to build the source")
+ return output
+
+ output = symlink(hostkey, install_path)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error('unable to create symlink')
+ return output
+ output['exitstatus'] = 0
+ return output
+
+def rpm_scp(version, down_path, *components):
+ """
+ This functions downloads all the rpms mentioned in the
+ components into one machine , then it scp the directory to all
+ other machines involved
+ """
+ rpm_path = down_path + 'glusterfs.rpm.' + version
+
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+
+ host_keys = env.getHostsKeys()
+ main_host = host_keys[0]
+ output = hostutils.mkdir(main_host, down_path)
+ output = source_cleanup(main_host, version, down_path)
+ output = hostutils.mkdir(main_host, rpm_path)
+ #changing directory to download path
+ chdir = 'cd '+rpm_path+' && '
+
+ component_url = "http://bits.gluster.com/pub/gluster/glusterfs/\
+" + version + "/x86_64/glusterfs-" + version + "-1.x86_64.rpm"
+ wget_command = "wget " + component_url
+ down_command = chdir + wget_command
+ output = hostutils.execute_command(main_host, down_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error('unable to to download the rpms')
+ return output
+
+ for component in components:
+ component_url = "http://bits.gluster.com/pub/gluster/glusterfs/\
+" + version + "/x86_64/glusterfs-" + component + "-" + version + "-1.x86_64.rpm"
+ wget_command = "wget " + component_url
+ down_command = chdir + wget_command
+ output = hostutils.execute_command(main_host, down_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error('unable to to download the rpms')
+ return output
+
+ for hostkey in host_keys:
+ if not hostkey is main_host:
+ output = hostutils.mkdir(hostkey, down_path)
+ output = source_cleanup(hostkey, version, down_path)
+ output = hostutils.mkdir(hostkey, rpm_path)
+ chdir = 'cd ' + down_path + ' && '
+ host_obj = env.getHost(hostkey)
+ host_value = 'root@' + host_obj.hostname + ':' + down_path
+ scp = 'scp -o StrictHostKeyChecking=no -r glusterfs.rpm.\
+' + version + ' ' + host_value
+ scp_command = chdir+scp
+ output = hostutils.execute_command(main_host,scp_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error("Unable to scp the rpms")
+ return output
+
+ return output
+
+def rpm_install(hostkey, version, down_path, component):
+ """
+ This function installs the rpms given, one at a time.
+ """
+ logger = GlobalObj.getLoggerObj()
+ rpm_path = down_path + 'glusterfs.rpm.' + version
+ if component == '':
+ install_command = "rpm -ivh glusterfs-" + version+"\
+-1.x86_64.rpm --nodeps"
+ else:
+ install_command = "rpm -ivh glusterfs-" + component + "-" + version+"\
+-1.x86_64.rpm --nodeps"
+ chdir ='cd ' + rpm_path + ' && '
+ rpm_command = chdir + install_command
+ output = hostutils.execute_command(hostkey, rpm_command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status:
+ logger.error('unable to install rpm')
+ return output
+
+ return output
+
+def gluster_install_rpm(version, *components):
+ """
+ Installs the Glusterfs with given version and
+ the given rpms.
+ components can have: fuse, debuginfo, devel, geo-replication
+ rdma, server
+ ex:gluster_install_rpm('3.3.0qa21','core','fuse') or
+ gluster_install_git('3.3.0qa21','fuse','debuginfo,'core')
+ """
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+ install_path = "/opt/glusterfs/" + version + "/"
+
+ down_path = ''.join(env.getGlusterDownloadPaths())
+ output = atfutils.get_new_output_obj()
+ if not down_path.endswith('/'):
+ down_path = down_path + '/'
+
+ if system_dirs.match(down_path):
+ logger.error("System Directiories cannot be created")
+ output['exitstatus'] = 1
+ return output
+ rpm_path = down_path + 'glusterfs.rpm.' + version
+
+ output = rpm_scp(version, down_path, *components)
+
+ host_keys = env.getHostsKeys()
+ for hostkey in host_keys:
+
+ output = stop_gluster_processes(hostkey)
+ output = rpm_check(hostkey)
+ output = gluster_cleanup(hostkey)
+ if output['exitstatus']:
+ return output
+ output = rpm_install(hostkey, version, down_path, '')
+ if output['exitstatus']:
+ return output
+ if 'fuse' in components:
+ output = rpm_install(hostkey, version, down_path, 'fuse')
+ if output['exitstatus']:
+ return output
+ if 'debuginfo' in components:
+ output = rpm_install(hostkey, version, down_path, 'debuginfo')
+ if output['exitstatus']:
+ return output
+ if 'devel' in components:
+ output = rpm_install(hostkey, version, down_path, 'devel')
+ if output['exitstatus']:
+ return output
+ if 'rdma' in components:
+ output = rpm_install(hostkey, version, down_path, 'rdma')
+ if output['exitstatus']:
+ return output
+ if 'geo-replication' in components:
+ output = rpm_install(hostkey, version, down_path, 'geo-replication')
+ if output['exitstatus']:
+ return output
+ if 'server' in components:
+ output = rpm_install(hostkey, version, down_path, 'server')
+ if output['exitstatus']:
+ return output
+
+ output['exitstatus'] = 0
+ return output
diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py
index 2c21d9b..ef9f45c 100644
--- a/libs/utils/glusterutils.py
+++ b/libs/utils/glusterutils.py
@@ -546,6 +546,63 @@ def volume_reset(serverkey):
output = hostutils.execute_command(serverkey, command, commandInput="y\n")
return output
+def volume_geo_replication(serverkey, slavekey, operation, volume=False,
+ local=False, *options):
+ """
+ operation: {start|stop|config|status|log-rotate}
+ options are valid oly if the operation is 'config'
+ ex: log_file /usr/local/var/log/glusterfs/geo.log
+ remote_gsyncd /usr/local/libexec/glusterfs/gsyncd
+ if you are starting geo-replication session with
+ another volume, you need to give volume = True
+ and by default it take path given in the configuration file
+ """
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ base_command = "gluster volume geo-replication"
+ env = GlobalObj.getTestenvObj()
+ command = [base_command]
+
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ logger.error("ActiveVolume not defined for the TestEnvironment")
+ output['exitstatus'] = 1
+ return output
+
+ volumename = active_volume.volumename
+
+ slave_obj = env.getSlave(slavekey)
+ if not slave_obj:
+ logger.error("Invalid slave. Slave not defined in Testenvironment")
+ output['exitstatus'] = 1
+ return ouput
+ if not local:
+ if not volume:
+ slave_value = slave_obj.hostname +":"+ slave_obj.path
+ else:
+ slave_value = slave_obj.hostname +":"+ slave_obj.volumename
+ else:
+ if not volume:
+ slave_value = slave_obj.path
+ else:
+ slave_value = ":"+slave_obj.volumename
+
+ command.extend([volumename, slave_value])
+
+ if operation == 'config':
+ if options:
+ command.extend(['config', options[0]])
+ else:
+ command.extend(['config'])
+ else:
+ command.extend([operation])
+
+ command = ' '.join(command)
+
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
+
+
def volume_profile(serverkey, operation):
"""
operation:{start|info|stop}
@@ -804,3 +861,95 @@ def create_brick_allservers():
create_brick_output["exitstatus"] = 0
create_brick_output["stdoutdata"] = "Successful in creating bricks on all servers"
return create_brick_output
+
+def create_slave(slavekey):
+ """
+ This function creates the slave. In the sense ,
+ if it is just some path, its not it leave as it is.
+ If path in slave section is given as some exportdir
+ then it will format the device given in the exportdir section
+ with the file system and mounts the device on the path ,
+ both defined in the exportdir section in configuration file
+ """
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
+ env = GlobalObj.getTestenvObj()
+ slave_obj = env.getRawSlave(slavekey)
+ if not slave_obj:
+ logger.error("Invalid slave.Slave not defined in Testenvironment")
+ output['exitstatus'] = 1
+ return output
+ hostname_value = slave_obj.hostname
+ serverkey = re.split("\.", hostname_value, maxsplit=1)[0]
+ exportdir = slave_obj.path
+
+ device = fstype = None
+ """If the exportdir is not a mount point of a device:
+ 1) Remove the existing exportdir
+ 2) Create new exportdir"""
+ if re.match("^\/", exportdir):
+ dirpath = exportdir
+ else:
+ export_obj = env.getExportdir(exportdir)
+ dirpath = export_obj.dir
+ device = export_obj.device
+ fstype = export_obj.fstype
+ options = export_obj.options
+
+ server_obj = env.getServer(serverkey)
+ if server_obj is None:
+ logger.error("Invalid Host. %s not defined in TestEnvironment"
+ % serverkey)
+ output['exitstatus'] = 1
+ return output
+ server_hostname = server_obj.hostname
+
+ logger.debug('%s: Executing Command: %s' %(server_hostname, 'create_slave'))
+ if device:
+ output = hostutils.umount_device(serverkey, device)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ output = hostutils.mkfs(serverkey, device, fstype, options)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ output = hostutils.mount(serverkey, device, fstype, dirpath, options)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+ else:
+ output = hostutils.rmdir(serverkey, dirpath)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ output = hostutils.mkdir(serverkey, dirpath)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ output["exitstatus"] = 0
+ output["stdoutdata"] = "Successfully Created Slave %s" % slavekey
+ return output
+
+def create_slave_allservers():
+ """
+ """
+ create_slave_output = atfutils.get_new_output_obj()
+
+ env = GlobalObj.getTestenvObj()
+ slave_keys = env.getSlaveKeys()
+ for slavekey in slave_keys:
+ output = create_slave(slavekey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ create_slave_output["exitstatus"] = 0
+ create_slave_output["stdoutdata"] = "Successful in creating bricks on all \
+servers"
+ return create_slave_output
diff --git a/libs/utils/hostutils.py b/libs/utils/hostutils.py
index 3955cc6..bc7efa0 100644
--- a/libs/utils/hostutils.py
+++ b/libs/utils/hostutils.py
@@ -258,336 +258,3 @@ def _substitute_value_for_variables(command):
return new_command
-def gluster_install_tar(version):
- """
- """
- logger = GlobalObj.getLoggerObj()
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- down_path = ''.join(env.getGlusterDownloadPaths())
-
- if system_dirs.match(down_path):
- logger.error("System Directiories cannot be created")
- return 1
-
- if not down_path[-1] is '/':
- down_path= down_path+'/'
-
- install_path = "/opt/gusterfs/"+version+"/"
-
- host_keys = env.getHostsKeys()
- for hostkey in host_keys:
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH Connection not established to host'%s'"
- %hostkey)
- return 1
- """
- stopping all the gluster processes
- """
- kill_command = "killall glusterd && killall glusterfsd && killall glusterfs"
- logger.debug('%s: Executing command : %s' %(hostkey, kill_command))
- output = host_connection.executecommand(kill_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- Cleaning /etc/glusterd, usr/local/sbin and /usr/sbin
- """
- remove_command = "rm -rf /etc/glusterd/ && rm -rf /usr/local/sbin/gluster* && rm -rf /usr/sbin/gluster* "
- logger.debug('%s: Executing command : %s' %(hostkey, remove_command))
- output = host_connection.executecommand(remove_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- checking for rpm installation of gluster and removing it.
- """
- cleanup_command = "rpm -qa | grep gluster | xargs rpm -e"
- logger.debug('%s: Executing command : %s' %(hostkey, cleanup_command))
- output = host_connection.executecommand(cleanup_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- mkdir_command = ["mkdir -p",down_path]
- mkdir_command =' '.join(mkdir_command)
- logger.debug('%s: Executing command : %s' %(hostkey, mkdir_command))
- output = host_connection.executecommand(mkdir_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- download_url= "http://bits.gluster.com/pub/gluster/glusterfs/src/glusterfs-"+version+".tar.gz"
- """
- changing directory to the download path
- """
- chdir = 'cd '+down_path+' && '
- wget_command = 'wget '+download_url
- download_command = chdir + wget_command
- logger.debug('%s: Executing command:%s'%(hostkey, download_command))
- output = host_connection.executecommand(download_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- extract = 'tar -xzf glusterfs-'+version+'.tar.gz'
- extract_command = chdir + extract
- logger.debug('%s: Executing command : %s'%(hostkey, extract_command))
- output = host_connection.executecommand(extract_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- """
- changing directory to the glusterfs directory
- """
- chdir = 'cd '+down_path+'glusterfs-'+version+' && '
- configure = "./autogen.sh && ./configure --prefix="+install_path+" CFLAGS=\"-g -O0 -DDEBUG\" "
- configure_command = chdir + configure
- logger.debug('%s: Executing command : %s' %(hostkey, configure_command))
- output = host_connection.executecommand(configure_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- make = "make && make install"
- make_command = chdir + make
- logger.debug('%s: Executing command : %s'%(hostkey, make_command))
- output = host_connection.executecommand(make_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- """
- """
- symlink_command = "ln -s "+install_path+"sbin/gluster /usr/sbin/gluster && ln -s "+install_path+"sbin/glusterd /usr/sbin/glusterd && ln -s "+install_path+"sbin/glusterfsd /usr/sbin/glusterfsd && ln -s "+install_path+"sbin/glusterfs /usr/sbin/glusterfs"
- logger.debug('%s: Executing command : %s'%(hostkey, symlink_command))
- output = host_connection.executecommand(symlink_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
-
- return 0
-
-def gluster_install_git(branch):
- """
- """
- logger = GlobalObj.getLoggerObj()
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- down_path = ''.join(env.getGlusterDownloadPaths())
-
- if system_dirs.match(down_path):
- logger.error("System Directiories cannot be created")
- return 1
-
- if not down_path[-1] is '/':
- down_path= down_path+'/'
-
- install_path = "/opt/gusterfs/"+branch+'/'
-
- host_keys = env.getHostsKeys()
- for hostkey in host_keys:
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH Connection not established to host'%s'"
- %hostkey)
- return 1
- """
- stopping all the gluster processes
- """
- kill_command = "killall glusterd && killall glusterfsd && killall glusterfs"
- logger.debug('%s: Executing command : %s' %(hostkey, kill_command))
- output = host_connection.executecommand(kill_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- Cleaning /etc/glusterd , /usr/local/sbin , /usr/sbin/
- and previous git directory
- """
- remove_command = "rm -rf /etc/glusterd/ && rm -rf "+down_path+"glusterfs.git && rm -rf /usr/local/sbin/gluster* && rm -rf /usr/sbin/gluster*"
- logger.debug('%s: Executing command : %s' %(hostkey, remove_command))
- output = host_connection.executecommand(remove_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- checking for rpm installation of gluster and removing it.
- """
- cleanup_command = "rpm -qa | grep gluster | xargs rpm -e"
- logger.debug('%s: Executing command : %s' %(hostkey, cleanup_command))
- output = host_connection.executecommand(cleanup_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- mkdir_command = ["mkdir -p",down_path]
- mkdir_command =' '.join(mkdir_command)
- logger.debug('%s: Executing command : %s' %(hostkey, mkdir_command))
- output = host_connection.executecommand(mkdir_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- git_url ='https://github.com/gluster/glusterfs.git'
-
- """
- changing directory to the download path
- """
- chdir = 'cd '+down_path+' && '
- clone_command = ' git clone '+git_url+" "+"glusterfs.git"
- git_command = chdir + clone_command
-
- logger.debug('%s: Executing command:%s'%(hostkey, git_command))
- output = host_connection.executecommand(git_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- """
- changing directory to the glusterfs directory and checking out
- to the branch
- """
- chdir = 'cd '+down_path+'glusterfs.git'+' && '
- checkout = "git checkout "+branch+' && '
- git_pull = "git pull"
- git_command = chdir+ checkout + git_pull
- logger.debug('%s: Executing command : %s' %(hostkey, git_command))
- output = host_connection.executecommand(git_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- configure = "./autogen.sh && ./configure --prefix="+install_path+" CFLAGS=\"-g -O0 -DDEBUG -lefence\" "
- configure_command = chdir + configure
- logger.debug('%s: Executing command : %s' %(hostkey, configure_command))
- output = host_connection.executecommand(configure_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- make = "make && make install"
- make_command = chdir + make
- logger.debug('%s: Executing command : %s'%(hostkey, make_command))
- output = host_connection.executecommand(make_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- """
- """
- symlink_command = "ln -s "+install_path+"sbin/gluster /usr/sbin/gluster && ln -s "+install_path+"sbin/glusterd /usr/sbin/glusterd && ln -s "+install_path+"sbin/glusterfsd /usr/sbin/glusterfsd && ln -s "+install_path+"sbin/glusterfs /usr/sbin/glusterfs"
- logger.debug('%s: Executing command : %s'%(hostkey, symlink_command))
- output = host_connection.executecommand(symlink_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- return 0
-
-def gluster_install_rpm(version, *components):
- """
- """
- logger = GlobalObj.getLoggerObj()
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- down_path = ''.join(env.getGlusterDownloadPaths())
-
- if system_dirs.match(down_path):
- logger.error("System Directiories cannot be created")
- return 1
-
- if not down_path[-1] is '/':
- down_path= down_path+'/'
- rpm_path = down_path+"glusterfs.rpm"
-
- host_keys = env.getHostsKeys()
- for hostkey in host_keys:
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH Connection not established to host'%s'"
- %hostkey)
- return 1
-
- """
- stopping all the gluster processes
- """
- kill_command = "killall glusterd && killall glusterfsd && killall glusterfs"
- logger.debug('%s: Executing command : %s' %(hostkey, kill_command))
- output = host_connection.executecommand(kill_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- deleting /etc/glusterd
- """
- remove_command = "rm -rf /etc/glusterd/ && rm -rf /usr/sbin/gluster* && rm -rf /usr/local/sbin/gluster*"
- logger.debug('%s: Executing command : %s' %(hostkey, remove_command))
- output = host_connection.executecommand(remove_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- """
- checking for rpm installation of gluster and removing it.
- """
- cleanup_command = "rpm -qa | grep gluster | xargs rpm -e"
- logger.debug('%s: Executing command : %s' %(hostkey, cleanup_command))
- output = host_connection.executecommand(cleanup_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
-
- mkdir_command = ["mkdir -p",rpm_path]
- mkdir_command =' '.join(mkdir_command)
- logger.debug('%s: Executing command : %s' %(hostkey, mkdir_command))
- output = host_connection.executecommand(mkdir_command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- for component in components:
- component_url = "http://bits.gluster.com/pub/gluster/glusterfs/"+version+"/x86_64/glusterfs-"+component+"-"+version+"-1.x86_64.rpm"
- chdir = 'cd '+rpm_path+' && '
- wget_command = "wget "+component_url
- down_command = chdir + wget_command
-
- logger.debug('%s: Executing command:%s'%(hostkey, down_command))
- output = host_connection.executecommand(down_command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
-
- install_command = "rpm -ivh glusterfs-"+component+"-"+version+"-1.x86_64.rpm --nodeps"
-
- command = chdir + install_command
-
- logger.debug('%s: Executing command:%s'%(hostkey, command))
- output = host_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- return 1
-
- return 0
diff --git a/libs/utils/managerutils.py b/libs/utils/managerutils.py
index 6f72e99..057460e 100644
--- a/libs/utils/managerutils.py
+++ b/libs/utils/managerutils.py
@@ -1,4 +1,4 @@
-"""managerutils module.
+"""managerutils module.
Supported Wrappers:-
---------------
@@ -9,6 +9,7 @@ Supported Wrappers:-
import re
import ssh
from atfglobals import GlobalObj
+import pdb
def ssh_connect(hostkey):
"""
@@ -19,7 +20,7 @@ def ssh_connect(hostkey):
if cm is None:
logger.error("Init ConnectionsManager")
return 1
-
+
host_connection = cm.getConnection(hostkey)
if not host_connection:
host_obj = env.getHost(hostkey)
@@ -53,10 +54,9 @@ def ssh_connect_allhosts():
for hostkey in hosts_keys:
return_status = ssh_connect(hostkey)
if return_status:
- return return_status
-
+ return return_status
+
return 0
__all__ = ['ssh_connect',
'ssh_connect_allhosts']
-