From 3a929611c0ec5dd8e7bf24692984d1df8b9a97f8 Mon Sep 17 00:00:00 2001 From: Hugh Saunders Date: Fri, 25 Nov 2016 11:44:13 +0000 Subject: compute: Pass through args to ssh Why limit a user to preset ssh arguments? Capture them all and send them along to ssh to deal with. This allows users to use the full range of ssh arguments, including specifying a command to run on the instance. For example: openstack server ssh -4 upg -- -l cirros -i ~/id_rsa_upg "date; uptime" SSH arguments that openstackclient currently mirrors are deprecated except for -4 and -6, as they are useful for retrieving the correct instance IP. Change-Id: Ia50786d5eee52688e180550fe16aeb8af610154b Co-authored-by: Stephen Finucane --- .../tests/unit/compute/v2/test_server.py | 50 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'openstackclient/tests') diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index acff61e6..3f7ad04a 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -8307,15 +8307,48 @@ class TestServerSsh(TestServer): ('ipv6', False), ('address_type', 'public'), ('verbose', False), + ('ssh_args', []), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - result = self.cmd.take_action(parsed_args) + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + result = self.cmd.take_action(parsed_args) + + self.assertIsNone(result) + mock_exec.assert_called_once_with('ssh 192.168.1.30 -l cloud') + mock_warning.assert_not_called() + + def test_server_ssh_passthrough_opts(self, mock_exec): + arglist = [ + self.server.name, + '--', + '-l', 'username', + '-p', '2222', + ] + verifylist = [ + ('server', self.server.name), + ('login', None), + ('port', None), + ('identity', None), + ('option', None), + ('ipv4', False), + ('ipv6', False), + ('address_type', 'public'), + ('verbose', False), + ('ssh_args', ['-l', 'username', '-p', '2222']), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + result = self.cmd.take_action(parsed_args) self.assertIsNone(result) - mock_exec.assert_called_once_with('ssh cloud@192.168.1.30') + mock_exec.assert_called_once_with( + 'ssh 192.168.1.30 -l username -p 2222' + ) + mock_warning.assert_not_called() - def test_server_ssh_opts(self, mock_exec): + def test_server_ssh_deprecated_opts(self, mock_exec): arglist = [ self.server.name, '-l', 'username', @@ -8331,14 +8364,21 @@ class TestServerSsh(TestServer): ('ipv6', False), ('address_type', 'public'), ('verbose', False), + ('ssh_args', []), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - result = self.cmd.take_action(parsed_args) + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + result = self.cmd.take_action(parsed_args) self.assertIsNone(result) mock_exec.assert_called_once_with( - 'ssh -p 2222 username@192.168.1.30' + 'ssh 192.168.1.30 -p 2222 -l username' + ) + mock_warning.assert_called_once() + self.assertIn( + 'The ssh options have been deprecated.', + mock_warning.call_args[0][0], ) -- cgit v1.2.1