summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2020-02-17 13:15:28 +0530
committerBala Konda Reddy M <bala12352@gmail.com>2020-03-02 16:17:16 +0000
commit8616ac1e44316ead3fea05e5b2c51d7a97b8eb4a (patch)
tree71ab963b3c742fff5eaa156c0e08706a6c0aace7 /glustolibs-gluster/glustolibs/gluster
parent7c860f945906b824da49755d7bc883b4d6c4e5ee (diff)
[lib] Add functionality to setup master and slave volumes
Adding the code for the following: 1.Adding function setup_master_and_slave_volumes() to geo_rep_libs. 2.Adding variables for master_mounts, slave_mounts, master_volume and slave_volume to gluster_base_class.py 3.Adding class class method setup_and_mount_geo_rep_master_and_slave_volumes to gluster_base_class.py. Change-Id: Ic8ae1cb1c8b5719d4774996c3e9e978551414b44 Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py59
-rw-r--r--glustolibs-gluster/glustolibs/gluster/gluster_base_class.py60
2 files changed, 118 insertions, 1 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py b/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
index a850681..20531b9 100644
--- a/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2018 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2017-2020 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -36,6 +36,8 @@ from glustolibs.gluster.lib_utils import (group_add, ssh_copy_id,
is_group_exists, is_user_exists,
is_passwordless_ssh_configured)
from glustolibs.gluster.glusterdir import get_dir_contents
+from glustolibs.gluster.volume_ops import set_volume_options
+from glustolibs.gluster.volume_libs import setup_volume
def georep_prerequisites(mnode, snode, passwd, user="root", group=None,
@@ -302,3 +304,58 @@ def georep_create_session(mnode, snode, mastervol, slavevol,
(user, mastervol, slavevol))
return False
return True
+
+
+def setup_master_and_slave_volumes(mnode, all_servers_info,
+ master_volume_config,
+ snode, all_slaves_info,
+ slave_volume_config,
+ force=False):
+ """Create master and slave volumes for geo-replication.
+
+ Args:
+ mnode(str): The primary master node where the commands are executed.
+ all_servers_info(dict): Information about all master servers.
+ master_volume_config(dict): Dict containing volume information
+ of master.
+ snode(str): slave node where the commande are executed.
+ all_slaves_info(dict): Information about all slave servers.
+ slave_volume_config(dict): Dict containing volume information
+ of slave.
+ kwargs:
+ force(bool): If set to true then will create volumes
+ with force option.
+
+ Returns:
+ bool : True if volumes created successfully, false if there are
+ any failures in the middle.
+
+ Example:
+ setup_master_and_slave_volumes(
+ cls.mode, cls.all_servers_info, cls.master_volume,
+ cls.snode, cls.all_slaves_info, cls.slave_volume)
+ >>> True
+ """
+ # Setting up the master and the slave volume.
+ ret = setup_volume(mnode, all_servers_info, master_volume_config,
+ force)
+ if not ret:
+ g.log.error("Failed to Setup master volume %s",
+ master_volume_config['name'])
+ return False
+
+ ret = setup_volume(snode, all_slaves_info, slave_volume_config,
+ force)
+ if not ret:
+ g.log.error("Failed to Setup slave volume %s",
+ slave_volume_config['name'])
+ return False
+
+ # Setting performance.quick-read to off.
+ ret = set_volume_options(snode, slave_volume_config['name'],
+ {"performance.quick-read": "off"})
+ if not ret:
+ g.log.error("Failed to performance.quick-read to off on "
+ "slave volume %s", slave_volume_config['name'])
+ return False
+ return True
diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
index 3046dc4..57ec9ba 100644
--- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
+++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
@@ -55,6 +55,7 @@ from glustolibs.gluster.brick_libs import (
from glustolibs.gluster.volume_ops import (
set_volume_options, volume_reset, volume_start)
from glustolibs.io.utils import log_mounts_info
+from glustolibs.gluster.geo_rep_libs import setup_master_and_slave_volumes
class runs_on(g.CarteTestClass):
@@ -411,6 +412,30 @@ class GlusterBaseClass(TestCase):
g.log.info("Successful in volume reset %s", cls.volname)
@classmethod
+ def setup_and_mount_geo_rep_master_and_slave_volumes(cls, force=False):
+ """Setup geo-rep master and slave volumes.
+
+ Returns (bool): True if cleanup volume is successful. False otherwise.
+ """
+ # Creating and starting master and slave volume.
+ ret = setup_master_and_slave_volumes(
+ cls.mode, cls.all_servers_info, cls.master_volume,
+ cls.snode, cls.all_slaves_info, cls.slave_volume,
+ force)
+ if not ret:
+ g.log.error('Failed to create master and slave volumes.')
+ return False
+
+ # Mounting master and slave volumes
+ for mount in [cls.master_mounts, cls.slave_mounts]:
+ ret = cls.mount_volume(cls, mount)
+ if not ret:
+ g.log.error('Failed to mount volume %s.',
+ mount['volname'])
+ return False
+ return True
+
+ @classmethod
def unmount_volume(cls, mounts):
"""Unmount all mounts for the volume
@@ -756,6 +781,25 @@ class GlusterBaseClass(TestCase):
cls.mnode = cls.servers[0]
cls.vol_options = cls.volume['options']
+ # Define useful variable for geo-rep volumes.
+ if cls.geo_rep_info:
+ # For master volume
+ cls.master_volume = cls.volume
+ cls.master_volume['name'] = ('master_testvol_%s'
+ % cls.volume_type)
+ cls.master_volname = cls.master_volume['name']
+ cls.master_voltype = (cls.master_volume['voltype']
+ ['type'])
+
+ # For slave volume
+ cls.slave_volume = deepcopy(cls.volume)
+ cls.slave_volume['name'] = ('slave_testvol_%s'
+ % cls.volume_type)
+ cls.slave_volume['servers'] = cls.slaves
+ cls.slave_volname = cls.slave_volume['name']
+ cls.slave_voltype = (cls.slave_volume['voltype']
+ ['type'])
+
# Get the mount configuration.
cls.mounts = []
if cls.mount_type:
@@ -804,6 +848,22 @@ class GlusterBaseClass(TestCase):
cls.mounts = create_mount_objs(cls.mounts_dict_list)
+ # Setting mounts for geo-rep volumes.
+ if cls.geo_rep_info:
+
+ # For master volume mount
+ cls.master_mounts = cls.mounts
+
+ # For slave volume mount
+ slave_mount_dict_list = deepcopy(cls.mounts_dict_list)
+ for mount_dict in slave_mount_dict_list:
+ mount_dict['volname'] = cls.slave_volume
+ mount_dict['server'] = cls.snode
+ mount_dict['mountpoint'] = path_join(
+ "/mnt", '_'.join([cls.slave_volname,
+ cls.mount_type]))
+ cls.slave_mounts = create_mount_objs(slave_mount_dict_list)
+
# Defining clients from mounts.
cls.clients = []
for mount in cls.mounts_dict_list: