diff options
Diffstat (limited to 'Libraries/GlusterCommands')
-rwxr-xr-x | Libraries/GlusterCommands/ATFGlusterPeer.py | 38 | ||||
-rwxr-xr-x | Libraries/GlusterCommands/ATFGlusterVolume.py | 230 | ||||
-rwxr-xr-x | Libraries/GlusterCommands/ATFGlusterd.py | 103 |
3 files changed, 371 insertions, 0 deletions
diff --git a/Libraries/GlusterCommands/ATFGlusterPeer.py b/Libraries/GlusterCommands/ATFGlusterPeer.py new file mode 100755 index 0000000..9e40f50 --- /dev/null +++ b/Libraries/GlusterCommands/ATFGlusterPeer.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import ATFUtils +import ATFTestEnv + +def probe(): + """ + Description: + probe peer specified by <HOSTNAME> + + Parameters: + None + + Returns: + Success: 0 + Failure: 1 + """ + + command = "gluster peer probe " + servers = ATFUtils.TestEnvObj.get_servershostlist() + + length = len(servers) + if (length == 1): + ATFUtils.Logger.warning("Self Probing of Server Not Required") + return 0 + else: + fromhost = servers.pop(0) + for host in servers: + command = command + host + " " + + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + host=fromhost, + user='root') + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + diff --git a/Libraries/GlusterCommands/ATFGlusterVolume.py b/Libraries/GlusterCommands/ATFGlusterVolume.py new file mode 100755 index 0000000..20bfd4f --- /dev/null +++ b/Libraries/GlusterCommands/ATFGlusterVolume.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python +import ATFUtils +import ATFTestEnv +import re + +def create_volume(volumekey, *exportdirs, **arguments): + """ + Description: + Create a new Volume of specified type with mentioned bricks + + Parameters: + volumekey: Name of the Volume + + exportdirs: List of exportdirs to be used to create Volume + + arguments: Key=Value pair for "Volume Type" and "Transport Type". + 'voltype' = stripe|replica|distribute + 'transport' = tcp|rdma|tcp,rdma + 'host' = Server_IP + 'user' = User + + Return: + Success: 0 + Failure: 1 + + Example: + create('Replicate', + 'host1:export1', + 'host2:export1, + voltype='replica 2', + transport='transport tcp' + host = 'host(1..n)' + server = 'server(1..n)' + ) + """ + + command = "gluster volume create" + + volumename = ATFUtils.TestEnvObj.get_volume(volumekey) + if ( volumename == ''): + ATFUtils.Logger.error("Volume %s Not defined in GlobalParam File" % + volumekey) + return 1 + else: + command = command + " " + volumename + + if (arguments.has_key('voltype')): + command = command + " " + arguments.pop('voltype') + + if (arguments.has_key('transport')): + command = command + " " + arguments.pop('transport') + + exportdirlist = [] + for exportdir in exportdirs: + hostkey, exportkey = re.split(':', exportdir) + + host = ATFUtils.TestEnvObj.get_host(hostkey) + if ( host == '' ): + ATFUtils.Logger.error("Host %s Not defined in GlobalParam File" % + hostkey) + return 1 + + export = ATFUtils.TestEnvObj.get_exportdir(exportkey) + if (export == '' ): + ATFUtils.Logger.error( + "ExportDir %s Not defined in GlobalParam File" % exportkey) + return 1 + + exportdirlist.append(host + ":" +export) + + for exportdir in exportdirlist: + command = command + " " + exportdir + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def start_volume(volumekey, force='', **arguments): + """ + Description: + Start volume specified by volumename + + Parameters: + volumekey: Name of the Volume + + Returns: + Success: 0 + Failure: 1 + """ + + command = "gluster volume start" + + volumename = ATFUtils.TestEnvObj.get_volume(volumekey) + if ( volumename == ''): + ATFUtils.Logger.error("Volume %s Not defined in GlobalParam File" % + volumekey) + return 1 + else: + command = command + " " + volumename + " " + force + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def stop_volume(volumekey, force='', **arguments): + """ + Description: + Stop volume specified by volumename + + Parameters: + volumekey: Name of the Volume + force: force stop Gluster Volume + + Returns: + Success: 0 + Failure: 1 + """ + + command = "gluster volume stop" + + volumename = ATFUtils.TestEnvObj.get_volume(volumekey) + if ( volumename == ''): + ATFUtils.Logger.error("Volume %s Not defined in GlobalParam File" % + volumekey) + return 1 + else: + command = command + " " + volumename + " " + force + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + stdin.write("y\n") + return ATFUtils.parse_output(stdout, stderr) + + +def delete_volume(volumekey, **arguments): + """ + Description: + Delete volume specified by volumename + + Parameters: + volumekey: Name of the Volume + + Returns: + Success: 0 + Failure: 1 + """ + + command = "gluster volume delete" + + volumename = ATFUtils.TestEnvObj.get_volume(volumekey) + if ( volumename == ''): + ATFUtils.Logger.error("Volume %s Not defined in GlobalParam File" % + volumekey) + return 1 + else: + command = command + " " + volumename + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + stdin.write("y\n") + return ATFUtils.parse_output(stdout, stderr) + +def create_exportdirs(*exportdirs, **arguments): + """ + Description: + Create Bricks on the Server 'server' + + Parameters: + server: IP Address of Server where bricks has to be created + username: User on Server 'server' + bricks: List of Bricks to be created + + Return: + Success: 0 + Failure: 1 + """ + + command = "mkdir -p" + cleanup_command = "rm -rf" + exportdirlist = [] + + for exportkey in exportdirs: + exportdir = ATFUtils.TestEnvObj.get_exportdir(exportkey) + if (exportdir == '' ): + ATFUtils.Logger.error( + "ExportDir %s Not defined in GlobalParam File" % exportkey) + return 1 + else: + exportdirlist.append(exportdir) + + for exportdir in exportdirlist: + command = command + " " + exportdir + cleanup_command = cleanup_command + " " + exportdir + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(cleanup_command, + **arguments) + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + + + + + + diff --git a/Libraries/GlusterCommands/ATFGlusterd.py b/Libraries/GlusterCommands/ATFGlusterd.py new file mode 100755 index 0000000..fe2a838 --- /dev/null +++ b/Libraries/GlusterCommands/ATFGlusterd.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +import ATFUtils + +def start_glusterd(**arguments): + """ + Objective : + Start Glusterd process on the server + + Parameter : + arguments: key = value pair. + server = 'server(1..n)' + host = 'host(1..n)' + Return: + Success : 0 + Failure : 1 + """ + + command = "/etc/init.d/glusterd start" + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def stop_glusterd(**arguments): + """ + Description: + Stop Glusterd process on the server + + Parameter: + arguments: key = value pair. + server = 'server(1..n)' + host = 'host(1..n)' + + Return: + Success : 0 + Failure : 1 + """ + + command = "/etc/init.d/glusterd stop" + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def restart_glusterd(**arguments): + """ + Description: + Restart Glusterd process on the server + + Parameter: + arguments: key = value pair. + server = 'server(1..n)' + host = 'host(1..n)' + + Return: + Success : 0 + Failure : 1 + """ + + command = "/etc/init.d/glusterd restart" + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def cleanup_glusterd(**arguments): + """ + Description: + Cleans up the glusterd directory on Servers + + Parameter: + arguments: key = value pair. + server = 'server(1..n)' + host = 'host(1..n)' + + Return: + Success : 0 + Failure : 1 + """ + + command = "rm -rf /etc/glusterd/*" + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if (status == 1): + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + + |