提交 7ef1d659 编写于 作者: L Lucas Meneghel Rodrigues 提交者: Cleber Rosa

avocado remote plugin: Add support to identity files

Add support for identity files as valid SSH options
to our remote plugin. The use case for this is connecting
to Amazon EC2 instances using the provided keypair (.pem
files).

avocado run --remote-hostname my-machine.com --remote-username myuser --remote-key-file /path/to/myfile.pem passtest
Signed-off-by: NLucas Meneghel Rodrigues <lookkas@gmail.com>
上级 e1ceb496
......@@ -83,11 +83,12 @@ class RemoteTestRunner(TestRunner):
self.job.args.remote_hostname,
self.job.args.remote_port,
self.job.args.remote_timeout)
self.remote = remoter.Remote(self.job.args.remote_hostname,
self.job.args.remote_username,
self.job.args.remote_password,
self.job.args.remote_port,
self.job.args.remote_timeout)
self.remote = remoter.Remote(hostname=self.job.args.remote_hostname,
username=self.job.args.remote_username,
password=self.job.args.remote_password,
key_filename=self.job.args.remote_key_file,
port=self.job.args.remote_port,
timeout=self.job.args.remote_timeout)
def check_remote_avocado(self):
"""
......@@ -296,6 +297,7 @@ class VMTestRunner(RemoteTestRunner):
self.job.args.remote_port = self.job.args.vm_port
self.job.args.remote_username = self.job.args.vm_username
self.job.args.remote_password = self.job.args.vm_password
self.job.args.remote_key_file = self.job.args.vm_key_file
self.job.args.remote_no_copy = self.job.args.vm_no_copy
self.job.args.remote_timeout = self.job.args.vm_timeout
super(VMTestRunner, self).setup()
......
......@@ -52,13 +52,16 @@ class Remote(object):
"""
def __init__(self, hostname, username=None, password=None,
port=22, timeout=60, attempts=10, quiet=False):
key_filename=None, port=22, timeout=60, attempts=10,
quiet=False):
"""
Creates an instance of :class:`Remote`.
:param hostname: the hostname.
:param username: the username. Default: autodetect.
:param password: the password. Default: try to use public key.
:param key_filename: path to an identity file (Example: .pem files
from Amazon EC2).
:param timeout: remote command timeout, in seconds. Default: 60.
:param attempts: number of attempts to connect. Default: 10.
:param quiet: performs quiet operations. Default: True.
......@@ -67,6 +70,7 @@ class Remote(object):
if username is None:
username = getpass.getuser()
self.username = username
self.key_filename = key_filename
# None = use public key
self.password = password
self.port = port
......@@ -82,6 +86,7 @@ class Remote(object):
self._setup_environment(host_string=hostname,
user=username,
password=password,
key_filename=key_filename,
port=port,
timeout=timeout / attempts,
connection_attempts=attempts,
......
......@@ -64,6 +64,11 @@ class Remote(CLI):
dest='remote_password', default=None,
help='Specify the password to login on'
' remote machine')
self.remote_parser.add_argument('--remote-key-file',
dest='remote_key_file', default=None,
help='Specify an identity file with '
'a private key instead of a password '
'(Example: .pem files from Amazon EC2)')
self.remote_parser.add_argument('--remote-no-copy',
dest='remote_no_copy',
action='store_true',
......
......@@ -66,6 +66,11 @@ class VM(CLI):
self.vm_parser.add_argument('--vm-password',
default=None,
help='Specify the password to login on VM')
self.vm_parser.add_argument('--vm-key-file',
dest='vm_key_file', default=None,
help='Specify an identity file with '
'a private key instead of a password '
'(Example: .pem files from Amazon EC2)')
self.vm_parser.add_argument('--vm-cleanup',
action='store_true', default=False,
help='Restore VM to a previous state, '
......
......@@ -34,6 +34,7 @@ class RemoteTestRunnerTest(unittest.TestCase):
remote_hostname='hostname',
remote_port=22,
remote_password='password',
remote_key_file=None,
remote_no_copy=False,
remote_timeout=60,
show_job_log=False,
......@@ -154,7 +155,8 @@ class RemoteTestRunnerSetup(unittest.TestCase):
Remote = flexmock()
remote_remote = flexmock(remoter)
(remote_remote.should_receive('Remote')
.with_args('hostname', 'username', 'password', 22, 60)
.with_args(hostname='hostname', username='username',
password='password', key_filename=None, port=22, timeout=60)
.once().ordered()
.and_return(Remote))
Args = flexmock(test_result_total=1,
......@@ -164,6 +166,7 @@ class RemoteTestRunnerSetup(unittest.TestCase):
remote_hostname='hostname',
remote_port=22,
remote_password='password',
remote_key_file=None,
remote_no_copy=False,
remote_timeout=60,
show_job_log=False)
......
......@@ -35,6 +35,7 @@ class VMTestRunnerSetup(unittest.TestCase):
vm_hostname='hostname',
vm_port=22,
vm_password='password',
vm_key_file=None,
vm_cleanup=True,
vm_no_copy=False,
vm_timeout=120,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册