summaryrefslogtreecommitdiffstats
path: root/libs/utils
diff options
context:
space:
mode:
authorShwetha-H-Panduranga <shwetha@gluster.com>2012-02-03 15:52:29 +0530
committerShwetha-H-Panduranga <shwetha@gluster.com>2012-02-06 21:08:26 +0530
commit2e06fd3e78331c0352fb9992a7ca3f49f86a2f54 (patch)
treeb61b1b25dca1a35a5acd12906d6d116b0d73498d /libs/utils
parent39329e86b7cc99a5d44e88f53ffc60ac46d2879b (diff)
Changing the return value of all the libraries. The libraries will return a dictionary with 'exitstatus', 'stdoutdata', 'stderrdata' as keys. The value of 'exitstatus' is the exit status of the command execution. The 'stdoutdata' contains data written to the stdout during command execution. The 'stderrdata' contains data written to stderr during command execution.
Change-Id: Ib04062ab34ddf6cf1d8bde07716c4a3be1800ec5 Signed-off-by: Shwetha-H-Panduranga <shwetha@gluster.com>
Diffstat (limited to 'libs/utils')
-rw-r--r--libs/utils/atfutils.py116
-rw-r--r--libs/utils/clientutils.py150
-rw-r--r--libs/utils/glusterutils.py888
-rw-r--r--libs/utils/hostutils.py244
-rw-r--r--libs/utils/serverutils.py42
-rw-r--r--libs/utils/validate.py13
6 files changed, 630 insertions, 823 deletions
diff --git a/libs/utils/atfutils.py b/libs/utils/atfutils.py
index d1c4e0a..1f0d499 100644
--- a/libs/utils/atfutils.py
+++ b/libs/utils/atfutils.py
@@ -6,32 +6,74 @@
*) print_stderr
*) set_active_volume
"""
-
import re
-import ssh
+import inspect
from atfglobals import GlobalObj
+commands = {
+ 'wc' : 'wc',
+ 'ls' : 'ls',
+ 'stat' : 'stat',
+ 'echo' : 'echo',
+ 'cat' : 'cat',
+ 'touch' : 'touch',
+ 'rename': 'mv',
+ 'unlink': 'rm',
+ 'dd' : 'dd',
+ 'chmod' : 'chmod',
+ 'chown' : 'chown',
+ 'mkdir' : 'mkdir -p',
+ 'mkfs' : 'mkfs',
+ 'mount' : 'mount',
+ 'umount' : 'umount',
+ 'hardlink' : 'ln',
+ 'symlink' : 'ln -s',
+ 'setattr' : 'setfattr',
+ 'getattr' : 'getfattr',
+ 'truncate' : 'truncate',
+ 'unlink_force' : 'rm -f',
+ 'unlink_dir_force' : 'rm -rf'
+ }
+
+def get_new_output_obj():
+ output = {}
+ for key in ('exitstatus', 'stdoutdata', 'stderrdata'):
+ output[key] = None
+ return output
+
def assert_success(exit_status):
"""
"""
- if exit_status is None:
+ if exit_status is not 0:
return 1
-
- if not exit_status:
- return 0
else:
- return 1
+ return 0
def assert_failure(exit_status):
"""
"""
- if exit_status is None:
+ if exit_status is 0:
return 1
-
- if exit_status:
- return 0
else:
+ return 0
+
+def assert_success_of_outputs(outputs):
+ """
+ """
+ caller = inspect.stack()[1][3]
+ logger = GlobalObj.getLoggerObj()
+ assert_success_flag = True
+ for key in outputs.keys():
+ output = outputs[key]
+ assert_success_status = assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
+ assert_success_flag = False
+ logger.error("%s Failed to Execute %s") % (key, caller)
+
+ if assert_success_flag is False:
return 1
+ else:
+ return 0
def expect(actual_string, expected_string):
"""
@@ -42,14 +84,14 @@ def expect(actual_string, expected_string):
matched = False
if not expected_string:
matched = True
-
else:
if re.search(new_pattern, actual_string):
matched = True
return matched
-def validate_output(output, expected_exit_status, expected_output, stream="stdout"):
+def validate_output(output, expected_exit_status, expected_output,
+ stream="stdout"):
"""
Parameters:
output: This is dictionary which is return value of
@@ -66,21 +108,38 @@ def validate_output(output, expected_exit_status, expected_output, stream="stdou
False: if output doesn't match with expected_exit_status or
expected_output
"""
- output_status = False
- if expected_exit_status is not 0:
- exit_status = assert_failure(output['exitstatus'])
- else:
- exit_status = assert_success(output['exitstatus'])
+ logger = GlobalObj.getLoggerObj()
+ exit_status_match = False
+ output_data_match = False
- if stream is "stdout":
- output_status = expect(str(output['stdoutdata']),
- expected_output)
+ if None in (output["stdoutdata"], output["stderrdata"]):
+ logger.error("Error in Test Environment")
+ return 1
- elif stream is "stderr":
- output_status = expect(str(output['stderrdata']),
- expected_output)
+ if expected_exit_status is not 0:
+ assert_exit_status = assert_failure(output['exitstatus'])
+ else:
+ assert_exit_status = assert_success(output['exitstatus'])
+ if assert_exit_status is 0:
+ exit_status_match = True
- if output_status is True and (not exit_status):
+ if not expected_output:
+ output_data_match = True
+ else:
+ if stream is "stderr":
+ actual_output = str(output['stderrdata'])
+ else:
+ actual_output = str(output['stdoutdata'])
+ output_data_match = expect(actual_output, expected_output)
+
+ if exit_status_match is False:
+ logger.error("Expected exit status is '%s'.Actual exit status is '%s'" %
+ (expected_exit_status, exit_status))
+ if output_data_match is False:
+ logger.error("Expected ouput is '%s'.Actual output is '%s'" %
+ (expected_output, actual_output))
+
+ if (exit_status_match and output_data_match) is True:
return 0
else:
return 1
@@ -119,10 +178,3 @@ def get_active_volume():
if active_volume is None:
logger.error("Active Volume not set in the TestEnvironment")
return active_volume
-
-__all__ = ['assert_success',
- 'assert_failure',
- 'print-stdout',
- 'print_stderr',
- 'set_active_volume',
- 'get_active_volume']
diff --git a/libs/utils/clientutils.py b/libs/utils/clientutils.py
index 347e159..57810d5 100644
--- a/libs/utils/clientutils.py
+++ b/libs/utils/clientutils.py
@@ -11,6 +11,7 @@ Supported Wrappers :-
import atfutils
import hostutils
+from atfutils import commands
from atfglobals import GlobalObj
def umount(mountkey):
@@ -25,38 +26,28 @@ def umount(mountkey):
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
- base_command = "umount"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. '%s' not defined in TestEnvironment"
% mountkey)
- return 1
+ output["exitstatus"] = 1
+ return output
clientkey = mount_obj.client
- client_connection = cm.getConnection(clientkey)
- if not client_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % clientkey)
- return 1
-
- command = ' '.join([base_command, mount_obj.dir])
- logger.debug('%s: Executing Command: %s' % (clientkey, command))
- output = client_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
+ command = ' '.join([commands['umount'], mount_obj.dir])
+ output = hostutils.execute_command(clientkey, command)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
stdoutdata = str(output["stdoutdata"])
if ((stdoutdata.rfind("not found")) or (stdoutdata.rfind("not mount"))):
- return_status = 0
-
+ output["exitstatus"] = 0
else:
logger.error("Unable to umount %s" % mountkey)
- return return_status
+ return output
def umountall():
"""unmounts all mount specified in testenv.cfg file.
@@ -69,19 +60,19 @@ def umountall():
Success : 0
Failure : 1`
"""
- env = GlobalObj.getTestenvObj()
- failure_flag = False
+ umountall_output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
- return_status = umount(mountkey)
- if return_status:
- failure_flag = True
+ output = umount(mountkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- if failure_flag:
- return 1
- else:
- return 0
+ umountall_output["exitstatus"] = 0
+ umountall_output["stdoutdata"] = "Successful in unmounting all mounts"
+ return umountall_output
def mount(mountkey):
"""mounts a filesystem
@@ -95,48 +86,42 @@ def mount(mountkey):
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
- base_command = "mount"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
- options = []
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. %s not defined in TestEnvironment"
% mountkey)
- return 1
+ output["exitstatus"] = 1
+ return output
- clientkey = mount_obj.client
- client_connection = cm.getConnection(clientkey)
- if not client_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % clientkey)
- return 1
+ #mount command
+ command = [commands['mount']]
- return_status = hostutils.mkdir(clientkey, mount_obj.dir)
- if return_status:
- return return_status
+ #mount type
+ command.extend(["-t", mount_obj.type])
- mountdevice_obj = mount_obj.device
- device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
- options.extend(["-t", mount_obj.type])
- if mount_obj.logfile:
- options.extend(["-o", ("log-file="+mount_obj.logfile),
- "log-level=INFO"])
+ #mount options if specified
if mount_obj.options:
- options.extend([mount_obj.option])
- options.extend([device, mount_obj.dir])
+ command.extend(["-o", mount_obj.options])
- command.extend(options)
+ #mount device
+ mountdevice_obj = mount_obj.device
+ device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
+ command.extend([device, mount_obj.dir])
command = ' '.join(command)
- logger.debug('%s: Executing Command: %s' % (clientkey, command))
- output = client_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ clientkey = mount_obj.client
+ #create mount directory
+ output = hostutils.mkdir(clientkey, mount_obj.dir)
+ assert_success_status = atfutils.assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
+ return output
+
+ #execute mount command
+ output = hostutils.execute_command(clientkey, command)
+ return output
def mountall():
"""mounts a filesystem for all mounts specified in testenv.cfg file.
@@ -148,15 +133,19 @@ def mountall():
Success : 0
Failure : 1`
"""
- env = GlobalObj.getTestenvObj()
+ mountall_output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
- return_status = mount(mountkey)
- if return_status:
- return return_status
+ output = mount(mountkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- return 0
+ mountall_output["exitstatus"] = 0
+ mountall_output["stdoutdata"] = "Successful in mounting all mounts"
+ return mountall_output
def md5sum_of_mount(mountkey):
"""
@@ -167,12 +156,9 @@ def md5sum_of_mount(mountkey):
stdoutdata: stdout data of arequal-checksum command execution
stderrdata: stderr data of arequal-checksum command execution
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
-
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
@@ -210,12 +196,9 @@ def md5sum_of_mounts(mounts):
def execute_on_mount(mountkey, command, commandInput=None):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
-
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
@@ -224,16 +207,19 @@ def execute_on_mount(mountkey, command, commandInput=None):
output["exitstatus"] = 1
return output
-
clientkey = mount_obj.client
mountdir = mount_obj.dir
- command = "cd " + mountdir + " ;" + command
+ command = "cd %s ; %s" % (mountdir , command)
output = hostutils.execute_command(clientkey, command, commandInput)
return output
-__all__ = ['execute_on_mount',
- 'md5sum_of_mounts',
- 'umount',
- 'umountall',
- 'mount',
- 'mountall']
+def execute_on_mounts(mounts, command, commandInput=None):
+ """
+ """
+ all_outputs = {}
+
+ for mountkey in mounts:
+ output = execute_on_mount(mountkey, command, commandInput)
+ all_outputs[mountkey] = output
+
+ return all_outputs
diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py
index 8264f3e..2c21d9b 100644
--- a/libs/utils/glusterutils.py
+++ b/libs/utils/glusterutils.py
@@ -25,200 +25,169 @@ import re
import os
import atfutils
import hostutils
+from atfutils import commands
from atfglobals import GlobalObj
def glusterd_start(serverkey, force=False):
"""
"""
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- commands_to_execute = ["which glusterd", "ps -e | grep glusterd"]
- gluster_version = env.getServer(serverkey).glusterversion
- host_connection = cm.getConnection(serverkey)
- if not host_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % serverkey)
- return 1
+ server_obj = env.getServer(serverkey)
+ if server_obj is None:
+ logger.error("Invalid Server. %s is not defined in TestEnvironment" %
+ serverkey)
+ output["exitstatus"] = 1
+ return output
+ gluster_version = server_obj.glusterversion
""" Check if gluster is already running. If already Running and force=True,
restart glusterd process"""
- command = commands_to_execute.pop()
- output = host_connection.executecommand(command)
+ command = "ps -e | grep glusterd"
+ output = hostutils.execute_command(serverkey, command)
return_status = atfutils.assert_success(output['exitstatus'])
- if not return_status:
+ if return_status is 0:
if force:
- return_status = glusterd_restart(serverkey)
- return return_status
+ output = glusterd_restart(serverkey)
+ return output
else:
- return return_status
-
- command = commands_to_execute.pop()
- output = host_connection.executecommand(command)
- if output["exitstatus"]:
- logger.error("Unable to start glusterd")
- return_status = atfutils.assert_success(output['exitstatus'])
- return return_status
+ return output
+
+ """ Check the glusterd installed PATH"""
+ command = "which glusterd"
+ output = hostutils.execute_command(serverkey, command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status is not 0:
+ logger.error("Unable to find glusterd PATH")
+ return output
else:
if output["stdoutdata"]:
- gluster_path = None
gluster_path = output["stdoutdata"][0].strip("\n")
else:
- logger.error("Unable to find gluster path")
- return_status = atfutils.assert_success(output['exitstatus'])
- return return_status
+ logger.error("Unable to find glusterd PATH")
+ return output
+ """ Get the glusterd version installed in path gluster_path"""
if gluster_path:
command = gluster_path + " --version"
- output = host_connection.executecommand(command)
- if not output["stdoutdata"] == None:
- if re.search(gluster_version, str(output["stdoutdata"])):
- logger.debug('%s: Executing Command: %s'
- %(serverkey, gluster_path))
- output = host_connection.executecommand(gluster_path)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
- else:
- logger.error("Unable to start glusterd")
- return 1
+ output = hostutils.execute_command(serverkey, command)
+ return_status = atfutils.assert_success(output['exitstatus'])
+ if return_status is not 0:
+ logger.error("Unable to get glusterd version")
+ return output
+ else:
+ """ Check if the installed glusted version in path gluster_path
+ matches with gluster_version specified in testenv"""
+ if output["stdoutdata"] is not None:
+ if re.search(gluster_version, str(output["stdoutdata"])):
+ command = gluster_path
+ output = hostutils.execute_command(serverkey, command)
+ return output
+ else:
+ logger.error("Unable to start glusterd")
+ output['exitstatus'] = 1
+ return output
else:
- logger.error("Unable to start glusterd")
- return 1
+ logger.error("Unable to find glusterd PATH")
+ output['exitstatus'] = 1
+ return output
def glusterd_start_allservers(force=False):
"""
"""
+ glusterd_start_output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
all_servers = env.getServers()
for serverkey in all_servers.keys():
- return_status = glusterd_start(serverkey)
- if return_status:
- return return_status
+ output = glusterd_start(serverkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- return 0
+ glusterd_start_output["exitstatus"] = 0
+ glusterd_start_output["stdoutdata"] = "Successful in starting glusterd on all servers"
+ return glusterd_start_output
-def glusterd_stop(serverkey):
+def glusterd_stop(serverkey, signal="SIGTERM"):
"""
"""
- logger = GlobalObj.getLoggerObj()
- base_command = "kill -KILL "
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- host_connection = cm.getConnection(serverkey)
- if not host_connection:
- 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'])
- if not return_status:
- return return_status
-
- else:
- if output["stdoutdata"]:
- for output in output["stdoutdata"]:
- gluster_pid_list.append(output)
-
- for pid in gluster_pid_list:
- command = base_command + pid
- 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'])
- if return_status:
- break
-
- return return_status
+ base_command = "pidof glusterd | xargs --no-run-if-empty kill -s %s"
+ command = base_command % (signal)
+ output = hostutils.execute_command(serverkey, command)
+ return output
-def glusterd_stop_allservers():
+def glusterd_stop_allservers(signal="SIGTERM"):
"""
"""
+ glusterd_stop_output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
all_servers = env.getServers()
for serverkey in all_servers.keys():
- return_status = glusterd_stop(serverkey)
- if return_status:
- return return_status
+ output = glusterd_stop(serverkey, signal)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- return 0
+ glusterd_stop_output["exitstatus"] = 0
+ glusterd_stop_output["stdoutdata"] = "Successful in stoping glusterd on all servers"
+ return glusterd_stop_output
-def glusterd_restart(serverkey):
+def glusterd_restart(serverkey, signal="SIGTERM"):
"""
"""
- return_status = glusterd_stop(serverkey)
- if return_status:
- return return_status
+ output = glusterd_stop(serverkey, signal)
+ if output['exitstatus']:
+ return output
else:
- return_status = glusterd_start(serverkey)
- return return_status
+ output = glusterd_start(serverkey)
+ return output
def glusterd_remove_dir(serverkey):
"""
"""
- logger = GlobalObj.getLoggerObj()
- base_command = "rm -rf"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
glusterd_dir = GlobalObj.glusterd_dir
-
- server_obj = env.getServer(serverkey)
- if not server_obj:
- logger.error("Invalid Host. %s not defined in TestEnvironment"
- % serverkey)
- return 1
-
- server_connection = cm.getConnection(serverkey)
- if not server_connection:
- 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)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return 0
+ command = ' '.join([commands['unlink_dir_force'], glusterd_dir])
+ output = hostutils.execute_command(serverkey, command)
+ return output
def glusterd_remove_dir_allservers():
"""
"""
+ glusterd_remove_dir_output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
all_servers = env.getServers()
for serverkey in all_servers.keys():
- return_status = glusterd_remove_dir(serverkey)
-
- return 0
+ output = glusterd_remove_dir(serverkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+ glusterd_remove_dir_output["exitstatus"] = 0
+ glusterd_remove_dir_output["stdoutdata"] = "Successful in removing glusterd dir on all servers"
+ return glusterd_remove_dir_output
def glusterd_remove_logs(serverkey):
"""
"""
logger = GlobalObj.getLoggerObj()
- base_command = "rm -rf"
+ output = atfutils.get_new_output_obj()
+
log_paths = GlobalObj.glusterd_log_paths
absolute_path_list = []
prefix_path = ''
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
+ env = GlobalObj.getTestenvObj()
server_obj = env.getServer(serverkey)
- if not server_obj:
+ if server_obj is None:
logger.error("Invalid Host. %s not defined in TestEnvironment"
% serverkey)
- return 1
-
- server_connection = cm.getConnection(serverkey)
- if not server_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % serverkey)
- return 1
+ output['exitstatus'] = 1
+ return output
if server_obj.installpath:
prefix_path = server_obj.installpath
@@ -226,67 +195,68 @@ def glusterd_remove_logs(serverkey):
for path in log_paths:
absolute_path_list.append(prefix_path + path)
- for path in absolute_path_list:
- command = ' '.join([base_command, path])
- logger.debug('%s: Executing Command: %s' % (serverkey, command))
- output = server_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- return 0
+ command = [commands['unlink_dir_force']]
+ command.extend(absolute_path_list)
+ command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command)
+ return output
def glusterd_remove_logs_allservers():
"""
"""
+ glusterd_remove_logs_output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
all_servers = env.getServers()
for serverkey in all_servers.keys():
- return_status = glusterd_remove_logs(serverkey)
+ output = glusterd_remove_logs(serverkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- return 0
+ glusterd_remove_logs_output["exitstatus"] = 0
+ glusterd_remove_logs_output["stdoutdata"] = "Successful in removing glusterd logs on all servers"
+ return glusterd_remove_logs_output
def volume_delete(serverkey):
"""
"""
+ base_command = "gluster volume delete"
logger = GlobalObj.getLoggerObj()
- base_command = "gluster volume delete "
- command = [base_command]
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("Invalid Volume.ActiveVolume not defined" +
"for the TestEnvironment")
- return 1
- 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"
- % serverkey)
- return 1
+ output['exitstatus'] = 1
+ return output
+ volumename = active_volume.volumename
- logger.debug('%s: Executing Command: %s' % (serverkey, command))
- output = host_connection.executecommand(command, commandInput="y\n")
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ command = [base_command]
+ command.extend([volumename])
+ command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
def volume_create(serverkey):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume create"
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
- command.extend([active_volume.volumename])
+ output['exitstatus'] = 1
+ return output
+ volumename = active_volume.volumename
+
+ command = [base_command]
+ command.extend([volumename])
if active_volume.replica:
command.extend(["replica", active_volume.replica])
@@ -298,113 +268,98 @@ def volume_create(serverkey):
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"
- % 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 return_status:
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
if str(output["stdoutdata"]).rfind("already exists"):
- return_status = 0
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output = volume_stop(serverkey, force=True)
+ output = volume_delete(serverkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+ else:
+ output = hostutils.execute_command(serverkey, command,
+ commandInput="y\n")
+ return output
+ else:
+ return output
def volume_start(serverkey, force=False):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume start"
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
- command.extend([active_volume.volumename])
+ output['exitstatus'] = 1
+ return output
+ volumename = active_volume.volumename
+ command = [base_command]
+ command.extend([volumename])
if 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"
- % 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 return_status:
+ command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
if str(output["stdoutdata"]).rfind("already started"):
- return_status = 0
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output['exitstatus'] = 0
+ return output
def volume_stop(serverkey, force=False):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume stop"
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
- command.extend([active_volume.volumename])
+ output['exitstatus'] = 1
+ return output
+ volumename = active_volume.volumename
+ command = [base_command]
+ command.extend([volumename])
if 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"
- % 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'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
def volume_addbrick(serverkey, *bricks, **arguments):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume add-brick"
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
- command = [base_command]
-
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+ command = [base_command]
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']])
@@ -412,26 +367,20 @@ def volume_addbrick(serverkey, *bricks, **arguments):
brick_obj = env.getBrick(brick)
if not brick_obj:
logger.error("Invalid Brick. Brick Not defined in TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
brick_value = brick_obj.hostname + ":" + brick_obj.path
command.extend([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, commandInput="y\n")
- return_status = atfutils.assert_success(output['exitstatus'])
- if not return_status:
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is 0:
if env.addBricksToVolume(*bricks):
- return 1
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output['exitstatus'] = 1
+ return output
+
+ return output
def volume_removebrick(serverkey, *bricks, **arguments):
"""
@@ -442,17 +391,20 @@ def volume_removebrick(serverkey, *bricks, **arguments):
brick_type: [replica <COUNT>]
operation:{start|pause|abort|status|commit|force}
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume remove-brick"
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
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])
+ output['exitstatus'] = 1
+ return output
+ volumename = active_volume.volumename
+
+ command = [base_command]
+ command.extend([volumename])
"""
brick_type can have only [replica <COUNT>]
"""
@@ -463,48 +415,42 @@ def volume_removebrick(serverkey, *bricks, **arguments):
brick_obj = env.getBrick(brick)
if not brick_obj:
logger.error("Invalid Brick. Brick not defined in TestEnviroment")
- return 1
+ output['exitstatus'] = 1
+ return output
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:
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is 0:
if env.removeBricksFromVolume(*bricks):
- return 1
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output['exitstatus'] = 1
+ return output
+
+ return output
def volume_replacebrick(serverkey, replace_brick, to_brick, operation):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume replace-brick"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+
replace_brick_obj = env.getBrick(replace_brick)
to_brick_obj = env.getBrick(to_brick)
"""
@@ -512,158 +458,116 @@ def volume_replacebrick(serverkey, replace_brick, to_brick, operation):
"""
if not (replace_brick_obj and to_brick_obj):
logger.error("Invalid Brick. Brick Not defined in TestEnvironment")
- return 1
-
- replace_brick_value = replace_brick_obj.hostname+':'+replace_brick_obj.path
- to_brick_value = to_brick_obj.hostname+':'+to_brick_obj.path
-
+ output['exitstatus'] = 1
+ return output
+ replace_brick_value = replace_brick_obj.hostname + ':' + replace_brick_obj.path
+ to_brick_value = to_brick_obj.hostname + ':' + to_brick_obj.path
+ command = [base_command]
command.extend([volumename, replace_brick_value, to_brick_value, 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
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if ((assert_success_status is 0) and (operation == "commit")):
+ if env.replaceBrickInVolume(replace_brick, to_brick):
+ output['exitstatus'] = 1
+ return output
- 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) and (operation == "commit"):
- if env.replaceBrickInVolume(brick, newbrick):
- return 1
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ return output
def volume_set(serverkey, key, value):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume set"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+ command = [base_command]
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"
- % 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'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
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]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the Testenvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
brick_obj = env.getBrick(brick)
if not brick_obj:
logger.error("Invalid Brick. Brick Not defined in TestEnvironment")
- return 1
-
+ output['exitstatus'] = 1
+ return output
brick_value = brick_obj.hostname + ":" + brick_obj.path
+ command = [base_command]
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
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
def volume_reset(serverkey):
"""
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume reset "
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
- command = base_command + volumename
- 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'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ command = [base_command]
+ command.extend([volumename])
+ command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
def volume_profile(serverkey, operation):
"""
operation:{start|info|stop}
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume profile"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defined for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+ command = [base_command]
command.extend([volumename, operation])
command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
- 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):
"""
@@ -673,17 +577,19 @@ def volume_quota(serverkey, operation, **arguments):
value: value can be in GB or MB
ex: value=1GB
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume quota"
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
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
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+ command = [base_command]
command.extend([volumename, operation])
if arguments.has_key('path'):
@@ -693,19 +599,9 @@ def volume_quota(serverkey, operation, **arguments):
command.extend([arguments['value']])
command = ' '.join(command)
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
- 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: 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):
"""
@@ -716,25 +612,27 @@ def volume_top(serverkey, operation, **arguments):
list-cnt: can take any number
"""
- logger = GlobalObj.getLoggerObj()
base_command = "gluster volume top"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
active_volume = env.getActiveVolume()
if not active_volume:
logger.error("ActiveVolume not defines for the TestEnvironment")
- return 1
+ output['exitstatus'] = 1
+ return output
volumename = active_volume.volumename
+ command = [base_command]
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
+ output['exitstatus'] = 1
+ return output
brick_value = brick_obj.hostname+':'+brick_obj.path
command.extend(['brick',brick_value])
@@ -742,43 +640,26 @@ def volume_top(serverkey, operation, **arguments):
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
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
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()
+ output = atfutils.get_new_output_obj()
- """Get the active volume
- """
- active_volume = atfutils.get_active_volume()
- if active_volume is None:
+ env = GlobalObj.getTestenvObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ logger.error("ActiveVolume not defines for the TestEnvironment")
output['exitstatus'] = 1
return output
volumename = active_volume.volumename
@@ -792,12 +673,6 @@ def volume_stop_brick(brickkey, signal="SIGTERM"):
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
"""
@@ -816,62 +691,55 @@ def volume_stop_brick(brickkey, signal="SIGTERM"):
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'])
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
return output
-def peer_probe(fromserverkey):
+def peer_probe(from_serverkey):
"""
"""
- logger = GlobalObj.getLoggerObj()
- base_command = "gluster peer probe "
- all_servers = {}
+ base_command = "gluster peer probe"
+ peer_probe_output = atfutils.get_new_output_obj()
+
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]
+ all_servers.pop(from_serverkey)
+ for serverkey in all_servers.keys():
+ if not serverkey is from_serverkey:
+ server_obj = all_servers[serverkey]
"""
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'])
+ output = hostutils.execute_command(from_serverkey, command,
+ commandInput="y\n")
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- if return_status:
- return 1
-
- return 0
+ peer_probe_output["exitstatus"] = 0
+ peer_probe_output["stdoutdata"] = "Peer Probe Successful for all servers"
+ return peer_probe_output
def create_brick(brickkey):
"""
"""
logger = GlobalObj.getLoggerObj()
- return_status = 1
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
brick_obj = env.getRawBrick(brickkey)
-
+ if not brick_obj:
+ logger.error("Invalid brick. Brick not defined in Testenvironment")
+ output['exitstatus'] = 1
+ return output
hostname_value = brick_obj.hostname
serverkey = re.split("\.", hostname_value, maxsplit=1)[0]
-
exportdir = brick_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:
@@ -881,118 +749,58 @@ def create_brick(brickkey):
fstype = export_obj.fstype
options = export_obj.options
- logger.debug('%s: Executing Command: %s'% (serverkey, 'create_brick'))
- if device:
- if umount_device(serverkey, device):
- return return_status
- if hostutils.mkfs(serverkey, device, fstype):
- return return_status
- if mount_exportdir(serverkey, device, fstype, options, dirpath):
- return return_status
- return 0
-
- else:
- if hostutils.rmdir(serverkey, dirpath):
- return return_status
- if hostutils.mkdir(serverkey, dirpath):
- return return_status
-
- return 0
-
-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:
- command = base_command + mountpoint
- logger.debug('%s: Executing Command: %s' % (serverkey, command))
- output = server_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
- stdoutdata = str(output["stdoutdata"])
- if ((stdoutdata.rfind("not found")) or (stdoutdata.rfind("not mount"))):
- return_status = 0
-
- else:
- return return_status
-
- return 0
-
-def mount_exportdir(serverkey, device, fstype, options, dirpath):
- """
- """
- logger = GlobalObj.getLoggerObj()
- 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"
+ server_obj = env.getServer(serverkey)
+ if server_obj is None:
+ logger.error("Invalid Host. %s not defined in TestEnvironment"
% serverkey)
- return 1
-
- if fstype is None:
- fstype = "xfs"
- command.extend(["-t", fstype])
-
- if options:
- command.extend([options])
-
- command.extend([device, dirpath])
- command = ' '.join(command)
+ output['exitstatus'] = 1
+ return output
+ server_hostname = server_obj.hostname
- logger.debug('%s: Executing Command: %s' % (serverkey, command))
- output = server_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ logger.debug('%s: Executing Command: %s' %(server_hostname, 'create_brick'))
+ 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 Brick %s" % brickkey
+ return output
def create_brick_allservers():
"""
"""
+ create_brick_output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
brick_keys = env.getBrickKeys()
for brickkey in brick_keys:
- return_status = create_brick(brickkey)
- if return_status:
- return return_status
-
- return 0
-
-
-__all__ = ['glusterd_start',
- 'glusterd_start_allservers',
- 'glusterd_stop',
- 'glusterd_stop_allservers',
- 'glusterd_restart',
- 'glusterd_remove_dir',
- 'glusterd_remove_dir_allservers',
- 'glusterd_remove_logs_allservers',
- 'volume_delete',
- 'volume_create',
- 'volume_start',
- 'volume_stop',
- 'volume_addbrick',
- 'volume_replacebrick',
- 'volume_set',
- 'volume_reset',
- 'peer_probe',
- 'create_brick',
- 'create_brick_allservers',
- 'mount_exportdir',
- 'umount_device']
+ output = create_brick(brickkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ create_brick_output["exitstatus"] = 0
+ create_brick_output["stdoutdata"] = "Successful in creating bricks on all servers"
+ return create_brick_output
diff --git a/libs/utils/hostutils.py b/libs/utils/hostutils.py
index c7ac7f2..3955cc6 100644
--- a/libs/utils/hostutils.py
+++ b/libs/utils/hostutils.py
@@ -10,141 +10,134 @@ Supported Wrappers:
"""
import re
-from collections import namedtuple
+import os
import atfutils
+from collections import namedtuple
from atfglobals import GlobalObj
-import os
+from atfutils import commands
system_dirs = re.compile('(/bin|/boot|/dev|/etc|/lib|/mnt|/net|/opt|/root|/sbin|/usr|/var|/sys)\/?$')
-def cd(hostkey, dirpath):
- """
- """
- logger = GlobalObj.getLoggerObj()
- base_command = "cd"
- cm = GlobalObj.getConnectionsManagerObj()
- host_connection = cm.getConnection(hostkey)
- 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
-
def rmdir(hostkey, dirpath):
"""
"""
logger = GlobalObj.getLoggerObj()
- base_command = "rm -rf"
- cm = GlobalObj.getConnectionsManagerObj()
+ output = atfutils.get_new_output_obj()
+
if system_dirs.match(dirpath):
logger.error("System Directiories cannot be deleted")
- return 1
-
- else:
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH Connection Not established to host '%s' "
- % hostkey)
- return 1
+ output["exitstatus"] = 1
+ return output
- 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
+ command = ' '.join([commands['unlink_dir_force'], dirpath])
+ output = execute_command(hostkey, command)
+ return output
def mkdir(hostkey, dirpath):
"""
"""
logger = GlobalObj.getLoggerObj()
- base_command = "mkdir -p"
- cm = GlobalObj.getConnectionsManagerObj()
+ output = atfutils.get_new_output_obj()
if system_dirs.match(dirpath):
logger.error("System Directiories cannot be created")
- return 1
-
- else:
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH Connection Not established to host '%s' "
- % hostkey)
- return 1
+ output["exitstatus"] = 1
+ return output
- 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
+ command = ' '.join([commands['mkdir'], dirpath])
+ output = execute_command(hostkey, command)
+ return output
-def mkfs(hostkey, device, fstype=None):
+def mkfs(hostkey, device, fstype, options=None):
"""
"""
- logger = GlobalObj.getLoggerObj()
- base_command = "mkfs"
- cm = GlobalObj.getConnectionsManagerObj()
- host_connection = cm.getConnection(hostkey)
- command = [base_command]
- options = []
+ command = [commands['mkfs']]
- if not host_connection:
- logger.error("SSH Connection Not established to host '%s' " % hostkey)
- return 1
+ # mkfs type
+ if fstype is None:
+ fstype = "xfs"
+ command.extend(["-t", fstype])
+
+ # mkfs options if specified
+ if options is not None:
+ command.extend(["-o", options])
+
+ # mkfs device
+ command.extend(["-f", device])
+ command = ' '.join(command)
+ output = execute_command(hostkey, command)
+ return output
+def mount(hostkey, device, fstype, mountpoint, options=None):
+ """
+ """
+ command = [commands['mount']]
+
+ # mount type
if fstype is None:
fstype = "xfs"
+ command.extend(["-t", fstype])
- options.extend(["-t", fstype, "-f", device])
+ # mount options
+ if options is not None:
+ command.extend(["-o", options])
- command.extend(options)
+ # mount device, mountpoint
+ command.extend([device, mountpoint])
command = ' '.join(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'])
- return return_status
+ output = execute_command(hostkey, command)
+ return output
-def md5sum(hostkey, path):
+def umount(hostkey, mountpoint):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
+ command = ' '.join([commands['umount'], mountpoint])
+ output = execute_command(hostkey, command)
+ return output
- base_command1 = "rm -rf"
- base_command2 = "arequal-checksum"
- landfill_dir = os.path.join(path, ".landfill")
+def umount_device(hostkey, device):
+ """
+ """
+ all_outputs = {}
+ umount_device_output = atfutils.get_new_output_obj()
- cm = GlobalObj.getConnectionsManagerObj()
- host_connection = cm.getConnection(hostkey)
- if not host_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % hostkey)
- output["exitstatus"] = 1
+ output = find_mountpoints(hostkey, device)
+ assert_success_status = atfutils.assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
return output
+ else:
+ mountpoints = output["stdoutdata"]
+
+ for mountpoint in mountpoints:
+ output = umount(hostkey, mountpoint)
+ assert_success_status = atfutils.assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
+ stdoutdata = str(output["stdoutdata"])
+ if ((stdoutdata.rfind("not found")) or
+ (stdoutdata.rfind("not mount"))):
+ output["exitstatus"] = 0
+ all_outputs[mountpoint] = output
+
+ assert_success_status = atfutils.assert_success_of_outputs(all_outputs)
+ if assert_success_status is not 0:
+ umount_device_output["exitstatus"] = 1
+ umount_device_output["stderrdata"] = "Unable to unmount device %s" % (device)
+ else:
+ umount_device_output["exitstatus"] = 0
+ umount_device_output["stdoutdata"] = "Successfully able to unmount device %s" % (device)
- command1 = ' '.join([base_command1, landfill_dir])
- command2 = ' '.join([base_command2, path])
- command = ';'.join([command1, command2])
- output = host_connection.executecommand(command)
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
+ return umount_device_output
+def md5sum(hostkey, path):
+ """
+ """
+ base_command = "rm -rf %s ; arequal-checksum %s"
+ landfill_dir = os.path.join(path, ".landfill")
+
+ command = base_command % (landfill_dir, path)
+ output = execute_command(hostkey, command)
if output['stdoutdata'] is None or (not output['stdoutdata']):
output['stdoutdata'] = ""
-
else:
output['stdoutdata'] = str(output['stdoutdata'])
@@ -153,34 +146,26 @@ def md5sum(hostkey, path):
def find_mountpoints(hostkey, device):
"""
"""
- logger = GlobalObj.getLoggerObj()
- 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"
- % hostkey)
- return 1
-
+ base_command = "mount | grep"
mountpoints = []
- command = base_command + device
- logger.debug('%s: Executing Command: %s' % (hostkey, command))
- output = host_connection.executecommand(command)
- if not output["exitstatus"]:
- for data in output["stdoutdata"]:
- mountpoints.append(data.split(" ")[2])
- return mountpoints
+ command = ' '.join([base_command, device])
+ output = execute_command(hostkey, command)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is 0:
+ if output["stdoutdata"]:
+ for data in output["stdoutdata"]:
+ mountpoints.append(data.split(" ")[2])
+ output["stdoutdata"] = mountpoints
+ return output
def execute_command(hostkey, command, commandInput=None):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+ new_command = _substitute_value_for_variables(command)
+
cm = GlobalObj.getConnectionsManagerObj()
host_connection = cm.getConnection(hostkey)
if not host_connection:
@@ -188,16 +173,22 @@ def execute_command(hostkey, command, commandInput=None):
% hostkey)
output["exitstatus"] = 1
return output
- new_command = _substitute_value_for_variables(command)
- logger.debug('%s: Executing Command: %s' % (hostkey, command))
+ env = GlobalObj.getTestenvObj()
+ host_obj = env.getHost(hostkey)
+ if host_obj is None:
+ logger.error("Invalid Host. %s is not defined in TestEnvironment" %
+ hostkey)
+ output["exitstatus"] = 1
+ return output
+
+ hostname = host_obj.hostname
+ logger.debug('%s: Executing Command: %s' % (hostname, command))
output = host_connection.executecommand(new_command, commandInput)
atfutils.print_stdout(output['stdoutdata'])
atfutils.print_stderr(output['stderrdata'])
return output
-
-
def _substitute_value_for_variables(command):
"""
"""
@@ -600,18 +591,3 @@ def gluster_install_rpm(version, *components):
return 1
return 0
-
-
-
-
-
-__all__ = ['cd',
- 'rmdir',
- 'mkdir',
- 'mkfs',
- 'md5sum',
- 'find_mountpoints',
- 'execute_command',
- 'gluster_install_tar',
- 'gluster_install_git',
- 'gluster_install_rpm']
diff --git a/libs/utils/serverutils.py b/libs/utils/serverutils.py
index 10fe830..0cecee0 100644
--- a/libs/utils/serverutils.py
+++ b/libs/utils/serverutils.py
@@ -1,9 +1,9 @@
"""serverutils module
"""
import re
+import atfutils
import hostutils
from atfglobals import GlobalObj
-import atfutils
def md5sum_of_brick(brickkey):
"""
@@ -14,11 +14,8 @@ def md5sum_of_brick(brickkey):
stdoutdata: stdout data of arequal-checksum command execution
stderrdata: stderr data of arequal-checksum command execution
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
raw_brick_obj = env.getRawBrick(brickkey)
@@ -27,7 +24,6 @@ def md5sum_of_brick(brickkey):
brickkey)
output["exitstatus"] = 1
return output
-
else:
serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
@@ -67,20 +63,11 @@ def md5sum_of_bricks(bricks):
def get_gfid_on_brick(brickkey, filename="."):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
base_command = "getfattr -n 'trusted.gfid' -e hex"
command = ' '.join([base_command, filename])
output = execute_on_brick(brickkey, command)
- if atfutils.assert_success(output['exitstatus']):
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
-
- elif output['stdoutdata'] is None or (not output['stdoutdata']):
+ if output['stdoutdata'] is None or (not output['stdoutdata']):
output['stdoutdata'] = ""
-
else:
output['stdoutdata'] = str(output['stdoutdata'])
@@ -99,12 +86,8 @@ def get_gfid_on_bricks(bricks, filename="."):
def execute_on_brick(brickkey, command, commandInput=None):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
-
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
raw_brick_obj = env.getRawBrick(brickkey)
@@ -125,9 +108,20 @@ def execute_on_brick(brickkey, command, commandInput=None):
else:
exportdirpath = brick_obj.path
- command = "cd " + exportdirpath + ";" + command
+ command = "cd %s ; %s" % (exportdirpath , command)
output = hostutils.execute_command(serverkey, command, commandInput)
return output
-__all__ = ['execute_on_brick',
- 'md5sum_of_bricks']
+def execute_on_bricks(bricks, command, commandInput=None):
+ """
+ Parameters:
+ bricks: List of bricks (Ex: [brick1, brick2, brick3, ...])
+ command: Command to execute on brick
+ """
+ all_outputs = {}
+
+ for brickkey in bricks:
+ output = execute_on_brick(brickkey, command, commandInput)
+ all_outputs[brickkey] = output
+
+ return all_outputs
diff --git a/libs/utils/validate.py b/libs/utils/validate.py
index 2cdfa45..fd8504d 100644
--- a/libs/utils/validate.py
+++ b/libs/utils/validate.py
@@ -5,15 +5,6 @@ import clientutils
from atfglobals import GlobalObj
import re
-def assert_success_of_outputs(outputs):
- """
- """
- for key in outputs.keys():
- output = outputs[key]
- if atfutils.assert_success(output["exitstatus"]):
- return 1
- return 0
-
def match_md5sum(sum1, sum2):
"""
Parameters:
@@ -112,7 +103,7 @@ def validate_md5sums(mounts, bricks):
md5sums = mounts_md5sums
md5sums.update(bricks_md5sums)
- assert_success_status = assert_success_of_outputs(md5sums)
+ assert_success_status = atfutils.assert_success_of_outputs(md5sums)
if assert_success_status is not 0:
return assert_success_status
@@ -127,7 +118,7 @@ def validate_gfids(bricks, filename="."):
"""
gfid_on_bricks = serverutils.get_gfid_on_bricks(bricks, filename)
- assert_success_status = assert_success_of_outputs(gfid_on_bricks)
+ assert_success_status = atfutils.assert_success_of_outputs(gfid_on_bricks)
if assert_success_status is not 0:
return assert_success_status