summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster
diff options
context:
space:
mode:
authorPranav <prprakas@redhat.com>2020-07-10 11:44:53 +0530
committerBala Konda Reddy M <bala12352@gmail.com>2020-07-10 07:11:53 +0000
commitcea7339f60f23996fa33ea9ce0fdf57a55f1ad83 (patch)
tree53f61980de1da5d9ddc1e238142299c4e864b5f6 /glustolibs-gluster
parentc6814acfc8e6db87e4b0be2a09f50b71a37a48aa (diff)
[Libfix] Fix rpyc dependency for NFS-Ganesha libs
Problem: The rpyc connection fails in envs where the python versions are different, resulting in test failures Fix: Replace rpyc with standard ssh approach to overcome this issue Change-Id: Iee4bb968b8b94a6ab3e0fe0d16babacad914a92d Signed-off-by: Pranav <prprakas@redhat.com>
Diffstat (limited to 'glustolibs-gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/nfs_ganesha_libs.py25
-rw-r--r--glustolibs-gluster/glustolibs/gluster/nfs_ganesha_ops.py71
2 files changed, 51 insertions, 45 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_libs.py b/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_libs.py
index 19e98408e..92d22a8a4 100644
--- a/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_libs.py
@@ -100,24 +100,25 @@ class NfsGaneshaClusterSetupClass(GlusterBaseClass):
"healthy state")
ganesha_ha_file = ("/var/run/gluster/shared_storage/"
"nfs-ganesha/ganesha-ha.conf")
+ g_node = cls.servers_in_nfs_ganesha_cluster[0]
g.log.info("Collecting server details of existing "
"nfs ganesha cluster")
- conn = g.rpyc_get_connection(
- cls.servers_in_nfs_ganesha_cluster[0], user="root")
- if not conn:
- tmp_node = cls.servers_in_nfs_ganesha_cluster[0]
- g.log.error("Unable to get connection to 'root' of node"
- " %s", tmp_node)
- return False
- if not conn.modules.os.path.exists(ganesha_ha_file):
+ # Check whether ganesha ha file exists
+ cmd = "[ -f {} ]".format(ganesha_ha_file)
+ ret, _, _ = g.run(g_node, cmd)
+ if ret:
g.log.error("Unable to locate %s", ganesha_ha_file)
return False
- with conn.builtin.open(ganesha_ha_file, "r") as fhand:
- ganesha_ha_contents = fhand.read()
- g.rpyc_close_connection(
- host=cls.servers_in_nfs_ganesha_cluster[0], user="root")
+
+ # Read contents of ganesha_ha_file
+ cmd = "cat {}".format(ganesha_ha_file)
+ ret, ganesha_ha_contents, _ = g.run(g_node, cmd)
+ if ret:
+ g.log.error("Failed to read %s", ganesha_ha_file)
+ return False
+
servers_in_existing_cluster = re.findall(r'VIP_(.*)\=.*',
ganesha_ha_contents)
diff --git a/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_ops.py b/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_ops.py
index 3e53ec29d..dfbf63fa3 100644
--- a/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/nfs_ganesha_ops.py
@@ -23,7 +23,6 @@
"""
import os
-import random
from glusto.core import Glusto as g
from glustolibs.gluster.glusterdir import mkdir
from glustolibs.gluster.lib_utils import add_services_to_firewall
@@ -667,6 +666,8 @@ def create_nfs_ganesha_cluster(servers, vips):
False(bool): If failed to configure ganesha cluster
"""
# pylint: disable=too-many-return-statements
+ # pylint: disable=too-many-branches
+ # pylint: disable=too-many-statements
ganesha_mnode = servers[0]
# Configure ports in ganesha servers
@@ -852,47 +853,51 @@ def create_nfs_passwordless_ssh(mnode, gnodes, guser='root'):
False(bool): On failure
"""
loc = "/var/lib/glusterd/nfs/"
- mconn_inst = random.randint(20, 100)
- mconn = g.rpyc_get_connection(host=mnode, instance=mconn_inst)
- if not mconn.modules.os.path.isfile('/root/.ssh/id_rsa'):
+ # Check whether key is present
+ cmd = "[ -f /root/.ssh/id_rsa ]"
+ ret, _, _ = g.run(mnode, cmd)
+ if ret:
# Generate key on mnode if not already present
- if not mconn.modules.os.path.isfile('%s/secret.pem' % loc):
+ g.log.info("id_rsa not found")
+ cmd = "[ -f %s/secret.pem ]" % loc
+ ret, _, _ = g.run(mnode, cmd)
+ if ret:
+ g.log.info("Secret.pem file not found. Creating new")
ret, _, _ = g.run(
mnode, "ssh-keygen -f %s/secret.pem -q -N ''" % loc)
- if ret != 0:
+ if ret:
g.log.error("Failed to generate the secret pem file")
return False
g.log.info("Key generated on %s" % mnode)
else:
- mconn.modules.shutil.copyfile("/root/.ssh/id_rsa",
- "%s/secret.pem" % loc)
- g.log.info("Copying the id_rsa.pub to secret.pem.pub")
- mconn.modules.shutil.copyfile("/root/.ssh/id_rsa.pub",
- "%s/secret.pem.pub" % loc)
+ g.log.info("Found existing key")
+ # Copy the .pem and .pyb files
+ for file, to_file in (('id_rsa', 'secret.pem'), ('id_rsa.pub',
+ 'secret.pem.pub')):
+ cmd = "cp /root/.ssh/{} {}{}".format(file, loc, to_file)
+ ret, _, err = g.run(mnode, cmd)
+ if ret:
+ g.log.error("Failed to copy {} to {} file {}".format(file,
+ to_file,
+ err))
+ return False
# Create password less ssh from mnode to all ganesha nodes
+ cmd = "cat /root/.ssh/id_rsa.pub"
+ ret, id_rsa, _ = g.run(mnode, cmd, user=guser)
+ if ret:
+ g.log.info("Failed to read key from %s", mnode)
+ return False
for gnode in gnodes:
- gconn_inst = random.randint(20, 100)
- gconn = g.rpyc_get_connection(gnode, user=guser, instance=gconn_inst)
- try:
- glocal = gconn.modules.os.path.expanduser('~')
- gfhand = gconn.builtin.open("%s/.ssh/authorized_keys" % glocal,
- "a")
- with mconn.builtin.open("/root/.ssh/id_rsa.pub", 'r') as fhand:
- for line in fhand:
- gfhand.write(line)
- gfhand.close()
- except Exception as exep:
- g.log.error("Exception occurred while trying to establish "
- "password less ssh from %s@%s to %s@%s. Exception: %s"
- % ('root', mnode, guser, gnode, exep))
+ file = "~/.ssh/authorized_keys"
+ cmd = ("grep -q '{}' {} || echo '{}' >> {}"
+ .format(id_rsa.rstrip(), file, id_rsa.rstrip(), file))
+ ret, _, _ = g.run(gnode, cmd, user=guser)
+ if ret:
+ g.log.info("Failed to add ssh key for %s", gnode)
return False
- finally:
- g.rpyc_close_connection(
- host=gnode, user=guser, instance=gconn_inst)
-
- g.rpyc_close_connection(host=mnode, instance=mconn_inst)
+ g.log.info("Successfully copied ssh key to all Ganesha nodes")
# Copy the ssh key pair from mnode to all the nodes in the Ganesha-HA
# cluster
@@ -906,8 +911,8 @@ def create_nfs_passwordless_ssh(mnode, gnodes, guser='root'):
% (loc, loc, guser, gnode, loc))
ret, _, _ = g.run(mnode, cmd)
if ret != 0:
- g.log.error("Failed to copy the ssh key pair from %s to %s",
- mnode, gnode)
+ g.log.error("Failed to copy the ssh key pair from "
+ "%s to %s", mnode, gnode)
return False
return True
@@ -923,7 +928,7 @@ def create_ganesha_ha_conf(hostnames, vips, temp_ha_file):
"""
hosts = ','.join(hostnames)
- with open(temp_ha_file, 'wb') as fhand:
+ with open(temp_ha_file, 'w') as fhand:
fhand.write('HA_NAME="ganesha-ha-360"\n')
fhand.write('HA_CLUSTER_NODES="%s"\n' % hosts)
for (hostname, vip) in zip(hostnames, vips):