summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2019-08-23 12:49:11 +0530
committerBala Konda Reddy M <bmekala@redhat.com>2019-09-17 09:33:38 +0000
commitea4bdc24ee668fbfca727f8d827e3df00e1f7838 (patch)
tree76714d2e3246d814f78d283ced459311510e8e6c
parente04dd165c33a21d2674f8084f824cf41a300c088 (diff)
[lib] Modifying georep libraries as per changes in lib_utils.
THIS PATCH IS DEPENDENT ON THE BELOW PATCH: https://review.gluster.org/#/c/glusto-tests/+/23291/ Removing the below functions as a more generic function is added in lib_utils: georep_ssh_keygen georep_ssh_copyid georep_groupadd georep_geoaccount georep_geoaccount_setpasswd Adding georep_mountbroker_remove_user to remove users from mountbroker which will be needed in teardown. Change-Id: I5b484b93cbc1660cdf223cfa4bac2a32acc8fc77 Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
-rw-r--r--glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py46
-rwxr-xr-xglustolibs-gluster/glustolibs/gluster/geo_rep_ops.py211
2 files changed, 66 insertions, 191 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py b/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
index 2b0618b..2e516cd 100644
--- a/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/geo_rep_libs.py
@@ -20,18 +20,16 @@
from glusto.core import Glusto as g
from glustolibs.gluster.gluster_init import restart_glusterd
-from glustolibs.gluster.geo_rep_ops import (georep_groupadd,
- georep_geoaccount,
- georep_mountbroker_setup,
- georep_mountbroker_adduser,
+from glustolibs.gluster.geo_rep_ops import (georep_mountbroker_setup,
+ georep_mountbroker_add_user,
georep_mountbroker_status,
- georep_geoaccount_setpasswd,
- georep_ssh_keygen,
- georep_ssh_copyid,
- georep_createpem, georep_create,
- georep_set_pemkeys,
+ georep_create_pem,
+ georep_create,
+ georep_set_pem_keys,
georep_config_set)
from glustolibs.gluster.shared_storage_ops import enable_shared_storage
+from glustolibs.gluster.lib_utils import (group_add, ssh_copy_id,
+ ssh_keygen, add_user, set_passwd)
def georep_root_prerequisites(mnode, snode, user, passwd):
@@ -63,13 +61,13 @@ def georep_root_prerequisites(mnode, snode, user, passwd):
g.log.debug("Creating a common pem pub file on all the nodes in "
"the master to establish passwordless ssh connection "
"to the slave ")
- ret = georep_ssh_keygen(mnode)
+ ret = ssh_keygen(mnode)
if not ret:
g.log.error("Failed to create a common pem pub file")
return False
g.log.debug("Establishing passwordless ssh between master and slave")
- ret = georep_ssh_copyid(mnode, snode, user, passwd)
+ ret = ssh_copy_id(mnode, snode, user, passwd)
if not ret:
g.log.error("Failed to establish ssh connection")
return False
@@ -99,7 +97,7 @@ def georep_create_root_session(mnode, snode, mastervol, slavevol,
any failures in the middle
"""
g.log.debug("Creating a common pem file on %s", mnode)
- ret, _, _ = georep_createpem(mnode)
+ ret, _, _ = georep_create_pem(mnode)
if not ret:
g.log.error("Failed to create a common pem file on all the nodes "
"belonging to the cluster %s ", mnode)
@@ -147,16 +145,21 @@ def georep_nonroot_prerequisites(mnode, snodes, group, user, mntbroker_dir,
return False
g.log.debug("Create new group: %s on all slave nodes", group)
- if not georep_groupadd(snodes, group):
+ if not group_add(snodes, group):
g.log.error("Creating group: %s on all slave nodes failed", group)
return False
g.log.debug("Create user: %s in group: %s on all slave nodes", user, group)
- if not georep_geoaccount(snodes, group, user):
+ if not add_user(snodes, user, group):
g.log.error("Creating user: %s in group: %s on all slave nodes "
"failed", user, group)
return False
+ g.log.debug("Set passwd for user account on slave")
+ if not set_passwd(snodes, group, user, "geopasswd"):
+ g.log.error("Setting password failed on slaves")
+ return False
+
g.log.debug("Setting up mount broker root directory: %s node: %s",
mntbroker_dir, snodes[0])
ret, _, _ = georep_mountbroker_setup(snodes[0], group, mntbroker_dir)
@@ -167,7 +170,7 @@ def georep_nonroot_prerequisites(mnode, snodes, group, user, mntbroker_dir,
g.log.debug("Add volume: %s and user: %s to mountbroker service",
slavevol, user)
- ret, _, _ = georep_mountbroker_adduser(snodes[0], slavevol, user)
+ ret, _, _ = georep_mountbroker_add_user(snodes[0], slavevol, user)
if ret:
g.log.error("Add volume: %s and user: %s to mountbroker "
"service failed", slavevol, user)
@@ -188,17 +191,12 @@ def georep_nonroot_prerequisites(mnode, snodes, group, user, mntbroker_dir,
g.log.error("Restarting glusterd failed")
return False
- g.log.debug("Set passwd for user account on slave")
- if not georep_geoaccount_setpasswd(snodes, group, user, "geopasswd"):
- g.log.error("Setting password failed on slaves")
- return False
-
g.log.debug("Setup passwordless SSH between %s and %s", mnode, snodes[0])
- if not georep_ssh_keygen(mnode):
+ if not ssh_keygen(mnode):
g.log.error("ssh keygen is failed on %s", mnode)
return False
- if not georep_ssh_copyid(mnode, snodes[0], user, "geopasswd"):
+ if not ssh_copy_id(mnode, snodes[0], user, "geopasswd"):
g.log.error("ssh copy-id is failed from %s to %s", mnode, snodes[0])
return False
@@ -225,7 +223,7 @@ def georep_create_nonroot_session(mnode, mastervol, snode, slavevol, user,
"""
g.log.debug("Create geo-rep pem keys")
- ret, _, _ = georep_createpem(mnode)
+ ret, _, _ = georep_create_pem(mnode)
if ret:
g.log.error("Failed to create pem keys")
return False
@@ -238,7 +236,7 @@ def georep_create_nonroot_session(mnode, mastervol, snode, slavevol, user,
return False
g.log.debug("Copy geo-rep pem keys onto all slave nodes")
- ret, _, _ = georep_set_pemkeys(snode, user, mastervol, slavevol)
+ ret, _, _ = georep_set_pem_keys(snode, user, mastervol, slavevol)
if ret:
g.log.error("Failed to copy geo-rep pem keys onto all slave nodes")
return False
diff --git a/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py b/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
index e68901d..24161f6 100755
--- a/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2018 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2019 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
@@ -21,7 +21,7 @@
from glusto.core import Glusto as g
-def georep_createpem(mnode):
+def georep_create_pem(mnode):
""" Creates a common pem pub file on all the nodes in the master and
is used to implement the passwordless SSH connection
Args:
@@ -42,134 +42,30 @@ def georep_createpem(mnode):
return g.run(mnode, cmd)
-def georep_ssh_keygen(mnode):
- """ Creates a pair of ssh private and public key if not present
-
- Args:
- mnode (str): Node on which cmd is to be executed
- Returns:
- bool : True if ssh-keygen is successful on all servers.
- False otherwise. It also returns True if ssh key
- is already present
-
- """
- cmd = 'echo -e "n" | ssh-keygen -f ~/.ssh/id_rsa -q -N ""'
- ret, out, _ = g.run(mnode, cmd)
- if ret and "already exists" not in out:
- return False
- return True
-
-
-def georep_ssh_copyid(mnode, tonode, user, passwd):
- """ Copies the default ssh public key onto tonode's
- authorized_keys file
-
- Args:
- mnode (str): Node on which cmd is to be executed
- tonode (str): Node to which ssh key is to be copied
- user (str): user of tonode
- passwd (str): passwd of the user of tonode
- Returns:
- bool : True if ssh-copy-id is successful to tonode.
- False otherwise. It also returns True if ssh key
- is already present
-
- """
- cmd = ('sshpass -p "%s" ssh-copy-id -o StrictHostKeyChecking=no %s@%s' %
- (passwd, user, tonode))
- ret, _, _ = g.run(mnode, cmd)
- if ret:
- return False
- return True
-
-
-def georep_groupadd(servers, groupname):
- """ Creates a group in all the slave nodes where a user will be added
- to set up a non-root session
-
- Args:
- servers (list): list of nodes on which cmd is to be executed
- groupname (str): Specifies a groupname
-
- Returns:
- bool : True if add group is successful on all servers.
- False otherwise.
-
- """
- cmd = "groupadd %s" % groupname
- results = g.run_parallel(servers, cmd)
-
- _rc = True
- for server, ret_value in list(results.items()):
- retcode, _, err = ret_value
- if retcode != 0 and "already exists" not in err:
- g.log.error("Unable to add group %s on server %s",
- groupname, server)
- _rc = False
- if not _rc:
- return False
-
- return True
-
-
-def georep_geoaccount(servers, groupname, groupaccount):
- """ Creates a user account with which the geo-rep session can be securely
- set up
+def georep_set_pem_keys(mnode, useraccount, mastervol, slavevol):
+ """ Sets geo-rep pem keys
Args:
- servers (list): list of nodes on which cmd is to be executed
- groupname (str): Specifies a groupname
- groupaccount (str): Specifies the user account to set up geo-rep
+ mnode (str): Node on which command is to be executed
+ useraccount (str) : User with which geo-rep is to be set up
+ mastervol (str) : The master volume
+ slavevol (str): The slave volume
Returns:
- bool : True if user add is successful on all servers.
- False otherwise.
-
- """
- cmd = "useradd -G %s %s" % (groupname, groupaccount)
- results = g.run_parallel(servers, cmd)
-
- _rc = True
- for server, ret_value in list(results.items()):
- retcode, _, err = ret_value
- if retcode != 0 and "already exists" not in err:
- g.log.error("Unable to add user on %s", server)
- _rc = False
- if not _rc:
- return False
-
- return True
-
-
-def georep_geoaccount_setpasswd(servers, groupname, groupaccount, passwd):
- """ Creates a user account with which the geo-rep session can be securely
- set up
+ tuple: Tuple containing three elements (ret, out, err).
+ The first element 'ret' is of type 'int' and is the return value
+ of command execution.
- Args:
- servers (list): list of nodes on which cmd is to be executed
- groupname (str): Specifies a groupname
- groupaccount (str): Specifies the user account to set up geo-rep
- passwd (str): Specifies password for they groupaccount
+ The second element 'out' is of type 'str' and is the stdout value
+ of the command execution.
- Returns:
- bool : True if password set is successful on all servers.
- False otherwise.
+ The third element 'err' is of type 'str' and is the stderr value
+ of the command execution.
"""
- cmd = "echo %s:%s | chpasswd" % (groupaccount, passwd)
- results = g.run_parallel(servers, cmd)
-
- _rc = True
- for server, ret_value in list(results.items()):
- retcode, _, err = ret_value
- if retcode != 0:
- g.log.error("Unable to set passwd for user %s on %s",
- groupaccount, server)
- _rc = False
- if not _rc:
- return False
-
- return True
+ cmd = ("/usr/libexec/glusterfs/set_geo_rep_pem_keys.sh %s %s %s" %
+ (useraccount, mastervol, slavevol))
+ return g.run(mnode, cmd)
def georep_mountbroker_setup(mnode, groupname, directory):
@@ -196,13 +92,13 @@ def georep_mountbroker_setup(mnode, groupname, directory):
return g.run(mnode, cmd)
-def georep_mountbroker_adduser(mnode, slavevol, useraccount):
+def georep_mountbroker_add_user(mnode, slavevol, useraccount):
""" Adds the volume and user to the mountbroker
Args:
mnode (str): Node on which command is to be executed
slavevol (str) : The slave volume name
- useraccount (str): The user with which geo-rep is to be set up
+ useraccount (str): The user with which geo-rep is to be setup
Returns:
tuple: Tuple containing three elements (ret, out, err).
@@ -243,14 +139,13 @@ def georep_mountbroker_status(mnode):
return g.run(mnode, cmd)
-def georep_set_pemkeys(mnode, useraccount, mastervol, slavevol):
- """ Sets geo-rep pem keys
+def georep_mountbroker_remove_user(mnode, slavevol, useraccount):
+ """ Remove the volume and user from the mountbroker
Args:
mnode (str): Node on which command is to be executed
- useraccount (str) : User with which geo-rep is to be set up
- mastervol (str) : The master volume
- slavevol (str): The slave volume
+ slavevol (str) : The slave volume name
+ useraccount (str): The user with which geo-rep is to be setup
Returns:
tuple: Tuple containing three elements (ret, out, err).
@@ -264,8 +159,8 @@ def georep_set_pemkeys(mnode, useraccount, mastervol, slavevol):
of the command execution.
"""
- cmd = ("/usr/libexec/glusterfs/set_geo_rep_pem_keys.sh %s %s %s" %
- (useraccount, mastervol, slavevol))
+ cmd = ("gluster-mountbroker remove --volume %s --user %s"
+ % (slavevol, useraccount))
return g.run(mnode, cmd)
@@ -328,19 +223,13 @@ def georep_create(mnode, mastervol, slaveip, slavevol, user=None, force=False):
"""
if user:
- if force:
- cmd = ("gluster volume geo-replication %s %s@%s::%s create "
- "push-pem force" % (mastervol, user, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s@%s::%s create "
- "push-pem" % (mastervol, user, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s@%s::%s create "
+ "push-pem " % (mastervol, user, slaveip, slavevol))
else:
- if force:
- cmd = ("gluster volume geo-replication %s %s::%s create "
- "push-pem force" % (mastervol, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s::%s create push-pem" %
- (mastervol, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s::%s create push-pem" %
+ (mastervol, slaveip, slavevol))
+ if force:
+ cmd = (cmd + " force")
return g.run(mnode, cmd)
@@ -431,19 +320,13 @@ def georep_start(mnode, mastervol, slaveip, slavevol, user=None, force=False):
"""
if user:
- if force:
- cmd = ("gluster volume geo-replication %s %s@%s::%s start force" %
- (mastervol, user, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s@%s::%s start" %
- (mastervol, user, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s@%s::%s start " %
+ (mastervol, user, slaveip, slavevol))
else:
- if force:
- cmd = ("gluster volume geo-replication %s %s::%s start force" %
- (mastervol, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s::%s start" %
- (mastervol, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s::%s start " %
+ (mastervol, slaveip, slavevol))
+ if force:
+ cmd = (cmd + "force")
return g.run(mnode, cmd)
@@ -477,19 +360,13 @@ def georep_stop(mnode, mastervol, slaveip, slavevol, user=None, force=False):
"""
if user:
- if force:
- cmd = ("gluster volume geo-replication %s %s@%s::%s stop force" %
- (mastervol, user, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s@%s::%s stop" %
- (mastervol, user, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s@%s::%s stop " %
+ (mastervol, user, slaveip, slavevol))
else:
- if force:
- cmd = ("gluster volume geo-replication %s %s::%s stop force" %
- (mastervol, slaveip, slavevol))
- else:
- cmd = ("gluster volume geo-replication %s %s::%s stop" %
- (mastervol, slaveip, slavevol))
+ cmd = ("gluster volume geo-replication %s %s::%s stop " %
+ (mastervol, slaveip, slavevol))
+ if force:
+ cmd = (cmd + "force")
return g.run(mnode, cmd)