api: Add response body schemas for servers APIs (4/6)

Tackle the create view. This is pretty simple again.

Change-Id: Ib806681a9514c6a2191cad9f6559a9cc2b610065
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2024-11-29 13:32:23 +00:00
parent 6e8395a421
commit 5e384f1994
3 changed files with 60 additions and 2 deletions
@@ -1392,6 +1392,53 @@ show_response_v2100['properties']['server'] = {
'oneOf': [_server_response_v2100, _server_cell_down_response_v271],
}
create_response = {
'type': 'object',
'oneOf': [
{
'properties': {
'reservation_id': {'type': 'string'},
},
'required': ['reservation_id'],
'additionalProperties': False,
},
{
'properties': {
'server': {
'type': 'object',
'properties': {
'adminPass': {'type': 'string'},
'id': {'type': 'string', 'format': 'uuid'},
'links': response_types.links,
'security_groups': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
},
'required': ['name'],
'additionalProperties': False,
},
},
'OS-DCF:diskConfig': {
'type': 'string', 'enum': ['AUTO', 'MANUAL'],
},
},
'required': [
# adminPass is an unfortunate example of config-driven
# API behavior and isn't present unless enabled
'id', 'links', 'security_groups', 'OS-DCF:diskConfig'
],
'additionalProperties': False,
},
},
'required': ['server'],
'additionalProperties': False,
},
],
}
resize_response = {'type': 'null'}
confirm_resize_response = {'type': 'null'}
+1
View File
@@ -707,6 +707,7 @@ class ServersController(wsgi.Controller):
@validation.schema(schema.create_v274, '2.74', '2.89')
@validation.schema(schema.create_v290, '2.90', '2.93')
@validation.schema(schema.create_v294, '2.94')
@validation.response_body_schema(schema.create_response)
def create(self, req, body):
"""Creates a new server for a given user."""
context = req.environ['nova.context']
+11 -1
View File
@@ -40,6 +40,14 @@ from nova.tests.unit.policies import base
CONF = nova.conf.CONF
def fake_add_security_grps(
req, servers, instances, create_request=False,
):
# just enough to satisfy schema checks
if create_request:
servers[0]['security_groups'] = [{'name': 'default'}]
class ServersPolicyTest(base.BasePolicyTest):
"""Test Servers APIs policies with all possible context.
This class defines the set of context with different roles
@@ -61,7 +69,9 @@ class ServersPolicyTest(base.BasePolicyTest):
self.req = fakes.HTTPRequest.blank('')
user_id = self.req.environ['nova.context'].user_id
self.controller._view_builder._add_security_grps = mock.MagicMock()
self.controller._view_builder._add_security_grps = mock.MagicMock(
side_effect=fake_add_security_grps
)
self.controller._view_builder._get_metadata = mock.MagicMock()
self.controller._view_builder._get_addresses = mock.MagicMock()
self.controller._view_builder._get_host_id = mock.MagicMock(