From da93b886f28f3818cb11a5a35fae37abe2ebb988 Mon Sep 17 00:00:00 2001 From: Vijaykumar Date: Mon, 13 Feb 2012 14:54:42 +0530 Subject: Geo-replication library and gluster installation. * Geo-replication library function in glusterutils * A new section in configuration file for geo-rep * In gluster installation , changing libexecdir to /usr/local/libexec in configuration. * Removed some unwanted code. * handling to have a geo-rep session locally also. Change-Id: Ifcf00b73ed933077640113ce0528b39bdad55999 Signed-off-by: Vijaykumar Signed-off-by: root --- libs/utils/glusterinstall.py | 498 +++++++++++++++++++++++++++++++++++++++++++ libs/utils/glusterutils.py | 149 +++++++++++++ libs/utils/hostutils.py | 333 ----------------------------- libs/utils/managerutils.py | 10 +- 4 files changed, 652 insertions(+), 338 deletions(-) create mode 100644 libs/utils/glusterinstall.py (limited to 'libs/utils') 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'] - -- cgit