Fix: Schema validation for attachment create API
Currently the schema validation for attachment create assumes that instance UUID will always be present in the request but that is not the case when glance calls cinder for attachment. Also there isn't any schema validation for MV3.54 which accepts attachment mode in the request hence failing requests passing mode. This patch removes the instance_uuid from required parameters and adds schema validation for MV3.54. Change-Id: I5108fd51effa4d72581654ed450d191a13e0e964
This commit is contained in:
parent
7c4b626c01
commit
560318c82e
@ -253,7 +253,7 @@ Request
|
||||
|
||||
- project_id: project_id_path
|
||||
- attachment: attachment
|
||||
- instance_uuid: instance_uuid_req
|
||||
- instance_uuid: instance_uuid
|
||||
- connector: connector
|
||||
- volume_uuid: volume_id_attachment
|
||||
- mode: attach_mode
|
||||
|
@ -17,6 +17,7 @@
|
||||
Schema for V3 Attachments API.
|
||||
|
||||
"""
|
||||
import copy
|
||||
|
||||
from cinder.api.validation import parameter_types
|
||||
|
||||
@ -32,7 +33,7 @@ create = {
|
||||
'connector': {'type': ['object', 'null']},
|
||||
'volume_uuid': parameter_types.uuid,
|
||||
},
|
||||
'required': ['instance_uuid', 'volume_uuid'],
|
||||
'required': ['volume_uuid'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
@ -56,3 +57,7 @@ update = {
|
||||
'required': ['attachment'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
create_v354 = copy.deepcopy(create)
|
||||
create_v354['properties']['attachment']['properties']['mode'] = (
|
||||
{'type': 'string', 'enum': ['rw', 'ro']})
|
||||
|
@ -107,7 +107,9 @@ class AttachmentsController(wsgi.Controller):
|
||||
|
||||
@wsgi.Controller.api_version(mv.NEW_ATTACH)
|
||||
@wsgi.response(HTTPStatus.OK)
|
||||
@validation.schema(attachment.create)
|
||||
@validation.schema(attachment.create, mv.NEW_ATTACH,
|
||||
mv.get_prior_version(mv.ATTACHMENT_CREATE_MODE_ARG))
|
||||
@validation.schema(attachment.create_v354, mv.ATTACHMENT_CREATE_MODE_ARG)
|
||||
def create(self, req, body):
|
||||
"""Create an attachment.
|
||||
|
||||
@ -130,6 +132,9 @@ class AttachmentsController(wsgi.Controller):
|
||||
referenced below is the UUID of the Instance, for non-nova consumers
|
||||
this can be a server UUID or some other arbitrary unique identifier.
|
||||
|
||||
Starting from microversion 3.54, we can pass the attach mode as
|
||||
argument in the request body.
|
||||
|
||||
Expected format of the input parameter 'body':
|
||||
|
||||
.. code-block:: json
|
||||
@ -138,8 +143,9 @@ class AttachmentsController(wsgi.Controller):
|
||||
"attachment":
|
||||
{
|
||||
"volume_uuid": "volume-uuid",
|
||||
"instance_uuid": "nova-server-uuid",
|
||||
"connector": "null|<connector-object>"
|
||||
"instance_uuid": "null|nova-server-uuid",
|
||||
"connector": "null|<connector-object>",
|
||||
"mode": "null|rw|ro"
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +173,7 @@ class AttachmentsController(wsgi.Controller):
|
||||
returns: A summary view of the attachment object
|
||||
"""
|
||||
context = req.environ['cinder.context']
|
||||
instance_uuid = body['attachment']['instance_uuid']
|
||||
instance_uuid = body['attachment'].get('instance_uuid')
|
||||
volume_uuid = body['attachment']['volume_uuid']
|
||||
volume_ref = objects.Volume.get_by_id(
|
||||
context,
|
||||
|
Loading…
Reference in New Issue
Block a user