From 51d21cdc228103119773ed228c0d5242e8b7449b Mon Sep 17 00:00:00 2001 From: Vijaykumar Date: Fri, 20 Jan 2012 16:52:40 +0530 Subject: Gluster installation through tar,git,rpm. Signed-off-by: Vijaykumar Change-Id: I10cf998ff87dabfbc3cd4abd5762dba255e53042 Signed-off-by: Vijaykumar --- libs/connect/ssh.py | 35 +++-- libs/utils/hostutils.py | 374 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 379 insertions(+), 30 deletions(-) diff --git a/libs/connect/ssh.py b/libs/connect/ssh.py index a419c31..e4540d5 100755 --- a/libs/connect/ssh.py +++ b/libs/connect/ssh.py @@ -7,8 +7,8 @@ import time from atfglobals import GlobalObj class SshConnection(): - - def __init__(self): + + def __init__(self): self._connection = paramiko.SSHClient() def connect(self, host, user, password): @@ -17,14 +17,14 @@ class SshConnection(): SSH to Server "host" as User "user" Parameter: - host: Server IP Address + host: Server IP Address user: Login Username password: Login password Return: Success: 0 Failure: 1 - """ + """ logger = GlobalObj.getLoggerObj() self._connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -43,22 +43,22 @@ class SshConnection(): except paramiko.SSHException: logger.error("SSHException: Unknown server " + host) - return 1 + return 1 return 0 def close(self): """ Objective: - Close SSH Connections + Close SSH Connections """ self._connection.close() - return + return def executecommand(self, command, commandInput=None): """ Objective: - Execute Command "comamnd" + Execute Command "comamnd" Parameters: command: command to execute @@ -73,14 +73,23 @@ class SshConnection(): output["stdoutdata"] = None output["stderrdata"] = None exit_status_ready_flag = True - + try: transport = self._connection.get_transport() channel = transport.open_session() channel.exec_command(command) # Adding sleep to get the correct exit_status. - time.sleep(5) - exit_status_ready_flag = channel.exit_status_ready() + 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") @@ -91,7 +100,7 @@ class SshConnection(): after executing comamnd for command completion") stdin.write("\n") return output - + stdout = channel.makefile("rb") stderr = channel.makefile_stderr("rb") exit_status = channel.recv_exit_status() @@ -104,5 +113,3 @@ class SshConnection(): logger.error("Unable to Execute Command: " + command) return output - - diff --git a/libs/utils/hostutils.py b/libs/utils/hostutils.py index e6f7189..8350c02 100644 --- a/libs/utils/hostutils.py +++ b/libs/utils/hostutils.py @@ -27,15 +27,15 @@ def cd(hostkey, dirpath): if not host_connection: logger.error("SSH Connection Not established to host '%s' " % hostkey) return 1 - + command = ' '.join([base_command, dirpath]) 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']) - return return_status - + return return_status + def rmdir(hostkey, dirpath): """ """ @@ -45,7 +45,7 @@ def rmdir(hostkey, dirpath): if system_dirs.match(dirpath): logger.error("System Directiories cannot be deleted") return 1 - + else: host_connection = cm.getConnection(hostkey) if not host_connection: @@ -60,7 +60,7 @@ def rmdir(hostkey, dirpath): atfutils.print_stdout(output['stdoutdata']) atfutils.print_stderr(output['stderrdata']) return return_status - + def mkdir(hostkey, dirpath): """ """ @@ -92,7 +92,7 @@ def mkfs(hostkey, device, fstype=None): """ logger = GlobalObj.getLoggerObj() base_command = "mkfs" - cm = GlobalObj.getConnectionsManagerObj() + cm = GlobalObj.getConnectionsManagerObj() host_connection = cm.getConnection(hostkey) command = [base_command] options = [] @@ -103,9 +103,9 @@ def mkfs(hostkey, device, fstype=None): if fstype is None: fstype = "xfs" - + options.extend(["-t", fstype, "-f", device]) - + command.extend(options) command = ' '.join(command) logger.debug('%s: Executing Command: %s' % (hostkey, command)) @@ -119,9 +119,9 @@ def find_mountpoints(hostkey, device): """ """ logger = GlobalObj.getLoggerObj() - base_command = "mount | grep " + base_command = "mount | grep " cm = GlobalObj.getConnectionsManagerObj() - + host_connection = cm.getConnection(hostkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -157,6 +157,7 @@ def execute_command(hostkey, command, commandInput=None): return output + def _substitute_value_for_variables(command): """ """ @@ -178,14 +179,14 @@ def _substitute_value_for_variables(command): "name", "option"]) variables_to_replace = [] - + variables = pattern_for_variables.findall(command) - if not variables: + if not variables: return new_command - + else: active_volume = env.getActiveVolume() - + for variable in variables: if variable not in variables_to_replace: name, option = (variable.strip("<>")).split(".") @@ -224,11 +225,352 @@ def _substitute_value_for_variables(command): new_command = "" return new_command - return new_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 + + + + __all__ = ['cd', 'rmdir', 'mkdir', 'mkfs', 'find_mountpoints', - 'execute_command'] + 'execute_command', + 'gluster_install_tar', + 'gluster_install_git', + 'gluster_install_rpm'] -- cgit