diff --git a/api-ref/source/os-consoles.inc b/api-ref/source/os-consoles.inc index f6bc8fa02464..6da4231d39cc 100644 --- a/api-ref/source/os-consoles.inc +++ b/api-ref/source/os-consoles.inc @@ -146,7 +146,8 @@ Show Console Authentication Token Given the console authentication token for a server instance, shows the related connection information. -This method is available for ``rdp-html5`` console type only. +This method used to be available just for the ``rdp-html5`` console type prior +microversion 2.31. Now it's available for all console types. Normal response codes: 200 diff --git a/doc/api_samples/versions/v21-version-get-resp.json b/doc/api_samples/versions/v21-version-get-resp.json index d8e1bb45c7c0..616ce04d7a20 100644 --- a/doc/api_samples/versions/v21-version-get-resp.json +++ b/doc/api_samples/versions/v21-version-get-resp.json @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.30", + "version": "2.31", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index 78626ded0a56..bc03195a925c 100644 --- a/doc/api_samples/versions/versions-get-resp.json +++ b/doc/api_samples/versions/versions-get-resp.json @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.30", + "version": "2.31", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index da90b07d3f64..38d2aab2988a 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -79,6 +79,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: behaviour for the host flag by calling the scheduler. * 2.30 - Add a force flag in live-migrate request body and change the behaviour for the host flag by calling the scheduler. + * 2.31 - Fix os-console-auth-tokens to work for all console types. """ # The minimum and maximum versions of the API supported @@ -87,7 +88,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: # Note(cyeoh): This only applies for the v2.1 API once microversions # support is fully merged. It does not affect the V2 API. _MIN_API_VERSION = "2.1" -_MAX_API_VERSION = "2.30" +_MAX_API_VERSION = "2.31" DEFAULT_API_VERSION = _MIN_API_VERSION diff --git a/nova/api/openstack/compute/console_auth_tokens.py b/nova/api/openstack/compute/console_auth_tokens.py index f7e4b514bb16..8eda3b85eb61 100644 --- a/nova/api/openstack/compute/console_auth_tokens.py +++ b/nova/api/openstack/compute/console_auth_tokens.py @@ -29,8 +29,7 @@ class ConsoleAuthTokensController(wsgi.Controller): self._consoleauth_rpcapi = consoleauth_rpcapi.ConsoleAuthAPI() super(ConsoleAuthTokensController, self).__init__(*args, **kwargs) - @extensions.expected_errors((400, 401, 404)) - def show(self, req, id): + def _show(self, req, id, rdp_only): """Checks a console auth token and returns the related connect info.""" context = req.environ['nova.context'] authorize(context) @@ -45,8 +44,8 @@ class ConsoleAuthTokensController(wsgi.Controller): raise webob.exc.HTTPNotFound(explanation=_("Token not found")) console_type = connect_info.get('console_type') - # This is currently required only for RDP consoles - if console_type != "rdp-html5": + + if rdp_only and console_type != "rdp-html5": raise webob.exc.HTTPUnauthorized( explanation=_("The requested console type details are not " "accessible")) @@ -57,6 +56,16 @@ class ConsoleAuthTokensController(wsgi.Controller): 'internal_access_path'] if i in connect_info}} + @wsgi.Controller.api_version("2.1", "2.30") + @extensions.expected_errors((400, 401, 404)) + def show(self, req, id): + return self._show(req, id, True) + + @wsgi.Controller.api_version("2.31") # noqa + @extensions.expected_errors((400, 404)) + def show(self, req, id): + return self._show(req, id, False) + class ConsoleAuthTokens(extensions.V21APIExtensionBase): """Console token authentication support.""" diff --git a/nova/api/openstack/rest_api_version_history.rst b/nova/api/openstack/rest_api_version_history.rst index 66daa3504f6b..e9674f997eb2 100644 --- a/nova/api/openstack/rest_api_version_history.rst +++ b/nova/api/openstack/rest_api_version_history.rst @@ -318,3 +318,9 @@ user documentation. Also changes the live-migrate action behaviour when providing a ``host`` string field by calling the nova scheduler to verify the provided host unless the ``force`` attribute is set. + +2.31 +---- + + Fix os-console-auth-tokens to return connection info for all types of tokens, + not just RDP. 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 ce5d96de81de..002cc6611d36 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 @@ -15,8 +15,10 @@ import copy +import mock import webob +from nova.api.openstack import api_version_request from nova.api.openstack.compute import console_auth_tokens \ as console_auth_tokens_v21 from nova.consoleauth import rpcapi as consoleauth_rpcapi @@ -71,8 +73,26 @@ class ConsoleAuthTokensExtensionTestV21(test.NoDBTestCase): self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, self.req, fakes.FAKE_UUID) - def test_get_console_connect_info_unauthorized_console_type(self): + def test_get_console_connect_info_nonrdp_console_type(self): self.stubs.Set(consoleauth_rpcapi.ConsoleAuthAPI, 'check_token', _fake_check_token_unauthorized) self.assertRaises(webob.exc.HTTPUnauthorized, self.controller.show, self.req, fakes.FAKE_UUID) + + +class ConsoleAuthTokensExtensionTestV231(ConsoleAuthTokensExtensionTestV21): + + def setUp(self): + super(ConsoleAuthTokensExtensionTestV231, self).setUp() + self.req.api_version_request = api_version_request.APIVersionRequest( + '2.31') + + @mock.patch.object(consoleauth_rpcapi.ConsoleAuthAPI, 'check_token') + def test_get_console_connect_info_nonrdp_console_type(self, mock_check): + mock_check.return_value = {'instance_uuid': 'fake_instance_uuid', + 'host': 'fake_host', + 'port': 'fake_port', + 'internal_access_path': 'fake_access_path', + 'console_type': 'webmks'} + output = self.controller.show(self.req, fakes.FAKE_UUID) + self.assertEqual(self._EXPECTED_OUTPUT, output) diff --git a/releasenotes/notes/bp-fix-console-auth-tokens-16b1b1b402dca362.yaml b/releasenotes/notes/bp-fix-console-auth-tokens-16b1b1b402dca362.yaml new file mode 100644 index 000000000000..1ff74db57440 --- /dev/null +++ b/releasenotes/notes/bp-fix-console-auth-tokens-16b1b1b402dca362.yaml @@ -0,0 +1,4 @@ +--- +features: + - Fix os-console-auth-tokens API to return connection info for all types + of tokens, not just RDP.