From 7ee80f76674bf4ee37b42a1223eb570138425ddd Mon Sep 17 00:00:00 2001 From: Vipin Balachandran Date: Thu, 9 Oct 2014 16:50:24 +0530 Subject: [PATCH] Fix display name change during backup restore Currently the display name and description of the target volume is changed to that in the backup meta-data during backup restore. This can confuse the end-user, especially in the case of restore to an existing volume. This patch removes display name and display description from the list of fields to be copied from the backup meta-data to update the volume. Change-Id: I21a0505352ddc8db801f4820d575399a4771b259 Closes-Bug: #1376194 --- cinder/backup/driver.py | 18 +------------ cinder/tests/test_backup_driver_base.py | 35 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/cinder/backup/driver.py b/cinder/backup/driver.py index 674f59e5a..7d8806ac2 100644 --- a/cinder/backup/driver.py +++ b/cinder/backup/driver.py @@ -149,19 +149,6 @@ class BackupMetadataAPI(base.Base): return subset - def _restore_vol_base_meta(self, metadata, volume_id, fields): - """Restore values to Volume object for provided fields.""" - LOG.debug("Restoring volume base metadata") - # Only set the display_name if it was not None since the - # restore action will have set a name which is more useful than - # None. - key = 'display_name' - if key in fields and key in metadata and metadata[key] is None: - fields = [f for f in fields if f != key] - - metadata = self._filter(metadata, fields) - self.db.volume_update(self.context, volume_id, metadata) - def _restore_vol_meta(self, metadata, volume_id, fields): """Restore values to VolumeMetadata object for provided fields.""" LOG.debug("Restoring volume metadata") @@ -196,10 +183,7 @@ class BackupMetadataAPI(base.Base): Empty field list indicates that all backed up fields should be restored. """ - return {self.TYPE_TAG_VOL_BASE_META: - (self._restore_vol_base_meta, - ['display_name', 'display_description']), - self.TYPE_TAG_VOL_META: + return {self.TYPE_TAG_VOL_META: (self._restore_vol_meta, []), self.TYPE_TAG_VOL_GLANCE_META: (self._restore_vol_glance_meta, [])} diff --git a/cinder/tests/test_backup_driver_base.py b/cinder/tests/test_backup_driver_base.py index a77ae7fa3..1fbb6797a 100644 --- a/cinder/tests/test_backup_driver_base.py +++ b/cinder/tests/test_backup_driver_base.py @@ -88,15 +88,22 @@ class BackupBaseDriverTestCase(test.TestCase): class BackupMetadataAPITestCase(test.TestCase): - def _create_volume_db_entry(self, id, size): - vol = {'id': id, 'size': size, 'status': 'available'} + def _create_volume_db_entry(self, id, size, display_name, + display_description): + vol = {'id': id, 'size': size, 'status': 'available', + 'display_name': display_name, + 'display_description': display_description} return db.volume_create(self.ctxt, vol)['id'] def setUp(self): super(BackupMetadataAPITestCase, self).setUp() self.ctxt = context.get_admin_context() self.volume_id = str(uuid.uuid4()) - self._create_volume_db_entry(self.volume_id, 1) + self.volume_display_name = 'vol-1' + self.volume_display_description = 'test vol' + self._create_volume_db_entry(self.volume_id, 1, + self.volume_display_name, + self.volume_display_description) self.bak_meta_api = driver.BackupMetadataAPI(self.ctxt) def _add_metadata(self, vol_meta=False, vol_glance_meta=False): @@ -158,17 +165,26 @@ class BackupMetadataAPITestCase(test.TestCase): def test_v1_restore_factory(self): fact = self.bak_meta_api._v1_restore_factory() - keys = [self.bak_meta_api.TYPE_TAG_VOL_BASE_META, - self.bak_meta_api.TYPE_TAG_VOL_META, + keys = [self.bak_meta_api.TYPE_TAG_VOL_META, self.bak_meta_api.TYPE_TAG_VOL_GLANCE_META] self.assertEqual(set(keys).symmetric_difference(set(fact.keys())), set([])) + meta_container = {self.bak_meta_api.TYPE_TAG_VOL_BASE_META: + {'display_name': 'vol-2', + 'display_description': 'description'}, + self.bak_meta_api.TYPE_TAG_VOL_META: {}, + self.bak_meta_api.TYPE_TAG_VOL_GLANCE_META: {}} for f in fact: func = fact[f][0] fields = fact[f][1] - func({}, self.volume_id, fields) + func(meta_container[f], self.volume_id, fields) + + vol = db.volume_get(self.ctxt, self.volume_id) + self.assertEqual(self.volume_display_name, vol['display_name']) + self.assertEqual(self.volume_display_description, + vol['display_description']) def test_restore_vol_glance_meta(self): fields = {} @@ -190,13 +206,6 @@ class BackupMetadataAPITestCase(test.TestCase): self.bak_meta_api._save_vol_meta(container, self.volume_id) self.bak_meta_api._restore_vol_meta(container, self.volume_id, fields) - def test_restore_vol_base_meta(self): - fields = {} - container = {} - self.bak_meta_api._save_vol_base_meta(container, self.volume_id) - self.bak_meta_api._restore_vol_base_meta(container, self.volume_id, - fields) - def test_filter(self): metadata = {'a': 1, 'b': 2, 'c': 3} self.assertEqual(metadata, self.bak_meta_api._filter(metadata, [])) -- 2.45.2