diff options
| author | Hugh Saunders <hugh@wherenow.org> | 2016-11-25 11:44:13 +0000 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2021-12-15 17:41:58 +0000 |
| commit | 3a929611c0ec5dd8e7bf24692984d1df8b9a97f8 (patch) | |
| tree | ee49f7fbe03aca03e60dd76ba0927064181d00ae /openstackclient/tests | |
| parent | ba69870d86b5840dec06c6c30c8ddf50398bdb44 (diff) | |
| download | python-openstackclient-3a929611c0ec5dd8e7bf24692984d1df8b9a97f8.tar.gz | |
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 <stephen@that.guru>
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_server.py | 50 |
1 files changed, 45 insertions, 5 deletions
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], ) |
