[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:07:44 UTC 2016
Greetings,
Sending the modified patch where there is an assertion when per host
username/password is used in OpenSSH mode.
Regards
Niranjan
-------------- next part --------------
From abfdda3cf8e4839b397ad82f61a8249317e10fba 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 | 12 ++++++++++--
2 files changed, 19 insertions(+), 5 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..e893e485425632729fa46fa81b3446d5d32d682b 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',
--
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/d438709f/attachment.sig>
More information about the Freeipa-devel
mailing list