]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix display name change during backup restore
authorVipin Balachandran <vbala@vmware.com>
Thu, 9 Oct 2014 11:20:24 +0000 (16:50 +0530)
committerVipin Balachandran <vbala@vmware.com>
Fri, 10 Oct 2014 12:38:08 +0000 (18:08 +0530)
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
cinder/tests/test_backup_driver_base.py

index 674f59e5a03ec8eed8ebbb3e246da16140176a23..7d8806ac2cbc61a5a9715f52d2ae7c7c2540d704 100644 (file)
@@ -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, [])}
index a77ae7fa39fddc4356941f6bba15ea7772fac60e..1fbb6797a58799897910bc9e056042ef6c79cb09 100644 (file)
@@ -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, []))