[Freeipa-devel] [python-pytest-multihost] Request to add support to specify username/password for each host

Niranjan mrniranjan at fedoraproject.org
Mon Feb 29 11:26:31 UTC 2016


Niranjan wrote:
> Greetings,
> 
> Request to review the patch for 
> https://fedorahosted.org/python-pytest-multihost/ticket/5
> 
> Regards
> Niranjan
> 

> From 28cd560f58b96817306a6eae6976e26166a9351a 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
> 
> 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 f3346f6..7885722 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 eda71cd..e893e48 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
> 

Greetings,

I have modified the subject to include python-pytest-multihost. The attached
patch adds support to include username/password or just username with
ssh_key_filename under each host in a domain. This helps specifically in cases
where we have AD (windows with openssh/cygwin installed) and we need to connect
using username "Administrator".

Also note that that this patch only works in cases where paramiko is used. This 
patch doesn't work in cases where openssh is used. 

> -- 
> Manage your subscription for the Freeipa-devel mailing list:
> https://www.redhat.com/mailman/listinfo/freeipa-devel
> Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

-------------- 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/00358b0d/attachment.sig>


More information about the Freeipa-devel mailing list