Merge "Save model_update as admin in create_volume"

This commit is contained in:
Jenkins 2017-01-16 20:09:48 +00:00 committed by Gerrit Code Review
commit 559d63f7d4
2 changed files with 11 additions and 2 deletions

View File

@ -1054,6 +1054,14 @@ class VolumeTestCase(base.BaseVolumeTestCase):
self.volume.create_volume(self.context, volume)
self.assertEqual(fake.PROVIDER_ID, volume['provider_id'])
def test_create_volume_with_admin_metadata(self):
with mock.patch.object(
self.volume.driver, 'create_volume',
return_value={'admin_metadata': {'foo': 'bar'}}):
volume = tests_utils.create_volume(self.user_context)
self.volume.create_volume(self.user_context, volume)
self.assertEqual({'foo': 'bar'}, volume['admin_metadata'])
@mock.patch.object(key_manager, 'API', new=fake_keymgr.fake_api)
def test_create_delete_volume_with_encrypted_volume_type(self):
cipher = 'aes-xts-plain64'

View File

@ -857,8 +857,9 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
# Persist any model information provided on creation.
try:
if model_update:
volume.update(model_update)
volume.save()
with volume.obj_as_admin():
volume.update(model_update)
volume.save()
except exception.CinderException:
# If somehow the update failed we want to ensure that the
# failure is logged (but not try rescheduling since the volume at