summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2019-08-05 18:05:34 +0530
committerBala Konda Reddy M <bmekala@redhat.com>2019-11-22 16:28:55 +0000
commit0702c89a4ce4a613aa096e99aaa96398375c705c (patch)
tree8c567d0d62e7e3e2408289b0aa31c9c01fa393ff
parent037994f9835cafe248e8a78e4cb875f01116f1ef (diff)
[Tool] Adding tool to setup passwordless ssh from glusto-test conf file.
As glusto-tests needs passwordless ssh configured for all severs and clients. This can sometime be an issue when you have a large number of nodes. Adding this tool would enable us to setup passwordless ssh to all the nodes from any given glusto-tests config file. The tool is a simple python3 commandline tool which will take glusto-tests config file and password and use sshpass and ssh-copy-id to setup passwordless ssh to all nodes from the master node. Pasting the help menu of the tool to give a better picture of what can be done with the tool. usage: setup_passwordless_ssh [-h] [-c CONFIG_FILE] [-p PASSWORD] [-u USERNAME] Tool to setup passwordless ssh to all nodes. optional arguments: -h, --help show this help message and exit -c CONFIG_FILE, --config_file CONFIG_FILE A glusto-tests configuration file. -p PASSWORD, --password PASSWORD Password of servers. -u USERNAME, --username USERNAME User to be used to setup passwordless ssh. Change-Id: I491cdd975719e29b7e8f43ce548b42f2ad59a4b9 Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
-rw-r--r--tools/setup_passwordless_ssh/README.md47
-rw-r--r--tools/setup_passwordless_ssh/setup.py31
-rw-r--r--tools/setup_passwordless_ssh/setup_passwordless_ssh.py147
3 files changed, 225 insertions, 0 deletions
diff --git a/tools/setup_passwordless_ssh/README.md b/tools/setup_passwordless_ssh/README.md
new file mode 100644
index 0000000..c122d37
--- /dev/null
+++ b/tools/setup_passwordless_ssh/README.md
@@ -0,0 +1,47 @@
+# setup_passwordless_ssh
+This is a tool to setup passwordless ssh to all nodes. It takes a glusto-tests
+config file and password as input.
+
+## Prerequisites
+1. Python 3.x
+2. All the servers should have the same password.
+3. Install sshpass on the control node.
+
+```
+# yum install sshpass
+```
+
+## Installation
+Download the project files from github.
+
+```
+# git clone https://github.com/gluster/glusto-tests.git
+```
+Change directory to the project directory.
+
+```
+# cd glusto-tests/tool/setup_passwordless_ssh/
+```
+Now run the installation script.
+
+```
+# python3 setup.py install
+```
+To check run:
+
+```
+setup_passwordless_ssh --help
+```
+
+## Usage
+To use this you need to have a valid glusto-tests config file([Sample file](https://github.com/gluster/glusto-tests/tree/master/tests/))
+after which just run the tool as shown below:
+
+```
+# setup_passwordless_ssh -c <Config file> -p <Password>
+```
+If you wish to establish passwordless ssh for a non-root user use `-u` or
+`--username` option followed by the username.
+
+## License
+[GPLv3](https://github.com/gluster/glusto-tests/blob/master/LICENSE) \ No newline at end of file
diff --git a/tools/setup_passwordless_ssh/setup.py b/tools/setup_passwordless_ssh/setup.py
new file mode 100644
index 0000000..6a8a499
--- /dev/null
+++ b/tools/setup_passwordless_ssh/setup.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+# 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
+# the Free Software Foundation; either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY :or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+from setuptools import setup
+
+setup(
+ name='setup_passwordless_ssh',
+ author='Red Hat, Inc.',
+ author_email='gluster-devel@gluster.org',
+ url='http://www.gluster.org',
+ license='GPLv3+',
+ description=("Tool to setup passwordless ssh to all nodes."),
+ py_modules=['setup_passwordless_ssh'],
+ entry_points="""
+ [console_scripts]
+ setup_passwordless_ssh = setup_passwordless_ssh:main
+ """
+)
diff --git a/tools/setup_passwordless_ssh/setup_passwordless_ssh.py b/tools/setup_passwordless_ssh/setup_passwordless_ssh.py
new file mode 100644
index 0000000..e9a619c
--- /dev/null
+++ b/tools/setup_passwordless_ssh/setup_passwordless_ssh.py
@@ -0,0 +1,147 @@
+#!/usr/bin/env python3
+# 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
+# the Free Software Foundation; either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY :or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import argparse
+import sys
+from os import system
+from yaml import safe_load
+
+
+def read_config_file(config_file):
+ """
+ A function to read the yaml file given to the script.
+ Args:
+ config_file(str): A config file used to run glusto-tests.
+ Return:
+ dict: A dictornary with all the details from config file.
+ """
+ return safe_load(open(config_file, 'r'))
+
+
+def setup_passwordless_ssh(server, username, password):
+ """
+ A function to setup passwordless ssh to all servers.
+ Args:
+ server(str): hostname/IP of server for
+ passwordless ssh has to be configured.
+ username(str): User to be used to login.
+ password(str): password to be used to login.
+ Returns:
+ bool: True if successful else false.
+ """
+ command = ("sshpass -p %s ssh-copy-id -o StrictHostKeyChecking=no %s@%s"
+ % (password, username, server))
+ ret = system(command)
+ return not ret
+
+
+def check_passwordless_ssh_setup(server, username):
+ """
+ A function to check if passwordless ssh setup was successfull or not.
+ Args:
+ server(str): hostname/IP of server for
+ passwordless ssh has to be configured.
+ username(str): User to be used to login.
+ Returns:
+ bool: True if successful else false.
+ """
+ command = ("ssh %s@%s hostname" % (username, server))
+ ret = system(command)
+ return not ret
+
+
+def main():
+ """
+ Main function of the tool.
+ """
+
+ # Setting up command line arguments.
+ parser = argparse.ArgumentParser(
+ description="Tool to setup passwordless ssh to all nodes."
+ )
+ parser.add_argument("-c", "--config_file",
+ type=str, dest="config_file",
+ help="A glusto-tests configuration file.")
+ parser.add_argument("-p", "--password", dest="password",
+ type=str, help="Password of servers.")
+ parser.add_argument("-u", "--username", dest="username",
+ type=str, default="root",
+ help="User to be used to setup"
+ " passwordless ssh.")
+ args = parser.parse_args()
+
+ # Reading the config file.
+ if args.config_file:
+ config = read_config_file(args.config_file)
+ else:
+ sys.exit("[ERROR]:Config file not provided.")
+
+ # Checking if password was provided.
+ if args.password:
+ password = args.password
+ else:
+ sys.exit("[ERROR]:Password not provided.")
+
+ # Configuring passwordless ssh to all servers.
+ for server in config.get('servers', []):
+ ret = setup_passwordless_ssh(server, args.username,
+ password)
+ if not ret:
+ sys.exit("[ERROR]:Unable to setup "
+ "passwordless ssh to %s."
+ % server)
+ ret = check_passwordless_ssh_setup(server,
+ args.username)
+ if ret:
+ print("[INFO]:Passwordless ssh setup "
+ "completed to %s." % server)
+
+ # Configuring passwordless ssh to all clients.
+ for server in config.get('clients', []):
+ ret = setup_passwordless_ssh(server,
+ args.username,
+ password)
+
+ if not ret:
+ sys.exit("[ERROR]:Unable to setup "
+ "passwordless ssh to %s."
+ % server)
+
+ ret = check_passwordless_ssh_setup(server,
+ args.username)
+ if ret:
+ print("[INFO]:Passwordless ssh setup "
+ "completed to %s." % server)
+
+ # Configure paswordless ssh to all geo-rep slaves nodes.
+ for server in config.get('slaves', []):
+ ret = setup_passwordless_ssh(server,
+ args.username,
+ password)
+ if not ret:
+ sys.exit("[ERROR]:Unable to setup "
+ "passwordless ssh to %s."
+ % server)
+ ret = check_passwordless_ssh_setup(server,
+ args.username)
+ if ret:
+ print("[INFO]:Passwordless ssh setup "
+ "completed to %s." % server)
+
+
+if __name__ == "__main__":
+ main()