diff options
author | Vijaykumar <vkoppad@redhat.com> | 2012-01-19 15:49:17 +0530 |
---|---|---|
committer | Vijaykumar <vkoppad@redhat.com> | 2012-01-19 15:53:56 +0530 |
commit | 6530684f9f32ecf5c0af4547ec3666e5aaeef9d2 (patch) | |
tree | 4c02c62a0a19f85d3d3f6e6af07926a9964a88e0 /libs/utils/glusterutils.py | |
parent | 78f3643f19c004c7a7b43c29e1b48e671a5231eb (diff) |
library functions: remove-brick, quota, profile
top, log rotate, replace-brick and
testenv function (removeBricksFromVolume).
Change-Id: I6593f831e5002bd077eee0ce8bf6a8c5aca18ba5
Signed-off-by: Vijaykumar <vkoppad@redhat.com>
Diffstat (limited to 'libs/utils/glusterutils.py')
-rw-r--r-- | libs/utils/glusterutils.py | 388 |
1 files changed, 306 insertions, 82 deletions
diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py index afd5db0..39f6a21 100644 --- a/libs/utils/glusterutils.py +++ b/libs/utils/glusterutils.py @@ -1,5 +1,4 @@ """glusterutils module contains wrappers for gluster commands. - *) glusterd_start *) glusterd_start_allservers *) glusterd_stop @@ -86,7 +85,7 @@ def glusterd_start(serverkey, force=False): else: logger.error("Unable to start glusterd") return 1 - + def glusterd_start_allservers(force=False): """ """ @@ -111,7 +110,7 @@ def glusterd_stop(serverkey): logger.error("SSH connection to host '%s' has not been established" % serverkey) return 1 - + gluster_pid_list = [] output = host_connection.executecommand("pidof glusterd") return_status = atfutils.assert_failure(output['exitstatus']) @@ -134,7 +133,7 @@ def glusterd_stop(serverkey): break return return_status - + def glusterd_stop_allservers(): """ """ @@ -156,7 +155,7 @@ def glusterd_restart(serverkey): else: return_status = glusterd_start(serverkey) return return_status - + def glusterd_remove_dir(serverkey): """ """ @@ -177,7 +176,7 @@ def glusterd_remove_dir(serverkey): logger.error("SSH connection to host '%s' has not been established" % serverkey) return 1 - + command = ' '.join([base_command, glusterd_dir]) logger.debug('%s: Executing Command: %s' % (serverkey, command)) output = server_connection.executecommand(command) @@ -193,7 +192,7 @@ def glusterd_remove_dir_allservers(): all_servers = env.getServers() for serverkey in all_servers.keys(): return_status = glusterd_remove_dir(serverkey) - + return 0 @@ -222,7 +221,7 @@ def glusterd_remove_logs(serverkey): if server_obj.installpath: prefix_path = server_obj.installpath - + for path in log_paths: absolute_path_list.append(prefix_path + path) @@ -235,7 +234,7 @@ def glusterd_remove_logs(serverkey): atfutils.print_stderr(output['stderrdata']) return 0 - + def glusterd_remove_logs_allservers(): """ """ @@ -243,7 +242,7 @@ def glusterd_remove_logs_allservers(): all_servers = env.getServers() for serverkey in all_servers.keys(): return_status = glusterd_remove_logs(serverkey) - + return 0 def volume_delete(serverkey): @@ -251,6 +250,7 @@ def volume_delete(serverkey): """ logger = GlobalObj.getLoggerObj() base_command = "gluster volume delete " + command = [base_command] env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() active_volume = env.getActiveVolume() @@ -258,8 +258,8 @@ def volume_delete(serverkey): logger.error("Invalid Volume.ActiveVolume not defined" + "for the TestEnvironment") return 1 - volumename = active_volume.volumename - command = base_command + volumename + command.extend([active_volume.volumename]) + command = ' '.join(command) host_connection = cm.getConnection(serverkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -285,7 +285,7 @@ def volume_create(serverkey): if not active_volume: logger.error("ActiveVolume not defined for the TestEnvironment") return 1 - command.extend([active_volume.volumename]) + command.extend([active_volume.volumename]) if active_volume.replica: command.extend(["replica", active_volume.replica]) @@ -295,12 +295,12 @@ def volume_create(serverkey): if active_volume.transporttype: command.extend(["transport", active_volume.transporttype]) - + command = ' '.join(command) for brick_obj in active_volume.bricks: brick_value = brick_obj.hostname + ":" + brick_obj.path command = ' '.join([command, brick_value]) - + host_connection = cm.getConnection(serverkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -321,18 +321,20 @@ def volume_start(serverkey, force=False): """ """ logger = GlobalObj.getLoggerObj() - base_command = "gluster volume start " + base_command = "gluster volume start" + command = [base_command] env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() active_volume = env.getActiveVolume() if not active_volume: logger.error("ActiveVolume not defined for the TestEnvironment") return 1 - volumename = active_volume.volumename - command = base_command + volumename + command.extend([active_volume.volumename]) + if force: - command = command + " force" - + command.extend(["force"]) + + command=' '.join(command) host_connection = cm.getConnection(serverkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -353,18 +355,20 @@ def volume_stop(serverkey, force=False): """ """ logger = GlobalObj.getLoggerObj() - base_command = "gluster volume stop " + base_command = "gluster volume stop" + command = [base_command] env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() active_volume = env.getActiveVolume() if not active_volume: logger.error("ActiveVolume not defined for the TestEnvironment") return 1 - volumename = active_volume.volumename - command = base_command + volumename + command.extend([active_volume.volumename]) + if force: - command = command + " force" - + command.extend(["force"]) + + command = ' '.join(command) host_connection = cm.getConnection(serverkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -378,7 +382,7 @@ def volume_stop(serverkey, force=False): atfutils.print_stderr(output['stderrdata']) return return_status -def volume_addbrick(serverkey, *bricks): +def volume_addbrick(serverkey, *bricks, **arguments): """ """ logger = GlobalObj.getLoggerObj() @@ -387,13 +391,22 @@ def volume_addbrick(serverkey, *bricks): cm = GlobalObj.getConnectionsManagerObj() active_volume = env.getActiveVolume() command = [base_command] - + if not active_volume: logger.error("ActiveVolume not defined for the TestEnvironment") return 1 volumename = active_volume.volumename - + command.extend([volumename]) + + """ + arguments can have key brick_type + brick_type=[<stripe|replica> <COUNT>] + """ + + if arguments.has_key('brick_type'): + command.extend([arguments['brick_type']]) + for brick in bricks: brick_obj = env.getBrick(brick) if not brick_obj: @@ -401,7 +414,7 @@ def volume_addbrick(serverkey, *bricks): return 1 brick_value = brick_obj.hostname + ":" + brick_obj.path command.extend([brick_value]) - + command = ' '.join(command) host_connection = cm.getConnection(serverkey) if not host_connection: @@ -419,7 +432,65 @@ def volume_addbrick(serverkey, *bricks): atfutils.print_stderr(output['stderrdata']) return return_status -def volume_replacebrick(serverkey, brick, newbrick, operation): +def volume_removebrick(serverkey, *bricks, **arguments): + """ + *bricks : list of bricks to be removed + **arguments(optional): It takes key:value pair + we are using optional keys + brick_type and operation + brick_type: [replica <COUNT>] + operation:{start|pause|abort|status|commit|force} + """ + logger = GlobalObj.getLoggerObj() + base_command = "gluster volume remove-brick" + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() + active_volume = env.getActiveVolume() + command = [base_command] + + if not active_volume: + logger.error("ActiveVolume not defined in the TestEnvironment") + return 1 + command.extend([active_volume.volumename]) + """ + brick_type can have only [replica <COUNT>] + """ + if arguments.has_key('brick_type'): + command.extend([arguments['brick_type']]) + + for brick in bricks: + brick_obj = env.getBrick(brick) + if not brick_obj: + logger.error("Invalid Brick. Brick not defined in TestEnviroment") + return 1 + brick_value = brick_obj.hostname +':'+ brick_obj.path + command.extend([brick_value]) + """ + operation can have {start|pause|abort|status|commit|force} + which is optional. + """ + + if arguments.has_key('operation'): + command.extend([arguments['operation']]) + + command = ' '.join(command) + host_connection = cm.getConnection(serverkey) + if not host_connection: + logger.error("SSH connection to host '%s' has not been established" + % serverkey) + return 1 + + logger.debug('%s:Executing Command: %s'% (serverkey, command)) + output = host_connection.executecommand(command, commandInput="y\n") + return_status = atfutils.assert_success(output['exitstatus']) + if not return_status: + if env.removeBricksFromVolume(*bricks): + return 1 + atfutils.print_stdout(output['stdoutdata']) + atfutils.print_stderr(output['stderrdata']) + return return_status + +def volume_replacebrick(serverkey, replace_brick, to_brick, operation): """ """ logger = GlobalObj.getLoggerObj() @@ -433,14 +504,20 @@ def volume_replacebrick(serverkey, brick, newbrick, operation): logger.error("ActiveVolume not defined for the TestEnvironment") return 1 volumename = active_volume.volumename - replace_brick = env.getbrick(replacebrick_key) - to_brick = env.getbrick(tobrick_key) - - if not (to_brick and replace_brick): + replace_brick_obj = env.getBrick(replace_brick) + to_brick_obj = env.getBrick(to_brick) + """ + checking if objects are none + """ + if not (replace_brick_obj and to_brick_obj): logger.error("Invalid Brick. Brick Not defined in TestEnvironment") return 1 - command.extend([volumename, brick, newbrick, operation]) + replace_brick_value = replace_brick_obj.hostname+':'+replace_brick_obj.path + to_brick_value = to_brick_obj.hostname+':'+to_brick_obj.path + + + command.extend([volumename, replace_brick_value, to_brick_value, operation]) command = ' '.join(command) host_connection = cm.getConnection(serverkey) if not host_connection: @@ -451,12 +528,12 @@ def volume_replacebrick(serverkey, brick, newbrick, operation): logger.debug('%s: Executing Command: %s' % (serverkey, command)) output = host_connection.executecommand(command, commandInput="y\n") return_status = atfutils.assert_success(output['exitstatus']) - if not return_status: + if (not return_status) and (operation == "commit"): if env.replaceBrickInVolume(brick, newbrick): return 1 atfutils.print_stdout(output['stdoutdata']) atfutils.print_stderr(output['stderrdata']) - return output + return return_status def volume_set(serverkey, key, value): """ @@ -466,16 +543,16 @@ def volume_set(serverkey, key, value): env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() command = [base_command] - + active_volume = env.getActiveVolume() if not active_volume: logger.error("ActiveVolume not defined for the TestEnvironment") return 1 volumename = active_volume.volumename - + command.extend([volumename, key, value]) command = ' '.join(command) - + host_connection = cm.getConnection(serverkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -489,6 +566,46 @@ def volume_set(serverkey, key, value): atfutils.print_stderr(output['stderrdata']) return return_status +def volume_log_rotate(serverkey, brick): + """ + brick is compulsory parameter + """ + logger = GlobalObj.getLoggerObj() + base_command = "gluster volume log rotate" + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() + command = [base_command] + + active_volume = env.getActiveVolume() + if not active_volume: + logger.error("ActiveVolume not defined for the Testenvironment") + return 1 + volumename = active_volume.volumename + + brick_obj = env.getBrick(brick) + if not brick_obj: + logger.error("Invalid Brick. Brick Not defined in TestEnvironment") + return 1 + + brick_value = brick_obj.hostname + ":" + brick_obj.path + + command.extend([volumename, brick_value]) + + command = ' '.join(command) + + host_connection = cm.getConnection(serverkey) + if not host_connection: + logger.error("SSH connection to host '%s' has not been established" + % serverkey) + return 1 + + logger.debug('%s: Executing Command: %s' %(serverkey, 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 + def volume_reset(serverkey): """ """ @@ -515,39 +632,163 @@ def volume_reset(serverkey): atfutils.print_stderr(output['stderrdata']) return return_status -def peer_probe(fromserverkey): +def volume_profile(serverkey, operation): """ + operation:{start|info|stop} """ logger = GlobalObj.getLoggerObj() - base_command = "gluster peer probe " + base_command = "gluster volume profile" + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() command = [base_command] - all_servers = {} + + active_volume = env.getActiveVolume() + if not active_volume: + logger.error("ActiveVolume not defined for the TestEnvironment") + return 1 + volumename = active_volume.volumename + + command.extend([volumename, operation]) + command = ' '.join(command) + + host_connection = cm.getConnection(serverkey) + if not host_connection: + logger.error("SSH connection to the Host '%s' has not been established" + & serverkey) + return 1 + + logger.debug('%s: Execute Command: %s' %(serverkey, 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 + +def volume_quota(serverkey, operation, **arguments): + """ + arguments can have two values + path: path can be '/' + ex: path='/' + value: value can be in GB or MB + ex: value=1GB + """ + logger = GlobalObj.getLoggerObj() + base_command = "gluster volume quota" env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() - all_servers = env.getServers() - all_servers.pop(fromserverkey) - - for key in all_servers.keys(): - if key is fromserverkey: - continue - else: - server_obj = all_servers[key] - command.extend([server_obj.hostname]) + command = [base_command] + active_volume = env.getActiveVolume() + if not active_volume: + logger.error("ActiveVolume not defined for the Testenvironment") + return 1 + volumename = active_volume.volumename + + command.extend([volumename, operation]) + + if arguments.has_key('path'): + command.extend([arguments['path']]) + + if arguments.has_key('value'): + command.extend([arguments['value']]) command = ' '.join(command) - host_connection = cm.getConnection(fromserverkey) + + host_connection = cm.getConnection(serverkey) if not host_connection: - logger.error("SSH connection to host '%s' has not been established" + logger.error("SSH connection to the host '%s' has not been established" % serverkey) return 1 - logger.debug('%s: Executing Command: %s' % (fromserverkey, command)) - output = host_connection.executecommand(command) + logger.debug('%s: Executing Command: %s' % (serverkey, 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 + +def volume_top(serverkey, operation, **arguments): + """ + operation:{[open|read|write|opendir|readdir] |[read-perf|write-perf + bs <size> count <count>]} + arguments(optional): Takes maximum two parameters + brick : brick1, brick2 etc + list-cnt: can take any number + + """ + logger = GlobalObj.getLoggerObj() + base_command = "gluster volume top" + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() + command = [base_command] + + active_volume = env.getActiveVolume() + if not active_volume: + logger.error("ActiveVolume not defines for the TestEnvironment") + return 1 + volumename = active_volume.volumename + + command.extend([volumename, operation]) + + if arguments.has_key('brick'): + brick_obj = env.getBrick(arguments['brick']) + if not brick_obj: + logger.error("Invalid Brick. Brick Not defined in TestEnvironment") + return 1 + brick_value = brick_obj.hostname+':'+brick_obj.path + command.extend(['brick',brick_value]) + + if arguments.has_key('list_cnt'): + command.extend(['list-cnt', arguments['list_cnt']]) + + command = ' '.join(command) + + host_connection = cm.getConnection(serverkey) + if not host_connection: + logger.error("SSH connection to host '%s' has not been established" + %serverkey) + return 1 + + logger.debug("%s: Executing command: %s" %(serverkey, 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 +def peer_probe(fromserverkey): + """ + """ + logger = GlobalObj.getLoggerObj() + base_command = "gluster peer probe " + all_servers = {} + env = GlobalObj.getTestenvObj() + cm = GlobalObj.getConnectionsManagerObj() + all_servers = env.getServers() + all_servers.pop(fromserverkey) + host_connection = cm.getConnection(fromserverkey) + if not host_connection: + logger.error("SSH connection to host '%s' has not been established" + % serverkey) + return 1 + + for key in all_servers.keys(): + if not key is fromserverkey: + server_obj = all_servers[key] + """ + One hostname is being taken at a time while executing peer probe + """ + command = ' '.join([base_command, server_obj.hostname]) + logger.debug('%s: Executing Command: %s' % (fromserverkey, 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 + def create_brick(brickkey): """ """ @@ -555,7 +796,7 @@ def create_brick(brickkey): return_status = 1 env = GlobalObj.getTestenvObj() brick_obj = env.getRawBrick(brickkey) - + hostname_value = brick_obj.hostname serverkey = re.split("\.", hostname_value, maxsplit=1)[0] @@ -564,7 +805,7 @@ def create_brick(brickkey): """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: @@ -583,7 +824,7 @@ def create_brick(brickkey): if mount_exportdir(serverkey, device, fstype, options, dirpath): return return_status return 0 - + else: if hostutils.rmdir(serverkey, dirpath): return return_status @@ -598,13 +839,13 @@ def umount_device(serverkey, device): logger = GlobalObj.getLoggerObj() base_command = "umount " cm = GlobalObj.getConnectionsManagerObj() - + server_connection = cm.getConnection(serverkey) if not server_connection: logger.error("SSH connection to host '%s' has not been established" % serverkey) return 1 - + mountpoints = hostutils.find_mountpoints(serverkey, device) for mountpoint in mountpoints: @@ -631,7 +872,7 @@ def mount_exportdir(serverkey, device, fstype, options, dirpath): base_command = "mount " cm = GlobalObj.getConnectionsManagerObj() command = [base_command] - + server_connection = cm.getConnection(serverkey) if not server_connection: logger.error("SSH connection to host '%s' has not been established" @@ -641,10 +882,10 @@ def mount_exportdir(serverkey, device, fstype, options, dirpath): if fstype is None: fstype = "xfs" command.extend(["-t", fstype]) - + if options: command.extend([options]) - + command.extend([device, dirpath]) command = ' '.join(command) @@ -666,7 +907,7 @@ def create_brick_allservers(): return return_status return 0 - + __all__ = ['glusterd_start', 'glusterd_start_allservers', @@ -689,20 +930,3 @@ __all__ = ['glusterd_start', 'create_brick_allservers', 'mount_exportdir', 'umount_device'] - - - - - - - - - - - - - - - - - |