From beccf8b67149e9b63642a46309404b6dd1a3123d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulko?= Date: Mon, 16 Jan 2017 15:53:31 +0100 Subject: [PATCH] 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 --- cinder/tests/unit/test_volume.py | 8 ++++++++ cinder/volume/flows/manager/create_volume.py | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index effcc61d426..08b6e58a275 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -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' diff --git a/cinder/volume/flows/manager/create_volume.py b/cinder/volume/flows/manager/create_volume.py index d9de3fa48fe..add697b936a 100644 --- a/cinder/volume/flows/manager/create_volume.py +++ b/cinder/volume/flows/manager/create_volume.py @@ -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