Merge "HyperV: Remove RDP console connection information API"
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
    "os-getRDPConsole": {
 | 
			
		||||
        "type": "rdp-html5"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
    "os-getRDPConsole": {
 | 
			
		||||
        "type": "rdp-html5"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "remote_console": {
 | 
			
		||||
        "protocol": "serial",
 | 
			
		||||
        "type": "serial"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user