Merge "Validate metadata before reserve quota"

This commit is contained in:
Zuul 2018-01-18 15:12:39 +00:00 committed by Gerrit Code Review
commit 0b392d393b
2 changed files with 21 additions and 1 deletions

View File

@ -218,6 +218,26 @@ class SnapshotTestCase(base.BaseVolumeTestCase):
"fake_description", False, {}, None, "fake_description", False, {}, None,
commit_quota=False) commit_quota=False)
@mock.patch('cinder.objects.volume.Volume.get_by_id')
def test_create_snapshot_in_db_invalid_metadata(self, mock_get):
test_volume = tests_utils.create_volume(
self.context,
status='available',
host=CONF.host)
mock_get.return_value = test_volume
volume_api = cinder.volume.api.API()
with mock.patch.object(QUOTAS, 'add_volume_type_opts'),\
mock.patch.object(QUOTAS, 'reserve') as mock_reserve,\
mock.patch.object(QUOTAS, 'commit') as mock_commit:
self.assertRaises(exception.InvalidInput,
volume_api.create_snapshot_in_db,
self.context, test_volume, "fake_snapshot_name",
"fake_description", False, "fake_metadata", None,
commit_quota=True)
mock_reserve.assert_not_called()
mock_commit.assert_not_called()
def test_create_snapshot_failed_maintenance(self): def test_create_snapshot_failed_maintenance(self):
"""Test exception handling when create snapshot in maintenance.""" """Test exception handling when create snapshot in maintenance."""
test_volume = tests_utils.create_volume( test_volume = tests_utils.create_volume(

View File

@ -862,6 +862,7 @@ class API(base.Base):
group_snapshot_id=None): group_snapshot_id=None):
context.authorize(snapshot_policy.CREATE_POLICY) context.authorize(snapshot_policy.CREATE_POLICY)
utils.check_metadata_properties(metadata)
if not volume.host: if not volume.host:
msg = _("The snapshot cannot be created because volume has " msg = _("The snapshot cannot be created because volume has "
"not been scheduled to any host.") "not been scheduled to any host.")
@ -909,7 +910,6 @@ class API(base.Base):
context, e, context, e,
resource='snapshots', resource='snapshots',
size=volume.size) size=volume.size)
utils.check_metadata_properties(metadata)
snapshot = None snapshot = None
try: try: