[Freeipa-devel] [python-pytest-multihost] Request to add support to specify username/password for each host
Niranjan
mrniranjan at fedoraproject.org
Mon Feb 29 16:57:49 UTC 2016
Greetings,
Attached wrong patch in my last mail. Request to review the patch
attached to this email
Regards
Niranjan
-------------- next part --------------
From 0bed8ae52972b782158394179b868a9ff028b5e6 Mon Sep 17 00:00:00 2001
From: Niranjan MR <mrniranjan at fedoraproject.org>
Date: Fri, 26 Feb 2016 15:30:25 +0530
Subject: [PATCH] Add support to specify usernames/password per host
Per Host username/password is supported when used with
Paramiko and not supported in OpenSSH Mode
https://fedorahosted.org/python-pytest-multihost/ticket/5
Signed-off-by: Niranjan MR <mrniranjan at fedoraproject.org>
---
pytest_multihost/host.py | 12 +++++++++---
pytest_multihost/transport.py | 16 +++++++++++++---
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/pytest_multihost/host.py b/pytest_multihost/host.py
index f3346f60e3c48d79e85f88aa2387e4c89ee38f08..7885722535bc260a758acc1e8ad2f98a0483b48a 100644
--- a/pytest_multihost/host.py
+++ b/pytest_multihost/host.py
@@ -26,10 +26,13 @@ class BaseHost(object):
"""
transport_class = None
- def __init__(self, domain, hostname, role, ip=None,
- external_hostname=None):
+ def __init__(self, domain, hostname, role,
+ username=None, password=None,
+ ip=None, external_hostname=None):
self.domain = domain
self.role = str(role)
+ self.username = username
+ self.password = password
shortname, dot, ext_domain = hostname.partition('.')
self.shortname = shortname
@@ -109,9 +112,12 @@ class BaseHost(object):
ip = dct.pop('ip', None)
external_hostname = dct.pop('external_hostname', None)
+ username = dct.pop('username', None)
+ password = dct.pop('password', None)
+
check_config_dict_empty(dct, 'host %s' % hostname)
- return cls(domain, hostname, role, ip, external_hostname)
+ return cls(domain, hostname, role, username, password, ip, external_hostname)
def to_dict(self):
"""Export info about this Host to a dict"""
diff --git a/pytest_multihost/transport.py b/pytest_multihost/transport.py
index eda71cd98ffe46d0d8927c10c391743345968751..0906683d2e04f16944d508e8fe410534b850c0ea 100644
--- a/pytest_multihost/transport.py
+++ b/pytest_multihost/transport.py
@@ -177,11 +177,19 @@ class ParamikoTransport(Transport):
host.ssh_port))
self._transport = transport = paramiko.Transport(sock)
transport.connect(hostkey=host.host_key)
+ if host.password:
+ self.log.debug('Authenticating with password set in host section')
+ transport.auth_password(username=host.username,
+ password=host.password)
if host.ssh_key_filename:
- self.log.debug('Authenticating with private RSA key')
filename = os.path.expanduser(host.ssh_key_filename)
key = paramiko.RSAKey.from_private_key_file(filename)
- transport.auth_publickey(username=host.ssh_username, key=key)
+ if host.username:
+ self.log.debug('Authenticating with private RSA key using user %s' % ( host.username))
+ transport.auth_publickey(username=host.username, key=key)
+ else:
+ self.log.debug('Authenticating with private RSA key')
+ transport.auth_publickey(username=host.ssh_username, key=key)
elif host.ssh_password:
self.log.debug('Authenticating with password')
transport.auth_password(username='root',
@@ -303,7 +311,9 @@ class OpenSSHTransport(Transport):
'-o', 'ControlPath=%s' % control_file,
'-o', 'StrictHostKeyChecking=no',
'-o', 'UserKnownHostsFile=%s' % known_hosts_file]
-
+ if host.username:
+ self.log.critical('Per Host Username/Password is not supported')
+ raise RuntimeError('Per Host Username/Password is not supported with OpenSSH Mode')
if self.host.ssh_key_filename:
key_filename = os.path.expanduser(self.host.ssh_key_filename)
argv.extend(['-i', key_filename])
--
1.9.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 311 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20160229/8dd54657/attachment.sig>
More information about the Freeipa-devel
mailing list