summaryrefslogtreecommitdiffstats
path: root/SharedModules/Utils
diff options
context:
space:
mode:
authorShwetha-H-Panduranga <shwetha@gluster.com>2011-12-06 14:26:59 +0530
committerShwetha-H-Panduranga <shwetha@gluster.com>2011-12-06 14:26:59 +0530
commit77c7f324610224e808d8940aec7e6dbf19b790a5 (patch)
tree4d5b3abe8e8220b058f9828822b527b2d6331702 /SharedModules/Utils
parent129e39fe6878f28ca203c690fab382b7289b334c (diff)
Adding New/Updated Automation Files
Diffstat (limited to 'SharedModules/Utils')
-rw-r--r--SharedModules/Utils/atfutils.py58
-rw-r--r--SharedModules/Utils/clientutils.py282
-rw-r--r--SharedModules/Utils/glusterutils.py644
-rw-r--r--SharedModules/Utils/hostutils.py193
-rw-r--r--SharedModules/Utils/managerutils.py55
-rw-r--r--SharedModules/Utils/serverutils.py33
6 files changed, 1265 insertions, 0 deletions
diff --git a/SharedModules/Utils/atfutils.py b/SharedModules/Utils/atfutils.py
new file mode 100644
index 0000000..980c286
--- /dev/null
+++ b/SharedModules/Utils/atfutils.py
@@ -0,0 +1,58 @@
+"""atfutils module contains general purpose wrappers
+
+*) assert_success
+*) assert_failure
+*) print-stdout
+*) print_stderr
+*) set_active_volume
+"""
+
+import re
+import ssh
+from atfglobals import GlobalObj
+
+def assert_success(**arguments):
+ """
+ """
+ if not arguments["exitstatus"]:
+ return 0
+ else:
+ return 1
+
+def assert_failure(**arguments):
+ """
+ """
+ if arguments["exitstatus"]:
+ return 0
+ else:
+ return 1
+
+def print_stdout(stdoutdata):
+ """
+ """
+ if not stdoutdata == None:
+ for data in stdoutdata:
+ print data
+
+def print_stderr(stderrdata):
+ if not stderrdata == None:
+ for data in stderrdata:
+ print data
+
+def set_active_volume(volumekey):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ return_status = env.setActiveVolume(volumekey)
+ if return_status:
+ print "Unable to set Active Volume. '%s' Not defined in TestEnvironment"\
+ % volumekey
+ return return_status
+
+
+
+__all__ = ['assert_success',
+ 'assert_failure',
+ 'print-stdout',
+ 'print_stderr',
+ 'set_active_volume']
diff --git a/SharedModules/Utils/clientutils.py b/SharedModules/Utils/clientutils.py
new file mode 100644
index 0000000..ad5d593
--- /dev/null
+++ b/SharedModules/Utils/clientutils.py
@@ -0,0 +1,282 @@
+"""clientutils module contains functions required for performing
+certain operations on client
+
+Supported Wrappers :-
+-----------
+*) umount
+*) umountall
+*) mount
+*) mountall
+"""
+
+import atfutils
+import hostutils
+from atfglobals import GlobalObj
+
+def umount(mountkey):
+ """unmounts a mountpoint
+
+ Parameters:
+ mountkey : name given to a mount as specified in testenv.cfg file.
+ Ex:-"mount1"
+
+ Returns:
+ Success : 0
+ Failure : 1`
+ """
+ base_command = "umount "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ mount_obj = env.getMount(mountkey)
+ if not mount_obj:
+ print "InValid Mount. %s not defined in TestEnvironment" % mountkey
+ return 1
+
+ clientkey = mount_obj.client
+ client_connection = cm.getConnection(clientkey)
+ if not client_connection:
+ print "SSH connection to host '%s' has not been established" % clientkey
+ return 1
+
+ command = base_command + mount_obj.dir
+ print "%s : %s" % (clientkey, command)
+ output = client_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ 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:
+ print "Unable to umount %s" % mountkey
+
+ return return_status
+
+def umountall():
+ """unmounts all mount specified in testenv.cfg file.
+ Ex:- mount1, mount2 etc
+
+ Parameters:
+ None
+
+ Returns:
+ Success : 0
+ Failure : 1`
+ """
+ env = GlobalObj.getTestenvObj()
+ failure_flag = False
+
+ mounts_keys = env.getMountsKeys()
+ for mountkey in mounts_keys:
+ return_status = umount(mountkey)
+ if return_status:
+ failure_flag = True
+
+ if failure_flag:
+ return 1
+ else:
+ return 0
+
+def mount(mountkey):
+ """mounts a filesystem
+
+ Parameters:
+ mountkey : name given to a mount as specified in testenv.cfg file.
+ Ex:-"mount1"
+
+ Returns:
+ Success : 0
+ Failure : 1`
+ """
+
+ base_command = command = "mount "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ mount_obj = env.getMount(mountkey)
+ if not mount_obj:
+ print "InValid Mount. %s not defined in TestEnvironment" % mountkey
+ return 1
+
+ clientkey = mount_obj.client
+ client_connection = cm.getConnection(clientkey)
+ if not client_connection:
+ print "SSH connection to host '%s' has not been established" % clientkey
+ return 1
+
+ mountdevice_obj = mount_obj.device
+ device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
+ options = ["-t", mount_obj.type]
+ if mount_obj.logfile:
+ options.extend(["-o", ("log-file="+mount_obj.logfile),
+ "log-level=INFO"])
+
+ if mount_obj.options:
+ options.extend([mount_obj.option])
+
+ options.extend([device, mount_obj.dir])
+ for index, option in enumerate(options):
+ command = command + option + " "
+
+ return_status = hostutils.mkdir(clientkey, mount_obj.dir)
+ if return_status:
+ return return_status
+
+ print "%s : %s" % (clientkey, command)
+ output = client_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def mountall():
+ """mounts a filesystem for all mounts specified in testenv.cfg file.
+
+ Parameters:
+ None
+
+ Returns:
+ Success : 0
+ Failure : 1`
+ """
+ env = GlobalObj.getTestenvObj()
+
+ mounts_keys = env.getMountsKeys()
+ for mountkey in mounts_keys:
+ return_status = mount(mountkey)
+ if return_status:
+ return return_status
+
+ return 0
+
+
+def execute_on_mount(mountkey, command, commandInput=None):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ mount_obj = env.getMount(mountkey)
+ if not mount_obj:
+ print "InValid Mount. %s not defined in TestEnvironment" % mountkey
+ return 1
+
+ clientkey = mount_obj.client
+ mountdir = mount_obj.dir
+ command = "cd " + mountdir + " ;" + command
+ return_status = hostutils.execute_command(clientkey, command, commandInput)
+ return return_status
+
+__all__ = ['execute_on_mount',
+ 'umount',
+ 'umountall',
+ 'mount',
+ 'mountall']
+
+##def umountall(clientkey):
+## """
+## """
+## base_command = "umount "
+## env = GlobalObj.get_testenv_obj()
+## cm = GlobalObj.get_connectionsmanager_obj()
+## client_obj = env.getclient(clientkey)
+## mountdir = client_obj.mountdir
+## volume = client_obj.device
+## client = cm.getconnection(clientkey)
+##
+## mountpoints = []
+## success_flag = False
+## failure_flag = False
+## command = "mount | grep " + mountdir
+## output = client.executecommand(command)
+## if not output["exitstatus"]:
+## for data in output["stdoutdata"]:
+## mountpoints.append(data.split(" ")[2])
+##
+## for mountpoint in mountpoints:
+## command = base_command + mountpoint
+## output = client.executecommand(command)
+## return_code = utils.assert_success(**output)
+## if return_code:
+## failure_flag = True
+## else:
+## success_flag = True
+## continue
+##
+## if failure_flag:
+## return 1
+##
+## mountpoints = []
+## success_flag = False
+## failure_flag = False
+## command = "mount | grep " + volume
+## output = client.executecommand(command)
+## if not output["exitstatus"]:
+## for data in output["stdoutdata"]:
+## mountpoints.append(data.split(" ")[2])
+##
+## for mountpoint in mountpoints:
+## command = base_command + mountpoint
+## output = client.executecommand(command)
+## return_code = utils.assert_success(**output)
+## if return_code:
+## failure_flag = True
+## else:
+## success_flag = True
+## continue
+##
+## if failure_flag:
+## return 1
+##
+## return 0
+
+##def cd_mount(mountkey):
+## """
+## """
+## env = GlobalObj.getTestenvObj()
+## mount_obj = env.getMount(mountkey)
+## if not mount_obj:
+## print "InValid Mount. %s not defined in TestEnvironment" % mountkey
+## return 1
+##
+## clientkey = mount_obj.client
+## dirpath = mount_obj.dir
+## return_status = hostutils.cd(clientkey, dirpath)
+## return return_status
+##
+##def cd_allmounts():
+## """
+## """
+## env = GlobalObj.getTestenvObj()
+## mounts_keys = env.getMountsKeys()
+## for mountkey in mounts_keys:
+## return_status = cd_mount(mountkey)
+## if return_status:
+## return return_status
+##
+## return 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SharedModules/Utils/glusterutils.py b/SharedModules/Utils/glusterutils.py
new file mode 100644
index 0000000..0c15af1
--- /dev/null
+++ b/SharedModules/Utils/glusterutils.py
@@ -0,0 +1,644 @@
+"""glusterutils module contains wrappers for gluster commands.
+
+*) 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
+*) mount_exportdir
+*) umount_exportdir
+"""
+
+import re
+import atfutils
+import hostutils
+from atfglobals import GlobalObj
+
+
+def glusterd_start(serverkey, force=False):
+ """
+ """
+ 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:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ """ 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)
+ return_status = atfutils.assert_success(**output)
+ if not return_status:
+ if force:
+ return_status = glusterd_restart(serverkey)
+ return return_status
+ else:
+ return return_status
+
+ command = commands_to_execute.pop()
+ output = host_connection.executecommand(command)
+ if output["exitstatus"]:
+ print "Unable to start glusterd"
+ return_status = atfutils.assert_success(**output)
+ return return_status
+ else:
+ if output["stdoutdata"]:
+ gluster_path = None
+ gluster_path = output["stdoutdata"][0].strip("\n")
+ else:
+ print "Unable to find gluster path"
+ return_status = atfutils.assert_success(**output)
+ return return_status
+
+ 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"])):
+ print "%s : %s" % (serverkey, gluster_path)
+ output = host_connection.executecommand(gluster_path)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+ else:
+ print "Unable to start glusterd"
+ return 1
+ else:
+ print "Unable to start glusterd"
+ return 1
+
+def glusterd_start_allservers(force=False):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ all_servers = env.getServers()
+ for serverkey in all_servers.keys():
+ return_status = glusterd_start(serverkey)
+ if return_status:
+ return return_status
+
+ return 0
+
+def glusterd_stop(serverkey):
+ """
+ """
+ base_command = "kill -KILL "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "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)
+ 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
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ if return_status:
+ break
+
+ return return_status
+
+def glusterd_stop_allservers():
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ all_servers = env.getServers()
+ for serverkey in all_servers.keys():
+ return_status = glusterd_stop(serverkey)
+ if return_status:
+ return return_status
+
+ return 0
+
+def glusterd_restart(serverkey):
+ """
+ """
+ return_status = glusterd_stop(serverkey)
+ if return_status:
+ return return_status
+ else:
+ return_status = glusterd_start(serverkey)
+ return return_status
+
+def glusterd_remove_dir(serverkey):
+ """
+ """
+ command = "rm -rf /etc/glusterd/*"
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ server_obj = env.getServer(serverkey)
+ if not server_obj:
+ print "Invalid Host. %s not defined in TestEnvironment" % serverkey
+ return 1
+
+ server_connection = cm.getConnection(serverkey)
+ if not server_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = server_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return 0
+
+def glusterd_remove_dir_allservers():
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ all_servers = env.getServers()
+ for serverkey in all_servers.keys():
+ return_status = glusterd_remove_dir(serverkey)
+
+ return 0
+
+
+def glusterd_remove_logs(serverkey):
+ """
+ """
+ base_command = "rm -rf "
+ log_paths = ["/var/log/glusterfs/*.log", "/var/log/glusterfs/bricks/*"]
+ absolute_path_list = []
+ prefix_path = ''
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ server_obj = env.getServer(serverkey)
+ if not server_obj:
+ print "Invalid Host. %s not defined in TestEnvironment" % serverkey
+ return 1
+
+ server_connection = cm.getConnection(serverkey)
+ if not server_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ if server_obj.installpath:
+ prefix_path = server_obj.installpath
+
+ for path in log_paths:
+ absolute_path_list.append(prefix_path + path)
+
+ for path in absolute_path_list:
+ command = base_command + path
+ print "%s : %s" % (serverkey, command)
+ output = server_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+
+ return 0
+
+def glusterd_remove_logs_allservers():
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ all_servers = env.getServers()
+ for serverkey in all_servers.keys():
+ return_status = glusterd_remove_logs(serverkey)
+
+ return 0
+
+def volume_delete(serverkey):
+ """
+ """
+ base_command = "gluster volume delete "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "Invalid Volume.ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_create(serverkey):
+ """
+ """
+ base_command = "gluster volume create "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+
+ command = base_command + \
+ active_volume.volumename + " " + \
+ active_volume.volumetype + " " + \
+ active_volume.count + " " + \
+ "transport " + active_volume.transporttype + " "
+
+ for brick_obj in active_volume.bricks:
+ brick_value = brick_obj.hostname + ":" + brick_obj.path
+ command = command + brick_value + " "
+
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ if return_status:
+ if str(output["stdoutdata"]).rfind("already exists"):
+ return_status = 0
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_start(serverkey, force=False):
+ """
+ """
+ base_command = "gluster volume start "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename
+ if force:
+ command = command + " force"
+
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ if return_status:
+ if str(output["stdoutdata"]).rfind("already started"):
+ return_status = 0
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_stop(serverkey, force=False):
+ """
+ """
+ base_command = "gluster volume stop "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename
+ if force:
+ command = command + " force"
+
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_addbrick(serverkey, *bricks):
+ """
+ """
+ base_command = "gluster volume add-brick "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumenameGlobalObj.getConnectionsManagerObj()
+ command = base_command + volumename + " "
+ for brick in bricks:
+ brick_obj = env.getBrick(brick)
+ if not brick_obj:
+ print "Invalid Brick. Brick Not defined in TestEnvironment"
+ return 1
+ brick_value = brick_obj.hostname + ":" + brick_obj.path
+ command = command + brick_value
+
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ if not return_status:
+ if env.addBricksToVolume(*bricks):
+ return 1
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_replacebrick(serverkey, replacebrick_key, tobrick_key):
+ """
+ """
+ base_command = "gluster volume replace-brick "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename + " "
+ replace_brick = env.getbrick(replacebrick_key)
+ to_brick = env.getbrick(tobrick_key)
+ command = command + replace_brick + " " + to_brick
+
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ if not return_status:
+ if env.replaceBrickInVolume(replacebrick_key, tobrick_key):
+ return 1
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_set(serverkey, key, value):
+ """
+ """
+ base_command = "gluster volume set "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename + " " + key + " " + value
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def volume_reset(serverkey):
+ """
+ """
+ base_command = "gluster volume reset "
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ print "ActiveVolume not defined for the TestEnvironment"
+ return 1
+ volumename = active_volume.volumename
+ command = base_command + volumename
+ host_connection = cm.getConnection(serverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (serverkey, command)
+ output = host_connection.executecommand(command, commandInput="y\n")
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def peer_probe(fromserverkey):
+ """
+ """
+ base_command = "gluster peer probe "
+ command = base_command
+ all_servers = {}
+ 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 = command + server_obj.hostname + " "
+
+ host_connection = cm.getConnection(fromserverkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ print "%s : %s" % (fromserverkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+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]
+
+ 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
+ command = base_command + dirpath
+ else:
+ export_obj = env.getExportdir(exportdir)
+ dirpath = export_obj.dir
+ device = export_obj.device
+ fstype = export_obj.fstype
+
+ print "%s : %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, 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):
+ """
+ """
+ base_command = "umount "
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ server_connection = cm.getConnection(serverkey)
+ if not server_connection:
+ print "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
+ print "%s : %s" % (serverkey, command)
+ output = server_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ 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, dirpath):
+ """
+ """
+ base_command = "mount "
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ server_connection = cm.getConnection(serverkey)
+ if not server_connection:
+ print "SSH connection to host '%s' has not been established" % serverkey
+ return 1
+
+ if fstype is None:
+ fstype = "xfs"
+
+ command = base_command + "-t " + fstype + " " + device + " " + dirpath
+
+ print "%s : %s" % (serverkey, command)
+ output = server_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def create_brick_allservers():
+ """
+ """
+ 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']
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SharedModules/Utils/hostutils.py b/SharedModules/Utils/hostutils.py
new file mode 100644
index 0000000..68bb1bf
--- /dev/null
+++ b/SharedModules/Utils/hostutils.py
@@ -0,0 +1,193 @@
+"""hostutils module contains wrappers for commands that can be executed on any
+host in the test environment
+
+Supported Wrappers:
+-------------------
+*) rmdir
+*) mkdir
+*) mkfs
+*) execute_command
+"""
+
+import re
+import atfutils
+from atfglobals import GlobalObj
+
+def cd(hostkey, dirpath):
+ """
+ """
+ base_command = "cd "
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH Connection Not established to host '%s' " % hostkey
+ return 1
+ command = base_command + dirpath
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def rmdir(hostkey, dirpath):
+ """
+ """
+ base_command = "rm -rf "
+ cm = GlobalObj.getConnectionsManagerObj()
+ system_dirs = re.compile('(/bin|/boot|/dev|/etc|/lib|/mnt|/net|/opt|/root|/sbin|/usr|/var|/sys)\/?$')
+ if system_dirs.match(dirpath):
+ print "System Directiories cannot be deleted"
+ return 1
+
+ else:
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH Connection Not established to host '%s' " % hostkey
+ return 1
+ command = base_command + dirpath
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def mkdir(hostkey, dirpath):
+ """
+ """
+ base_command = "mkdir -p "
+ cm = GlobalObj.getConnectionsManagerObj()
+ system_dirs = re.compile('(/bin|/boot|/dev|/etc|/lib|/mnt|/net|/opt|/root|/sbin|/usr|/var|/sys)\/?$')
+ if system_dirs.match(dirpath):
+ print "System Directiories cannot be created"
+ return 1
+
+ else:
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH Connection Not established to host '%s' " % hostkey
+ return 1
+ command = base_command + dirpath
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def mkfs(hostkey, device, fstype=None):
+ """
+ """
+ base_command = "mkfs "
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH Connection Not established to host '%s' " % hostkey
+ return 1
+
+ if fstype is None:
+ fstype = "xfs"
+
+ command = base_command + " -t " + fstype + " -f " + device
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(command)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+def find_mountpoints(hostkey, device):
+ """
+ """
+ base_command = "mount | grep "
+ cm = GlobalObj.getConnectionsManagerObj()
+
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH connection to host '%s' has not been established" % hostkey
+ return 1
+
+ mountpoints = []
+ command = base_command + device
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(command)
+ if not output["exitstatus"]:
+ for data in output["stdoutdata"]:
+ mountpoints.append(data.split(" ")[2])
+
+ return mountpoints
+
+def execute_command(hostkey, command, commandInput=None):
+ """
+ """
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ print "SSH Connection Not established to host '%s' " % hostkey
+ return 1
+ new_command = _substitute_value_for_variables(hostkey, command)
+
+ print "%s : %s" % (hostkey, command)
+ output = host_connection.executecommand(new_command, commandInput)
+ return_status = atfutils.assert_success(**output)
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+ return return_status
+
+
+def _substitute_value_for_variables(hostkey, command):
+ """
+ """
+ pattern_for_variables = re.compile("<[a-z]+\d*>")
+ pattern_for_hosts = re.compile('(server|client|master)*')
+ variables_to_replace = []
+ replace_values = {}
+ new_command = command
+ Functions_Map = {
+ "server" : "getserver",
+ "client" : "getclient",
+ "master" : "getmaster"
+ }
+ variables = pattern_for_variables.findall(command)
+ host = None
+
+ if not variables:
+ return new_command
+
+ else:
+ result = pattern_for_hosts.match(hostkey.lower()).group(0)
+ if result:
+ funcname = Functions_Map[result]
+ function = getattr(env, funcname)
+ if re.match("master", result):
+ host = function()
+ else:
+ host = function(hostkey)
+
+ if not host:
+ print "No Host to execute the command\n"
+ return 1
+
+ for variable in variables:
+ if variable not in variables_to_replace:
+ variables_to_replace.append(variable.strip("<>"))
+
+ for variable in variables_to_replace:
+ value = host.__getattribute__(variable)
+ replace_values[variable] = value
+
+ for key in replace_values.keys():
+ value = replace_values[key]
+ key = "<" + key + ">"
+ pattern = re.compile(key)
+ new_command = pattern.sub(value, new_command)
+
+ return new_command
+
+__all__ = ['cd',
+ 'rmdir',
+ 'mkdir',
+ 'mkfs',
+ 'find_mountpoints',
+ 'execute_command']
diff --git a/SharedModules/Utils/managerutils.py b/SharedModules/Utils/managerutils.py
new file mode 100644
index 0000000..ca38b3f
--- /dev/null
+++ b/SharedModules/Utils/managerutils.py
@@ -0,0 +1,55 @@
+"""managerutils module.
+
+Supported Wrappers:-
+---------------
+*) ssh_connect
+*) ssh_connect_allhosts
+"""
+
+import re
+import ssh
+from atfglobals import GlobalObj
+
+def ssh_connect(hostkey):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ host_obj = env.getHost(hostkey)
+ if not host_obj:
+ print "Invalid Host. %s is not defined in TestEnvironment" % hostkey
+ return 1
+ else:
+ host_connection = ssh.SshConnection()
+ if host_connection.connect(host_obj.hostname, host_obj.user,
+ host_obj.password):
+ return 1
+ else:
+ if re.match("server", hostkey, re.IGNORECASE):
+ cm.addServer(hostkey, host_connection)
+ else:
+ cm.addClient(hostkey, host_connection)
+ return 0
+ else:
+ print "Connection to %s already exist" % hostkey
+
+ return 0
+
+def ssh_connect_allhosts():
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ hosts_keys = env.getHostsKeys()
+ for hostkey in hosts_keys:
+ return_status = ssh_connect(hostkey)
+ if return_status:
+ return return_status
+
+ return 0
+
+__all__ = ['ssh_connect',
+ 'ssh_connect_allhosts']
+
diff --git a/SharedModules/Utils/serverutils.py b/SharedModules/Utils/serverutils.py
new file mode 100644
index 0000000..618ee23
--- /dev/null
+++ b/SharedModules/Utils/serverutils.py
@@ -0,0 +1,33 @@
+"""serverutils module
+"""
+import re
+import hostutils
+from atfglobals import GlobalObj
+
+def execute_on_brick(brickkey, command, commandInput=None):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+
+ raw_brick_obj = env.getRawBrick(brickkey)
+ if not raw_brick_obj:
+ print "InValid Brick. %s not defined in TestEnvironment" % brickkey
+ return 1
+ serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
+
+ brick_obj = env.getBrick(brickkey)
+ if not brick_obj:
+ print "InValid Brick. %s not defined in TestEnvironment" % brickkey
+ return 1
+ exportdirpath = brick_obj.path
+
+ command = "cd " + exportdirpath + ";" + command
+ return_status = hostutils.execute_command(serverkey, command, commandInput)
+ return return_status
+
+__all__ = ['execute_on_brick']
+
+
+
+
+