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.py149
1 files changed, 149 insertions, 0 deletions
diff --git a/libs/utils/glusterutils.py b/libs/utils/glusterutils.py
index 2c21d9b..ef9f45c 100644
--- a/libs/utils/glusterutils.py
+++ b/libs/utils/glusterutils.py
@@ -546,6 +546,63 @@ def volume_reset(serverkey):
output = hostutils.execute_command(serverkey, command, commandInput="y\n")
return output
+def volume_geo_replication(serverkey, slavekey, operation, volume=False,
+ local=False, *options):
+ """
+ operation: {start|stop|config|status|log-rotate}
+ options are valid oly if the operation is 'config'
+ ex: log_file /usr/local/var/log/glusterfs/geo.log
+ remote_gsyncd /usr/local/libexec/glusterfs/gsyncd
+ if you are starting geo-replication session with
+ another volume, you need to give volume = True
+ and by default it take path given in the configuration file
+ """
+ output = atfutils.get_new_output_obj()
+ logger = GlobalObj.getLoggerObj()
+ base_command = "gluster volume geo-replication"
+ env = GlobalObj.getTestenvObj()
+ command = [base_command]
+
+ active_volume = env.getActiveVolume()
+ if not active_volume:
+ logger.error("ActiveVolume not defined for the TestEnvironment")
+ output['exitstatus'] = 1
+ return output
+
+ volumename = active_volume.volumename
+
+ slave_obj = env.getSlave(slavekey)
+ if not slave_obj:
+ logger.error("Invalid slave. Slave not defined in Testenvironment")
+ output['exitstatus'] = 1
+ return ouput
+ if not local:
+ if not volume:
+ slave_value = slave_obj.hostname +":"+ slave_obj.path
+ else:
+ slave_value = slave_obj.hostname +":"+ slave_obj.volumename
+ else:
+ if not volume:
+ slave_value = slave_obj.path
+ else:
+ slave_value = ":"+slave_obj.volumename
+
+ command.extend([volumename, slave_value])
+
+ if operation == 'config':
+ if options:
+ command.extend(['config', options[0]])
+ else:
+ command.extend(['config'])
+ else:
+ command.extend([operation])
+
+ command = ' '.join(command)
+
+ output = hostutils.execute_command(serverkey, command, commandInput="y\n")
+ return output
+
+
def volume_profile(serverkey, operation):
"""
operation:{start|info|stop}
@@ -804,3 +861,95 @@ def create_brick_allservers():
create_brick_output["exitstatus"] = 0
create_brick_output["stdoutdata"] = "Successful in creating bricks on all servers"
return create_brick_output
+
+def create_slave(slavekey):
+ """
+ This function creates the slave. In the sense ,
+ if it is just some path, its not it leave as it is.
+ If path in slave section is given as some exportdir
+ then it will format the device given in the exportdir section
+ with the file system and mounts the device on the path ,
+ both defined in the exportdir section in configuration file
+ """
+ logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
+ env = GlobalObj.getTestenvObj()
+ slave_obj = env.getRawSlave(slavekey)
+ if not slave_obj:
+ logger.error("Invalid slave.Slave not defined in Testenvironment")
+ output['exitstatus'] = 1
+ return output
+ hostname_value = slave_obj.hostname
+ serverkey = re.split("\.", hostname_value, maxsplit=1)[0]
+ exportdir = slave_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:
+ export_obj = env.getExportdir(exportdir)
+ dirpath = export_obj.dir
+ device = export_obj.device
+ fstype = export_obj.fstype
+ options = export_obj.options
+
+ server_obj = env.getServer(serverkey)
+ if server_obj is None:
+ logger.error("Invalid Host. %s not defined in TestEnvironment"
+ % serverkey)
+ output['exitstatus'] = 1
+ return output
+ server_hostname = server_obj.hostname
+
+ logger.debug('%s: Executing Command: %s' %(server_hostname, 'create_slave'))
+ 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 Slave %s" % slavekey
+ return output
+
+def create_slave_allservers():
+ """
+ """
+ create_slave_output = atfutils.get_new_output_obj()
+
+ env = GlobalObj.getTestenvObj()
+ slave_keys = env.getSlaveKeys()
+ for slavekey in slave_keys:
+ output = create_slave(slavekey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
+
+ create_slave_output["exitstatus"] = 0
+ create_slave_output["stdoutdata"] = "Successful in creating bricks on all \
+servers"
+ return create_slave_output