Fix BadRequest for 'ref' as string value

Before schema validation patch [1] got merged, it was allowed to
pass "ref" as string value (ref:"string") in request body of
snapshot_manage create API but after schema changes, it is
returning 400 error.

This patch fixes this issue by allowing user to pass "ref" parameter
as string.

Note: In case user uses python-cinderclient to manage snapshot, it
always passes "ref" parameter as object (dict).

Change-Id: I6464eacf9f970cbcc1429a50bd59d59faf262bc6
Closes-Bug: #1743338
This commit is contained in:
Neha Alhat 2018-01-15 19:31:15 +05:30
parent 9cbb200ec2
commit 38976a5b93
2 changed files with 24 additions and 1 deletions

View File

@ -31,7 +31,7 @@ create = {
"metadata": parameter_types.metadata_allows_null,
"name": parameter_types.name_allow_zero_min_length,
"volume_id": parameter_types.uuid,
"ref": {'type': ['object', 'null']},
"ref": {'type': ['object', 'null', 'string']},
},
'required': ['ref', 'volume_id'],
'additionalProperties': False,

View File

@ -167,6 +167,29 @@ class SnapshotManageTest(test.TestCase):
# 5th argument of args is metadata.
self.assertIsNone(args[5])
@mock.patch('cinder.volume.rpcapi.VolumeAPI.manage_existing_snapshot')
@mock.patch('cinder.volume.api.API.create_snapshot_in_db')
@mock.patch('cinder.db.sqlalchemy.api.service_get')
def test_manage_snapshot_ok_ref_as_string(self, mock_db,
mock_create_snapshot,
mock_rpcapi):
mock_db.return_value = fake_service.fake_service_obj(
self._admin_ctxt,
binary=constants.VOLUME_BINARY)
body = {'snapshot': {'volume_id': fake.VOLUME_ID,
'ref': "string"}}
res = self._get_resp_post(body)
self.assertEqual(http_client.ACCEPTED, res.status_int, res)
# Check the volume_rpcapi.manage_existing_snapshot was called with
# correct arguments.
self.assertEqual(1, mock_rpcapi.call_count)
args = mock_rpcapi.call_args[0]
self.assertEqual(body['snapshot']['ref'], args[2])
@mock.patch('cinder.objects.service.Service.is_up',
return_value=True,
new_callable=mock.PropertyMock)