diff --git a/avocado/core/remote/runner.py b/avocado/core/remote/runner.py index 704b238bef96432a6fcbeebfc8e76af3cbf6f45f..b8d1c75316d635195ee954599a9edd4c6210a6c7 100644 --- a/avocado/core/remote/runner.py +++ b/avocado/core/remote/runner.py @@ -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() diff --git a/avocado/core/remoter.py b/avocado/core/remoter.py index 5d80ed9746b67ed18bd3166288e0d2b6992091c6..0bc3794138f7803cbde9560d6dd5a12fea6c1b16 100644 --- a/avocado/core/remoter.py +++ b/avocado/core/remoter.py @@ -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, diff --git a/avocado/plugins/remote.py b/avocado/plugins/remote.py index 3b5962c20e41552976a0cc94de9fc1b0dc4ef611..c8f303bfb6a9b447868ba8c13bf3747a0ca06c57 100644 --- a/avocado/plugins/remote.py +++ b/avocado/plugins/remote.py @@ -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', diff --git a/avocado/plugins/vm.py b/avocado/plugins/vm.py index a853f4be7ddfe7e47545c9161b57839f4ffb084b..03f48abd48c6e079d03d61992c92dd5350cf6791 100644 --- a/avocado/plugins/vm.py +++ b/avocado/plugins/vm.py @@ -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, ' diff --git a/selftests/unit/test_remote.py b/selftests/unit/test_remote.py index 052ffb9d374f23d91e53a79fc3c3200158658851..4b738d06a450709b72eb1f89cdc0d2f5e2d38059 100644 --- a/selftests/unit/test_remote.py +++ b/selftests/unit/test_remote.py @@ -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) diff --git a/selftests/unit/test_vm.py b/selftests/unit/test_vm.py index 8250cfad14e0caa7da057d54f22627b738dee490..6dedeedf94c74775fb13b8e2b5937ca04a4e6569 100644 --- a/selftests/unit/test_vm.py +++ b/selftests/unit/test_vm.py @@ -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,