Merge "Fix BadRequest for 'ref' as string value"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2018-01-18 09:08:28 +00:00
commit 7c2cbe5254
2 files changed
+24 -1

No files matched your search

+1 -1
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,
@@ -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)