Save model_update as admin in create_volume
admin_metadata are not saved by the object without an admin context. Turns out Huawei driver returns admin_metadata in model_update. To make sure admin_metadata will be saved we should save the volume to the DB with admin context. This commit implements that. Change-Id: Ia48498734db61474009c8854a353c67cbdfccc0e Closes-Bug: 1656867
This commit is contained in:
parent
d9e48eb1a4
commit
beccf8b671
@ -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'
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user