From 5388b3ab6ba7480223624554e42a157dbe7d4744 Mon Sep 17 00:00:00 2001 From: Shwetha-H-Panduranga Date: Fri, 20 Jan 2012 17:03:31 +0530 Subject: Adding new library to stop a volume's brick Change-Id: I6045f4f5510a2ea087592a7af57767db0be4064c Signed-off-by: Shwetha-H-Panduranga Adding an argument signal for specifying the signal type for the kill command Change-Id: Ief94944fa7ed9ae6f2b764a542d61769a601b044 Signed-off-by: Shwetha-H-Panduranga --- libs/utils/glusterutils.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py index 39f6a21..8264f3e 100644 --- a/libs/utils/glusterutils.py +++ b/libs/utils/glusterutils.py @@ -22,6 +22,7 @@ """ import re +import os import atfutils import hostutils from atfglobals import GlobalObj @@ -755,6 +756,71 @@ def volume_top(serverkey, operation, **arguments): atfutils.print_stderr(output['stderrdata']) return return_status +def volume_stop_brick(brickkey, signal="SIGTERM"): + """ + Description: Stop a brick + Arguments: brickkey. (The brick to be stopped. Ex:- "brick1") + """ + output = {} + output['exitstatus'] = None + output['stdoutdata'] = None + output['stderrdata'] = None + + base_command = "kill -s %s $(cat %s)" + glusterd_vol_dir = "/etc/glusterd/vols" + brick_pid_dir = "run" + pid_file_extension = ".pid" + + logger = GlobalObj.getLoggerObj() + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() + + """Get the active volume + """ + active_volume = atfutils.get_active_volume() + if active_volume is None: + output['exitstatus'] = 1 + return output + volumename = active_volume.volumename + + """ Get the serverkey on which it has to be executed + """ + raw_brick_obj = env.getRawBrick(brickkey) + if not raw_brick_obj: + logger.error("InValid Brick. %s not defined in TestEnvironment" + % brickkey) + output['exitstatus'] = 1 + return output + serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0] + server_connection = cm.getConnection(serverkey) + if not server_connection: + logger.error("SSH connection to host '%s' has not been established" + % serverkey) + output['exitstatus'] = 1 + return output + + """ Get the brickobj + """ + brick_obj = env.getBrick(brickkey) + if not brick_obj: + logger.error("Invalid Brick. Brick Not defined in TestEnvironment") + output['exitstatus'] = 1 + return output + + """ Absolute path for the file containing the pid of brick process + """ + hostname = brick_obj.hostname + path = brick_obj.path.replace("/", "-") + pid_filename = hostname + path + pid_file_extension + pid_file_abspath = os.path.join(glusterd_vol_dir, volumename, + brick_pid_dir, pid_filename) + + command = base_command % (signal, pid_file_abspath) + output = server_connection.executecommand(command, commandInput="y\n") + atfutils.print_stdout(output['stdoutdata']) + atfutils.print_stderr(output['stderrdata']) + return output + def peer_probe(fromserverkey): """ """ -- cgit