From d84e10347eb42ffca7d5d761e0f7af447f3e2ef7 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 5 Jun 2013 15:41:37 +0200 Subject: tests: Allow public keys for authentication to the remote machines Part of the work for https://fedorahosted.org/freeipa/ticket/3621 --- ipatests/test_integration/host.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'ipatests/test_integration/host.py') diff --git a/ipatests/test_integration/host.py b/ipatests/test_integration/host.py index da5546de..b4d736cd 100644 --- a/ipatests/test_integration/host.py +++ b/ipatests/test_integration/host.py @@ -145,6 +145,7 @@ class Host(object): self.role = 'other' self.root_password = self.config.root_password + self.root_ssh_key_filename = self.config.root_ssh_key_filename self.host_key = None self.ssh_port = 22 @@ -233,8 +234,19 @@ class Host(object): except AttributeError: sock = socket.create_connection((self.hostname, self.ssh_port)) self._transport = transport = paramiko.Transport(sock) - transport.connect(hostkey=self.host_key, username='root', - password=self.root_password) + transport.connect(hostkey=self.host_key) + if self.root_ssh_key_filename: + self.log.debug('Authenticating with private RSA key') + filename = os.path.expanduser(self.root_ssh_key_filename) + key = paramiko.RSAKey.from_private_key_file(filename) + transport.auth_publickey(username='root', key=key) + elif self.root_password: + self.log.debug('Authenticating with password') + transport.auth_password(username='root', + password=self.root_password) + else: + self.log.critical('No SSH credentials configured') + raise RuntimeError('No SSH credentials configured') return transport @property -- cgit