Skip to content

Commit

Permalink
Merge "Fix: Schema validation for attachment create API"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jun 17, 2021
2 parents 76ed66c + 560318c commit 7a854c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api-ref/source/v3/attachments.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion cinder/api/schemas/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Schema for V3 Attachments API.
"""
import copy

from cinder.api.validation import parameter_types

Expand All @@ -32,7 +33,7 @@
'connector': {'type': ['object', 'null']},
'volume_uuid': parameter_types.uuid,
},
'required': ['instance_uuid', 'volume_uuid'],
'required': ['volume_uuid'],
'additionalProperties': False,
},
},
Expand All @@ -56,3 +57,7 @@
'required': ['attachment'],
'additionalProperties': False,
}

create_v354 = copy.deepcopy(create)
create_v354['properties']['attachment']['properties']['mode'] = (
{'type': 'string', 'enum': ['rw', 'ro']})
14 changes: 10 additions & 4 deletions cinder/api/v3/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def _items(self, req):

@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.
Expand All @@ -130,6 +132,9 @@ def create(self, req, body):
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
Expand All @@ -138,8 +143,9 @@ def create(self, req, body):
"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"
}
}
Expand Down Expand Up @@ -167,7 +173,7 @@ def create(self, req, body):
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,
Expand Down

0 comments on commit 7a854c1

Please sign in to comment.