From 3e47439a684fb452e8a4332bf1aaf57cee32f80a Mon Sep 17 00:00:00 2001 From: Ghanshyam Mann Date: Wed, 7 Feb 2024 12:18:05 -0800 Subject: [PATCH] HyperV: Remove RDP console connection information API The RDP console was only available for HyperV driver, therefore its connection information via API ``os-console-auth-tokens`` will now return HTTP ``400 (BadRequest)`` error. Starting from 2.31 microversion, this API return connection info for all other console type. Change-Id: I94e590eb4cbe3b2d8eff7fe881f7b98af8979be2 --- api-ref/source/servers-remote-consoles.inc | 8 ++-- .../get-rdp-console-post-req.json | 5 --- .../get-console-connect-info-get-resp.json | 0 .../openstack/compute/console_auth_tokens.py | 21 ++++++----- .../get-rdp-console-post-req.json.tpl | 5 --- .../v2.31/create-serial-console-req.json.tpl | 6 +++ ...get-console-connect-info-get-resp.json.tpl | 0 .../test_console_auth_tokens.py | 12 +++--- .../compute/test_console_auth_tokens.py | 37 ++++++------------- .../notes/remove-hyperv-94d5bfd8a539fe9f.yaml | 9 ++++- 10 files changed, 47 insertions(+), 56 deletions(-) delete mode 100644 doc/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json rename doc/api_samples/os-console-auth-tokens/{ => v2.31}/get-console-connect-info-get-resp.json (100%) delete mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json.tpl create mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/create-serial-console-req.json.tpl rename nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/{ => v2.31}/get-console-connect-info-get-resp.json.tpl (100%) diff --git a/api-ref/source/servers-remote-consoles.inc b/api-ref/source/servers-remote-consoles.inc index c8515d3315bc..be3876070b6f 100644 --- a/api-ref/source/servers-remote-consoles.inc +++ b/api-ref/source/servers-remote-consoles.inc @@ -64,9 +64,9 @@ Show Console Connection Information Given the console authentication token for a server, shows the related connection information. -This method used to be available only for the ``rdp-html5`` console type before -microversion 2.31. Starting from microversion 2.31 it's available for all -console types. +Nova HyperV driver has been removed therefore requests for RDP console connection +information will always return an http 400 error. Starting from microversion 2.31 +it's available for all other console types. Normal response codes: 200 @@ -94,5 +94,5 @@ Response **Example Show Console Authentication Token** -.. literalinclude:: ../../doc/api_samples/os-console-auth-tokens/get-console-connect-info-get-resp.json +.. literalinclude:: ../../doc/api_samples/os-console-auth-tokens/v2.31/get-console-connect-info-get-resp.json :language: javascript diff --git a/doc/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json b/doc/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json deleted file mode 100644 index 00956b90e4a0..000000000000 --- a/doc/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "os-getRDPConsole": { - "type": "rdp-html5" - } -} diff --git a/doc/api_samples/os-console-auth-tokens/get-console-connect-info-get-resp.json b/doc/api_samples/os-console-auth-tokens/v2.31/get-console-connect-info-get-resp.json similarity index 100% rename from doc/api_samples/os-console-auth-tokens/get-console-connect-info-get-resp.json rename to doc/api_samples/os-console-auth-tokens/v2.31/get-console-connect-info-get-resp.json diff --git a/nova/api/openstack/compute/console_auth_tokens.py b/nova/api/openstack/compute/console_auth_tokens.py index 810eb00ca3fd..4943304eb843 100644 --- a/nova/api/openstack/compute/console_auth_tokens.py +++ b/nova/api/openstack/compute/console_auth_tokens.py @@ -27,7 +27,7 @@ CONF = nova.conf.CONF class ConsoleAuthTokensController(wsgi.Controller): - def _show(self, req, id, rdp_only): + def _show(self, req, id): """Checks a console auth token and returns the related connect info.""" context = req.environ['nova.context'] context.can(cat_policies.BASE_POLICY_NAME) @@ -55,13 +55,6 @@ class ConsoleAuthTokensController(wsgi.Controller): if not connect_info: raise webob.exc.HTTPNotFound(explanation=_("Token not found")) - console_type = connect_info.console_type - - if rdp_only and console_type != "rdp-html5": - raise webob.exc.HTTPUnauthorized( - explanation=_("The requested console type details are not " - "accessible")) - return {'console': { 'instance_uuid': connect_info.instance_uuid, 'host': connect_info.host, @@ -72,9 +65,17 @@ class ConsoleAuthTokensController(wsgi.Controller): @wsgi.Controller.api_version("2.1", "2.30") @wsgi.expected_errors((400, 401, 404)) def show(self, req, id): - return self._show(req, id, True) + """Until microversion 2.30, this API was available only for the + rdp-html5 console type which has been removed along with the HyperV + driver in the Nova 29.0.0 (Caracal) release. As this method is for + microversion <=2.30, it will return an http 400 error. Starting + from 2.31 microversion, this API works for all the supported + console types that are handled by the separate show method + defined below. + """ + raise webob.exc.HTTPBadRequest() @wsgi.Controller.api_version("2.31") # noqa @wsgi.expected_errors((400, 404)) def show(self, req, id): # noqa - return self._show(req, id, False) + return self._show(req, id) diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json.tpl deleted file mode 100644 index 00956b90e4a0..000000000000 --- a/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-rdp-console-post-req.json.tpl +++ /dev/null @@ -1,5 +0,0 @@ -{ - "os-getRDPConsole": { - "type": "rdp-html5" - } -} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/create-serial-console-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/create-serial-console-req.json.tpl new file mode 100644 index 000000000000..a129e1e08c8a --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/create-serial-console-req.json.tpl @@ -0,0 +1,6 @@ +{ + "remote_console": { + "protocol": "serial", + "type": "serial" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-console-connect-info-get-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/get-console-connect-info-get-resp.json.tpl similarity index 100% rename from nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/get-console-connect-info-get-resp.json.tpl rename to nova/tests/functional/api_sample_tests/api_samples/os-console-auth-tokens/v2.31/get-console-connect-info-get-resp.json.tpl diff --git a/nova/tests/functional/api_sample_tests/test_console_auth_tokens.py b/nova/tests/functional/api_sample_tests/test_console_auth_tokens.py index fcd79d54b6f7..e9bb45866918 100644 --- a/nova/tests/functional/api_sample_tests/test_console_auth_tokens.py +++ b/nova/tests/functional/api_sample_tests/test_console_auth_tokens.py @@ -22,20 +22,22 @@ from nova.tests.functional.api_sample_tests import test_servers class ConsoleAuthTokensSampleJsonTests(test_servers.ServersSampleBase): ADMIN_API = True sample_dir = "os-console-auth-tokens" + microversion = '2.31' + scenarios = [('v2_31', {'api_major_version': 'v2.1'})] def _get_console_url(self, data): - return jsonutils.loads(data)["console"]["url"] + return jsonutils.loads(data)["remote_console"]["url"] def _get_console_token(self, uuid): - response = self._do_post('servers/%s/action' % uuid, - 'get-rdp-console-post-req', - {'action': 'os-getRDPConsole'}) + body = {'protocol': 'serial', 'type': 'serial'} + response = self._do_post('servers/%s/remote-consoles' % uuid, + 'create-serial-console-req', body) url = self._get_console_url(response.content) return re.match('.+?token=([^&]+)', url).groups()[0] def test_get_console_connect_info(self): - self.flags(enabled=True, group='rdp') + self.flags(enabled=True, group='serial_console') uuid = self._post_server() token = self._get_console_token(uuid) diff --git a/nova/tests/unit/api/openstack/compute/test_console_auth_tokens.py b/nova/tests/unit/api/openstack/compute/test_console_auth_tokens.py index a1f3d1e63d1e..8b8af21cc842 100644 --- a/nova/tests/unit/api/openstack/compute/test_console_auth_tokens.py +++ b/nova/tests/unit/api/openstack/compute/test_console_auth_tokens.py @@ -49,33 +49,11 @@ class ConsoleAuthTokensExtensionTestV21(test.NoDBTestCase): self.req = fakes.HTTPRequest.blank('', use_admin_context=True) self.context = self.req.environ['nova.context'] - @mock.patch('nova.objects.ConsoleAuthToken.validate', - return_value=objects.ConsoleAuthToken( - instance_uuid=fakes.FAKE_UUID, host='fake_host', - port='1234', internal_access_path='fake_access_path', - console_type='rdp-html5', token=fakes.FAKE_UUID)) + @mock.patch.object(objects.ConsoleAuthToken, 'validate') def test_get_console_connect_info(self, mock_validate): - output = self.controller.show(self.req, fakes.FAKE_UUID) - self.assertEqual(self._EXPECTED_OUTPUT_DB, output) - mock_validate.assert_called_once_with(self.context, fakes.FAKE_UUID) - - @mock.patch('nova.objects.ConsoleAuthToken.validate', - side_effect=exception.InvalidToken(token='***')) - def test_get_console_connect_info_token_not_found(self, mock_validate): - self.assertRaises(webob.exc.HTTPNotFound, + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.show, self.req, fakes.FAKE_UUID) - mock_validate.assert_called_once_with(self.context, fakes.FAKE_UUID) - - @mock.patch('nova.objects.ConsoleAuthToken.validate', - return_value=objects.ConsoleAuthToken( - instance_uuid=fakes.FAKE_UUID, host='fake_host', - port='1234', internal_access_path='fake_access_path', - console_type='unauthorized_console_type', - token=fakes.FAKE_UUID)) - def test_get_console_connect_info_nonrdp_console_type(self, mock_validate): - self.assertRaises(webob.exc.HTTPUnauthorized, - self.controller.show, self.req, fakes.FAKE_UUID) - mock_validate.assert_called_once_with(self.context, fakes.FAKE_UUID) + mock_validate.assert_not_called() class ConsoleAuthTokensExtensionTestV231(ConsoleAuthTokensExtensionTestV21): @@ -91,7 +69,14 @@ class ConsoleAuthTokensExtensionTestV231(ConsoleAuthTokensExtensionTestV21): port='1234', internal_access_path='fake_access_path', console_type='webmks', token=fakes.FAKE_UUID)) - def test_get_console_connect_info_nonrdp_console_type(self, mock_validate): + def test_get_console_connect_info(self, mock_validate): output = self.controller.show(self.req, fakes.FAKE_UUID) self.assertEqual(self._EXPECTED_OUTPUT_DB, output) mock_validate.assert_called_once_with(self.context, fakes.FAKE_UUID) + + @mock.patch('nova.objects.ConsoleAuthToken.validate', + side_effect=exception.InvalidToken(token='***')) + def test_get_console_connect_info_token_not_found(self, mock_validate): + self.assertRaises(webob.exc.HTTPNotFound, + self.controller.show, self.req, fakes.FAKE_UUID) + mock_validate.assert_called_once_with(self.context, fakes.FAKE_UUID) diff --git a/releasenotes/notes/remove-hyperv-94d5bfd8a539fe9f.yaml b/releasenotes/notes/remove-hyperv-94d5bfd8a539fe9f.yaml index 0bee041146e2..709408041f43 100644 --- a/releasenotes/notes/remove-hyperv-94d5bfd8a539fe9f.yaml +++ b/releasenotes/notes/remove-hyperv-94d5bfd8a539fe9f.yaml @@ -5,7 +5,14 @@ upgrade: Nova 27.2.0 (Antelope) release. This driver was untested and has no maintainers. In addition, it has a dependency on the OpenStack Winstacker project that also has been retired. - - | + + The RDP console was only available for the HyperV driver, therefore its + connection information via below API ``os-console-auth-tokens`` will now + return HTTP ``400 (BadRequest)`` error: + + * Show Console Connection Information: + GET /os-console-auth-tokens/{console_token} + The following config options which only apply for the ``HyperV`` virt driver also been removed: