diff --git a/lower-constraints.txt b/lower-constraints.txt index 74eac6403b..52766b2290 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -5,7 +5,7 @@ asn1crypto==0.23.0 bandit==1.1.0 cachetools==2.0.0 cffi==1.14.0 -cliff==2.8.0 +cliff==3.4.0 cmd2==0.8.0 contextlib2==0.4.0 coverage==4.0 @@ -48,7 +48,7 @@ netifaces==0.10.4 openstacksdk==0.48.0 os-service-types==1.7.0 os-testr==1.0.0 -osc-lib==2.0.0 +osc-lib==2.2.0 osc-placement==1.7.0 oslo.concurrency==3.26.0 oslo.config==5.2.0 diff --git a/openstackclient/compute/v2/console.py b/openstackclient/compute/v2/console.py index f0abaf4cf4..0ab5c8a2a3 100644 --- a/openstackclient/compute/v2/console.py +++ b/openstackclient/compute/v2/console.py @@ -22,6 +22,15 @@ from osc_lib import utils from openstackclient.i18n import _ +def _get_console_columns(item): + # To maintain backwards compatibility we need to rename sdk props to + # whatever OSC was using before + column_map = {} + hidden_columns = ['id', 'links', 'location', 'name'] + return utils.get_osc_show_columns_for_sdk_resource( + item, column_map, hidden_columns) + + class ShowConsoleLog(command.Command): _description = _("Show server's console output") @@ -119,21 +128,15 @@ class ShowConsoleURL(command.ShowOne): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute - server = utils.find_resource( - compute_client.servers, + compute_client = self.app.client_manager.sdk_connection.compute + server = compute_client.find_server( parsed_args.server, - ) + ignore_missing=False) - data = server.get_console_url(parsed_args.url_type) - if not data: - return ({}, {}) + data = compute_client.create_console(server.id, + console_type=parsed_args.url_type) - info = {} - # NOTE(Rui Chen): Return 'remote_console' in compute microversion API - # 2.6 and later, return 'console' in compute - # microversion API from 2.0 to 2.5, do compatibility - # handle for different microversion API. - console_data = data.get('remote_console', data.get('console')) - info.update(console_data) - return zip(*sorted(info.items())) + display_columns, columns = _get_console_columns(data) + data = utils.get_dict_properties(data, columns) + + return (display_columns, data) diff --git a/openstackclient/tests/unit/compute/v2/test_console.py b/openstackclient/tests/unit/compute/v2/test_console.py index 1c6d658bc1..db9603c9b9 100644 --- a/openstackclient/tests/unit/compute/v2/test_console.py +++ b/openstackclient/tests/unit/compute/v2/test_console.py @@ -32,9 +32,6 @@ class TestConsole(compute_fakes.TestComputev2): self.sdk_client.find_server = mock.Mock() self.sdk_client.get_server_console_output = mock.Mock() - self.servers_mock = self.app.client_manager.compute.servers - self.servers_mock.reset_mock() - class TestConsoleLog(TestConsole): _server = compute_fakes.FakeServer.create_one_server() @@ -107,18 +104,16 @@ class TestConsoleLog(TestConsole): class TestConsoleUrlShow(TestConsole): + _server = compute_fakes.FakeServer.create_one_server() def setUp(self): super(TestConsoleUrlShow, self).setUp() - fake_console_data = {'remote_console': {'url': 'http://localhost', - 'protocol': 'fake_protocol', - 'type': 'fake_type'}} - methods = { - 'get_console_url': fake_console_data - } - self.fake_server = compute_fakes.FakeServer.create_one_server( - methods=methods) - self.servers_mock.get.return_value = self.fake_server + self.sdk_client.find_server.return_value = self._server + fake_console_data = {'url': 'http://localhost', + 'protocol': 'fake_protocol', + 'type': 'fake_type'} + self.sdk_client.create_console = mock.Mock( + return_value=fake_console_data) self.columns = ( 'protocol', @@ -126,9 +121,9 @@ class TestConsoleUrlShow(TestConsole): 'url', ) self.data = ( - fake_console_data['remote_console']['protocol'], - fake_console_data['remote_console']['type'], - fake_console_data['remote_console']['url'] + fake_console_data['protocol'], + fake_console_data['type'], + fake_console_data['url'] ) self.cmd = console.ShowConsoleURL(self.app, None) @@ -143,7 +138,9 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with('novnc') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='novnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -158,7 +155,9 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with('novnc') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='novnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -173,7 +172,9 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with('xvpvnc') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='xvpvnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -188,41 +189,12 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with( - 'spice-html5') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='spice-html5') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) - def test_console_url_show_compatible(self): - methods = { - 'get_console_url': {'console': {'url': 'http://localhost', - 'type': 'fake_type'}}, - } - old_fake_server = compute_fakes.FakeServer.create_one_server( - methods=methods) - old_columns = ( - 'type', - 'url', - ) - old_data = ( - methods['get_console_url']['console']['type'], - methods['get_console_url']['console']['url'] - ) - arglist = [ - 'foo_vm', - ] - verifylist = [ - ('url_type', 'novnc'), - ('server', 'foo_vm'), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - with mock.patch.object(self.servers_mock, 'get', - return_value=old_fake_server): - columns, data = self.cmd.take_action(parsed_args) - old_fake_server.get_console_url.assert_called_once_with('novnc') - self.assertEqual(old_columns, columns) - self.assertEqual(old_data, data) - def test_console_url_show_with_rdp(self): arglist = [ '--rdp', @@ -234,8 +206,9 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with( - 'rdp-html5') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='rdp-html5') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -250,8 +223,9 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with( - 'serial') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='serial') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -266,6 +240,8 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_console_url.assert_called_once_with('webmks') + self.sdk_client.create_console.assert_called_once_with( + self._server.id, + console_type='webmks') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/requirements.txt b/requirements.txt index ee6b6241ae..99d409bf51 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,10 +3,10 @@ # process, which may cause wedges in the gate later. pbr!=2.1.0,>=2.0.0 # Apache-2.0 -cliff!=2.9.0,>=2.8.0 # Apache-2.0 +cliff>=3.4.0 # Apache-2.0 iso8601>=0.1.11 # MIT openstacksdk>=0.48.0 # Apache-2.0 -osc-lib>=2.0.0 # Apache-2.0 +osc-lib>=2.2.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 python-keystoneclient>=3.22.0 # Apache-2.0 python-novaclient>=15.1.0 # Apache-2.0