Merge "api: Add response body schemas for console auth token APIs"
This commit is contained in:
@@ -67,11 +67,15 @@ class ConsoleAuthTokensController(wsgi.Controller):
|
|||||||
@wsgi.Controller.api_version("2.1", "2.30")
|
@wsgi.Controller.api_version("2.1", "2.30")
|
||||||
@wsgi.expected_errors((400, 401, 404))
|
@wsgi.expected_errors((400, 401, 404))
|
||||||
@validation.query_schema(schema.show_query)
|
@validation.query_schema(schema.show_query)
|
||||||
|
# NOTE(stephenfin): Technically this will never return a response now (as
|
||||||
|
# an exception will be raised instead) but we use the same schema for
|
||||||
|
# documentation purposes
|
||||||
|
@validation.response_body_schema(schema.show_response)
|
||||||
def show(self, req, id):
|
def show(self, req, id):
|
||||||
"""Until microversion 2.30, this API was available only for the
|
"""Until microversion 2.30, this API was available only for the
|
||||||
rdp-html5 console type which has been removed along with the HyperV
|
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
|
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
|
microversion <= 2.30, it will return an http 400 error. Starting
|
||||||
from 2.31 microversion, this API works for all the supported
|
from 2.31 microversion, this API works for all the supported
|
||||||
console types that are handled by the separate show method
|
console types that are handled by the separate show method
|
||||||
defined below.
|
defined below.
|
||||||
@@ -81,5 +85,6 @@ class ConsoleAuthTokensController(wsgi.Controller):
|
|||||||
@wsgi.Controller.api_version("2.31") # noqa
|
@wsgi.Controller.api_version("2.31") # noqa
|
||||||
@wsgi.expected_errors((400, 404))
|
@wsgi.expected_errors((400, 404))
|
||||||
@validation.query_schema(schema.show_query)
|
@validation.query_schema(schema.show_query)
|
||||||
|
@validation.response_body_schema(schema.show_response)
|
||||||
def show(self, req, id): # noqa
|
def show(self, req, id): # noqa
|
||||||
return self._show(req, id)
|
return self._show(req, id)
|
||||||
|
@@ -16,3 +16,34 @@ show_query = {
|
|||||||
'properties': {},
|
'properties': {},
|
||||||
'additionalProperties': True,
|
'additionalProperties': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_response = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'console': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'instance_uuid': {'type': 'string', 'format': 'uuid'},
|
||||||
|
'host': {'type': ['string', 'null']},
|
||||||
|
'port': {'type': 'integer'},
|
||||||
|
'internal_access_path': {
|
||||||
|
'oneOf': [
|
||||||
|
{
|
||||||
|
'type': 'null',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'string',
|
||||||
|
'format': 'uuid',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'required': [
|
||||||
|
'instance_uuid', 'host', 'port', 'internal_access_path',
|
||||||
|
],
|
||||||
|
'additionalProperties': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'required': ['console'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
@@ -33,15 +33,14 @@ class ConsoleAuthTokensExtensionTestV21(test.NoDBTestCase):
|
|||||||
_EXPECTED_OUTPUT = {'console': {'instance_uuid': fakes.FAKE_UUID,
|
_EXPECTED_OUTPUT = {'console': {'instance_uuid': fakes.FAKE_UUID,
|
||||||
'host': 'fake_host',
|
'host': 'fake_host',
|
||||||
'port': '1234',
|
'port': '1234',
|
||||||
'internal_access_path':
|
'internal_access_path': fakes.FAKE_UUID}}
|
||||||
'fake_access_path'}}
|
|
||||||
|
|
||||||
# The database backend returns a ConsoleAuthToken.to_dict() and o.vo
|
# The database backend returns a ConsoleAuthToken.to_dict() and o.vo
|
||||||
# StringField are unicode. And the port is an IntegerField.
|
# StringField are unicode. And the port is an IntegerField.
|
||||||
_EXPECTED_OUTPUT_DB = copy.deepcopy(_EXPECTED_OUTPUT)
|
_EXPECTED_OUTPUT_DB = copy.deepcopy(_EXPECTED_OUTPUT)
|
||||||
_EXPECTED_OUTPUT_DB['console'].update(
|
_EXPECTED_OUTPUT_DB['console'].update(
|
||||||
{'host': u'fake_host', 'port': 1234,
|
{'host': 'fake_host', 'port': 1234,
|
||||||
'internal_access_path': u'fake_access_path'})
|
'internal_access_path': fakes.FAKE_UUID})
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ConsoleAuthTokensExtensionTestV21, self).setUp()
|
super(ConsoleAuthTokensExtensionTestV21, self).setUp()
|
||||||
@@ -66,7 +65,7 @@ class ConsoleAuthTokensExtensionTestV231(ConsoleAuthTokensExtensionTestV21):
|
|||||||
@mock.patch('nova.objects.ConsoleAuthToken.validate',
|
@mock.patch('nova.objects.ConsoleAuthToken.validate',
|
||||||
return_value = objects.ConsoleAuthToken(
|
return_value = objects.ConsoleAuthToken(
|
||||||
instance_uuid=fakes.FAKE_UUID, host='fake_host',
|
instance_uuid=fakes.FAKE_UUID, host='fake_host',
|
||||||
port='1234', internal_access_path='fake_access_path',
|
port='1234', internal_access_path=fakes.FAKE_UUID,
|
||||||
console_type='webmks',
|
console_type='webmks',
|
||||||
token=fakes.FAKE_UUID))
|
token=fakes.FAKE_UUID))
|
||||||
def test_get_console_connect_info(self, mock_validate):
|
def test_get_console_connect_info(self, mock_validate):
|
||||||
|
@@ -12,7 +12,10 @@
|
|||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
from oslo_utils.fixture import uuidsentinel as uuids
|
||||||
|
|
||||||
from nova.api.openstack.compute import console_auth_tokens
|
from nova.api.openstack.compute import console_auth_tokens
|
||||||
|
from nova import objects
|
||||||
from nova.tests.unit.api.openstack import fakes
|
from nova.tests.unit.api.openstack import fakes
|
||||||
from nova.tests.unit.policies import base
|
from nova.tests.unit.policies import base
|
||||||
|
|
||||||
@@ -43,6 +46,16 @@ class ConsoleAuthTokensPolicyTest(base.BasePolicyTest):
|
|||||||
@mock.patch('nova.objects.ConsoleAuthToken.validate')
|
@mock.patch('nova.objects.ConsoleAuthToken.validate')
|
||||||
def test_console_connect_info_token_policy(self, mock_validate):
|
def test_console_connect_info_token_policy(self, mock_validate):
|
||||||
rule_name = "os_compute_api:os-console-auth-tokens"
|
rule_name = "os_compute_api:os-console-auth-tokens"
|
||||||
|
mock_validate.return_value = objects.ConsoleAuthToken(
|
||||||
|
id=1,
|
||||||
|
host='node1',
|
||||||
|
port=10000,
|
||||||
|
console_type='novnc',
|
||||||
|
access_url_base='https://example.net:6080',
|
||||||
|
internal_access_path=None,
|
||||||
|
instance_uuid=uuids.instance,
|
||||||
|
token='123-456-789',
|
||||||
|
)
|
||||||
self.common_policy_auth(self.project_admin_authorized_contexts,
|
self.common_policy_auth(self.project_admin_authorized_contexts,
|
||||||
rule_name, self.controller.show,
|
rule_name, self.controller.show,
|
||||||
self.req, fakes.FAKE_UUID)
|
self.req, fakes.FAKE_UUID)
|
||||||
|
@@ -476,25 +476,29 @@ class FakeDriver(driver.ComputeDriver):
|
|||||||
return 'FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE'
|
return 'FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE'
|
||||||
|
|
||||||
def get_vnc_console(self, context, instance):
|
def get_vnc_console(self, context, instance):
|
||||||
return ctype.ConsoleVNC(internal_access_path='FAKE',
|
return ctype.ConsoleVNC(
|
||||||
host='fakevncconsole.com',
|
internal_access_path=uuids.vnc_access_path,
|
||||||
port=6969)
|
host='fakevncconsole.com',
|
||||||
|
port=6969)
|
||||||
|
|
||||||
def get_spice_console(self, context, instance):
|
def get_spice_console(self, context, instance):
|
||||||
return ctype.ConsoleSpice(internal_access_path='FAKE',
|
return ctype.ConsoleSpice(
|
||||||
host='fakespiceconsole.com',
|
internal_access_path=uuids.spice_access_path,
|
||||||
port=6969,
|
host='fakespiceconsole.com',
|
||||||
tlsPort=6970)
|
port=6969,
|
||||||
|
tlsPort=6970)
|
||||||
|
|
||||||
def get_serial_console(self, context, instance):
|
def get_serial_console(self, context, instance):
|
||||||
return ctype.ConsoleSerial(internal_access_path='FAKE',
|
return ctype.ConsoleSerial(
|
||||||
host='fakerdpconsole.com',
|
internal_access_path=uuids.serial_access_path,
|
||||||
port=6969)
|
host='fakerdpconsole.com',
|
||||||
|
port=6969)
|
||||||
|
|
||||||
def get_mks_console(self, context, instance):
|
def get_mks_console(self, context, instance):
|
||||||
return ctype.ConsoleMKS(internal_access_path='FAKE',
|
return ctype.ConsoleMKS(
|
||||||
host='fakemksconsole.com',
|
internal_access_path=uuids.mks_access_path,
|
||||||
port=6969)
|
host='fakemksconsole.com',
|
||||||
|
port=6969)
|
||||||
|
|
||||||
def get_available_resource(self, nodename):
|
def get_available_resource(self, nodename):
|
||||||
"""Updates compute manager resource info on ComputeNode table.
|
"""Updates compute manager resource info on ComputeNode table.
|
||||||
|
Reference in New Issue
Block a user