summaryrefslogtreecommitdiffstats
path: root/libs/utils/glusterutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/utils/glusterutils.py')
-rw-r--r--libs/utils/glusterutils.py210
1 files changed, 133 insertions, 77 deletions
diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py
index 0c15af1..7ab41d0 100644
--- a/libs/utils/glusterutils.py
+++ b/libs/utils/glusterutils.py
@@ -27,17 +27,18 @@ import atfutils
import hostutils
from atfglobals import GlobalObj
-
def glusterd_start(serverkey, force=False):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
""" Check if gluster is already running. If already Running and force=True,
@@ -55,7 +56,7 @@ def glusterd_start(serverkey, force=False):
command = commands_to_execute.pop()
output = host_connection.executecommand(command)
if output["exitstatus"]:
- print "Unable to start glusterd"
+ logger.error("Unable to start glusterd")
return_status = atfutils.assert_success(**output)
return return_status
else:
@@ -63,7 +64,7 @@ def glusterd_start(serverkey, force=False):
gluster_path = None
gluster_path = output["stdoutdata"][0].strip("\n")
else:
- print "Unable to find gluster path"
+ logger.error("Unable to find gluster path")
return_status = atfutils.assert_success(**output)
return return_status
@@ -72,17 +73,18 @@ def glusterd_start(serverkey, force=False):
output = host_connection.executecommand(command)
if not output["stdoutdata"] == None:
if re.search(gluster_version, str(output["stdoutdata"])):
- print "%s : %s" % (serverkey, gluster_path)
+ logger.debug('%s: Executing Command: %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"
+ logger.error("Unable to start glusterd")
return 1
else:
- print "Unable to start glusterd"
+ logger.error("Unable to start glusterd")
return 1
def glusterd_start_allservers(force=False):
@@ -100,12 +102,14 @@ def glusterd_start_allservers(force=False):
def glusterd_stop(serverkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
gluster_pid_list = []
@@ -121,7 +125,7 @@ def glusterd_stop(serverkey):
for pid in gluster_pid_list:
command = base_command + pid
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command)
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -156,21 +160,26 @@ def glusterd_restart(serverkey):
def glusterd_remove_dir(serverkey):
"""
"""
- command = "rm -rf /etc/glusterd/*"
+ 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:
- print "Invalid Host. %s not defined in TestEnvironment" % serverkey
+ logger.error("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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
-
- print "%s : %s" % (serverkey, command)
+
+ 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)
atfutils.print_stdout(output['stdoutdata'])
@@ -191,8 +200,9 @@ def glusterd_remove_dir_allservers():
def glusterd_remove_logs(serverkey):
"""
"""
- base_command = "rm -rf "
- log_paths = ["/var/log/glusterfs/*.log", "/var/log/glusterfs/bricks/*"]
+ logger = GlobalObj.getLoggerObj()
+ base_command = "rm -rf"
+ log_paths = GlobalObj.glusterd_log_paths
absolute_path_list = []
prefix_path = ''
env = GlobalObj.getTestenvObj()
@@ -200,12 +210,14 @@ def glusterd_remove_logs(serverkey):
server_obj = env.getServer(serverkey)
if not server_obj:
- print "Invalid Host. %s not defined in TestEnvironment" % serverkey
+ logger.error("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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
if server_obj.installpath:
@@ -215,8 +227,8 @@ def glusterd_remove_logs(serverkey):
absolute_path_list.append(prefix_path + path)
for path in absolute_path_list:
- command = base_command + path
- print "%s : %s" % (serverkey, command)
+ command = ' '.join([base_command, path])
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = server_connection.executecommand(command)
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -237,21 +249,24 @@ def glusterd_remove_logs_allservers():
def volume_delete(serverkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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"
+ logger.error("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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -261,30 +276,30 @@ def volume_delete(serverkey):
def volume_create(serverkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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"
+ logger.error("ActiveVolume not defined for the TestEnvironment")
return 1
-
- command = base_command + \
- active_volume.volumename + " " + \
- active_volume.volumetype + " " + \
- active_volume.count + " " + \
- "transport " + active_volume.transporttype + " "
+
+ command = ' '.join([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 + " "
+ command = ' '.join([command, brick_value])
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
if return_status:
@@ -297,12 +312,13 @@ def volume_create(serverkey):
def volume_start(serverkey, force=False):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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"
+ logger.error("ActiveVolume not defined for the TestEnvironment")
return 1
volumename = active_volume.volumename
command = base_command + volumename
@@ -311,10 +327,11 @@ def volume_start(serverkey, force=False):
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
if return_status:
@@ -327,12 +344,13 @@ def volume_start(serverkey, force=False):
def volume_stop(serverkey, force=False):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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"
+ logger.error("ActiveVolume not defined for the TestEnvironment")
return 1
volumename = active_volume.volumename
command = base_command + volumename
@@ -341,10 +359,11 @@ def volume_stop(serverkey, force=False):
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -354,29 +373,35 @@ def volume_stop(serverkey, force=False):
def volume_addbrick(serverkey, *bricks):
"""
"""
- base_command = "gluster volume add-brick "
+ logger = GlobalObj.getLoggerObj()
+ base_command = "gluster volume add-brick"
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
active_volume = env.getActiveVolume()
+ command = [base_command]
+
if not active_volume:
- print "ActiveVolume not defined for the TestEnvironment"
+ logger.error("ActiveVolume not defined for the TestEnvironment")
return 1
- volumename = active_volume.volumenameGlobalObj.getConnectionsManagerObj()
- command = base_command + volumename + " "
+ volumename = active_volume.volumename
+
+ command.extend([volumename])
for brick in bricks:
brick_obj = env.getBrick(brick)
if not brick_obj:
- print "Invalid Brick. Brick Not defined in TestEnvironment"
+ logger.error("Invalid Brick. Brick Not defined in TestEnvironment")
return 1
brick_value = brick_obj.hostname + ":" + brick_obj.path
- command = command + brick_value
-
+ command.extend([brick_value])
+
+ command = ' '.join(command)
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
if not return_status:
@@ -389,25 +414,33 @@ def volume_addbrick(serverkey, *bricks):
def volume_replacebrick(serverkey, replacebrick_key, tobrick_key):
"""
"""
+ logger = GlobalObj.getLoggerObj()
base_command = "gluster volume replace-brick "
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
+ command = [base_command]
+
active_volume = env.getActiveVolume()
if not active_volume:
- print "ActiveVolume not defined for the TestEnvironment"
+ logger.error("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
-
+
+ if not (to_brick and replace_brick):
+ logger.error("Invalid Brick. Brick Not defined in TestEnvironment")
+ return 1
+
+ command.extend([volumename, replace_brick, to_brick])
+ command = ' '.join(command)
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
if not return_status:
@@ -420,21 +453,28 @@ def volume_replacebrick(serverkey, replacebrick_key, tobrick_key):
def volume_set(serverkey, key, value):
"""
"""
- base_command = "gluster volume set "
+ logger = GlobalObj.getLoggerObj()
+ base_command = "gluster volume set"
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
+ command = [base_command]
+
active_volume = env.getActiveVolume()
if not active_volume:
- print "ActiveVolume not defined for the TestEnvironment"
+ logger.error("ActiveVolume not defined for the TestEnvironment")
return 1
volumename = active_volume.volumename
- command = base_command + volumename + " " + key + " " + value
+
+ command.extend([volumename, key, value])
+ command = ' '.join(command)
+
host_connection = cm.getConnection(serverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -444,21 +484,23 @@ def volume_set(serverkey, key, value):
def volume_reset(serverkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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"
+ logger.error("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
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = host_connection.executecommand(command, commandInput="y\n")
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -468,8 +510,9 @@ def volume_reset(serverkey):
def peer_probe(fromserverkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
base_command = "gluster peer probe "
- command = base_command
+ command = [base_command]
all_servers = {}
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
@@ -481,14 +524,16 @@ def peer_probe(fromserverkey):
continue
else:
server_obj = all_servers[key]
- command = command + server_obj.hostname + " "
-
+ command.extend([server_obj.hostname])
+
+ command = ' '.join(command)
host_connection = cm.getConnection(fromserverkey)
if not host_connection:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % serverkey)
return 1
- print "%s : %s" % (fromserverkey, command)
+ logger.debug('%s: Executing Command: %s' % (fromserverkey, command))
output = host_connection.executecommand(command)
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -498,6 +543,7 @@ def peer_probe(fromserverkey):
def create_brick(brickkey):
"""
"""
+ logger = GlobalObj.getLoggerObj()
return_status = 1
env = GlobalObj.getTestenvObj()
brick_obj = env.getRawBrick(brickkey)
@@ -513,20 +559,20 @@ def create_brick(brickkey):
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
+ options = export_obj.options
- print "%s : %s" % (serverkey, 'create_brick')
+ 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, dirpath):
+ if mount_exportdir(serverkey, device, fstype, options, dirpath):
return return_status
return 0
@@ -541,19 +587,21 @@ def create_brick(brickkey):
def umount_device(serverkey, device):
"""
"""
+ logger = GlobalObj.getLoggerObj()
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
+ 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
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = server_connection.executecommand(command)
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])
@@ -568,23 +616,31 @@ def umount_device(serverkey, device):
return 0
-def mount_exportdir(serverkey, device, fstype, dirpath):
+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:
- print "SSH connection to host '%s' has not been established" % serverkey
+ logger.error("SSH connection to host '%s' has not been established"
+ % 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)
- command = base_command + "-t " + fstype + " " + device + " " + dirpath
-
- print "%s : %s" % (serverkey, command)
+ logger.debug('%s: Executing Command: %s' % (serverkey, command))
output = server_connection.executecommand(command)
return_status = atfutils.assert_success(**output)
atfutils.print_stdout(output['stdoutdata'])