diff options
author | kshithijiyer <kshithij.ki@gmail.com> | 2019-09-19 21:15:31 +0530 |
---|---|---|
committer | Bala Konda Reddy M <bmekala@redhat.com> | 2020-01-03 09:08:05 +0000 |
commit | e6c1c5d7809494ced4f7273dac9784b3276c798e (patch) | |
tree | b6d9b55c01d67f7b7efc634ee661c30682e9025f /glustolibs-gluster/glustolibs/gluster/lib_utils.py | |
parent | 62aeeec189f145d521ebf719956a3fbc570af1ee (diff) |
[lib] Adding more check functions and tarssh support
- Adding the following check functions:
1. is_passwordless_ssh_configured() - To check if passwordless
ssh is configured or not between given nodes with a given user.
2. is_group_exists() - To check if group is present on servers
or not.
3. is_user_exists() - To check if a given user is present on
servers or not.
- Adding functionality to support both sync methods.
- Adding nonrootpass parameter to georep_prerequisites() as in
the previous logic the password for the non-root and the root
user were the same which might not always be the case.
- Fixing georep_config_get() and georep_config_set() to take
non-root user as well.
Change-Id: I8a42d48d56690040dd7f78d1fb919029c0d6e61d
Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/lib_utils.py')
-rwxr-xr-x | glustolibs-gluster/glustolibs/gluster/lib_utils.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py index 516cd76c8..f8b6cc720 100755 --- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py +++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py @@ -1105,3 +1105,81 @@ def set_passwd(servers, username, passwd): username, server) return False return True + + +def is_user_exists(servers, username): + """ + Checks if user is present on the given servers or not. + + Args: + servers(str|list): list of nodes on which you need to + check if the user is present or not. + username(str): username of user whose presence has to be checked. + + Returns: + bool: True if user is present on all nodes else False. + """ + if not isinstance(servers, list): + servers = [servers] + + cmd = "id %s" % username + results = g.run_parallel(servers, cmd) + + for server, (ret_value, _, _) in results.items(): + if not ret_value: + g.log.error("User %s doesn't exists on server %s.", + (username, server)) + return False + return True + + +def is_group_exists(servers, group): + """ + Checks if group is present on the given servers. + + Args: + servers(str|list): list of nodes on which you need to + check if group is present or not. + group(str): groupname of group whose presence has + to be checked. + + Returns: + bool: True if group is present on all nodes else False. + """ + if not isinstance(servers, list): + servers = [servers] + + cmd = "grep -q %s /etc/group" % group + results = g.run_parallel(servers, cmd) + + for server, (ret_value, _, _) in results.items(): + if not ret_value: + g.log.error("Group %s doesn't exists on server %s.", + (group, server)) + return False + return True + + +def is_passwordless_ssh_configured(fromnode, tonode, username): + """ + Checks if passwordless ssh is configured between nodes or not. + + Args: + fromnode: Server from which passwordless ssh has to be + configured. + tonode: Server to which passwordless ssh has to be + configured. + username: username of user to be used for checking + passwordless ssh. + Returns: + bool: True if configured else false. + """ + cmd = ("ssh %s@%s hostname" % (username, tonode)) + ret, out, _ = g.run(fromnode, cmd) + _, hostname, _ = g.run(tonode, "hostname") + if ret or hostname not in out: + g.log.error("Passwordless ssh not configured " + "from server %s to server %s using user %s.", + (fromnode, tonode, username)) + return False + return True |