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.

Also includes a squash to add a releasenote from
Change-Id: I4a6e93ea98cfd4988d38bedca6e5538391c1f74d

Change-Id: I5108fd51effa4d72581654ed450d191a13e0e964
(cherry picked from commit 560318c82e)
(cherry picked from commit 58250aae06)
Conflicts:
    cinder/api/v3/attachments.py
This commit is contained in:
Rajat Dhasmana 2021-03-26 13:05:11 -04:00 committed by Bence Romsics
parent a6ffb102af
commit d7bb194d09
4 changed files with 27 additions and 6 deletions

View File

@ -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

View File

@ -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']})

View File

@ -101,7 +101,9 @@ class AttachmentsController(wsgi.Controller):
@wsgi.Controller.api_version(mv.NEW_ATTACH)
@wsgi.response(http_client.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.
@ -124,6 +126,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
@ -132,8 +137,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"
}
}
@ -161,7 +167,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,

View File

@ -0,0 +1,10 @@
---
fixes:
- |
Fixed the schema validation for attachment create API
to make instance uuid an optional field. It had mistakenly
been defined as a required field when schema validation
was added in an earlier release.
Also updated the schema to allow specification of the ``mode``
parameter, which has been available since microversion >= 3.54,
but which was not recognized as a legitimate request field.