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
This commit is contained in:
parent
35b6b55ff3
commit
7ee80f7667
@ -149,19 +149,6 @@ class BackupMetadataAPI(base.Base):
|
|||||||
|
|
||||||
return subset
|
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):
|
def _restore_vol_meta(self, metadata, volume_id, fields):
|
||||||
"""Restore values to VolumeMetadata object for provided fields."""
|
"""Restore values to VolumeMetadata object for provided fields."""
|
||||||
LOG.debug("Restoring volume metadata")
|
LOG.debug("Restoring volume metadata")
|
||||||
@ -196,10 +183,7 @@ class BackupMetadataAPI(base.Base):
|
|||||||
Empty field list indicates that all backed up fields should be
|
Empty field list indicates that all backed up fields should be
|
||||||
restored.
|
restored.
|
||||||
"""
|
"""
|
||||||
return {self.TYPE_TAG_VOL_BASE_META:
|
return {self.TYPE_TAG_VOL_META:
|
||||||
(self._restore_vol_base_meta,
|
|
||||||
['display_name', 'display_description']),
|
|
||||||
self.TYPE_TAG_VOL_META:
|
|
||||||
(self._restore_vol_meta, []),
|
(self._restore_vol_meta, []),
|
||||||
self.TYPE_TAG_VOL_GLANCE_META:
|
self.TYPE_TAG_VOL_GLANCE_META:
|
||||||
(self._restore_vol_glance_meta, [])}
|
(self._restore_vol_glance_meta, [])}
|
||||||
|
@ -88,15 +88,22 @@ class BackupBaseDriverTestCase(test.TestCase):
|
|||||||
|
|
||||||
class BackupMetadataAPITestCase(test.TestCase):
|
class BackupMetadataAPITestCase(test.TestCase):
|
||||||
|
|
||||||
def _create_volume_db_entry(self, id, size):
|
def _create_volume_db_entry(self, id, size, display_name,
|
||||||
vol = {'id': id, 'size': size, 'status': 'available'}
|
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']
|
return db.volume_create(self.ctxt, vol)['id']
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BackupMetadataAPITestCase, self).setUp()
|
super(BackupMetadataAPITestCase, self).setUp()
|
||||||
self.ctxt = context.get_admin_context()
|
self.ctxt = context.get_admin_context()
|
||||||
self.volume_id = str(uuid.uuid4())
|
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)
|
self.bak_meta_api = driver.BackupMetadataAPI(self.ctxt)
|
||||||
|
|
||||||
def _add_metadata(self, vol_meta=False, vol_glance_meta=False):
|
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):
|
def test_v1_restore_factory(self):
|
||||||
fact = self.bak_meta_api._v1_restore_factory()
|
fact = self.bak_meta_api._v1_restore_factory()
|
||||||
|
|
||||||
keys = [self.bak_meta_api.TYPE_TAG_VOL_BASE_META,
|
keys = [self.bak_meta_api.TYPE_TAG_VOL_META,
|
||||||
self.bak_meta_api.TYPE_TAG_VOL_META,
|
|
||||||
self.bak_meta_api.TYPE_TAG_VOL_GLANCE_META]
|
self.bak_meta_api.TYPE_TAG_VOL_GLANCE_META]
|
||||||
|
|
||||||
self.assertEqual(set(keys).symmetric_difference(set(fact.keys())),
|
self.assertEqual(set(keys).symmetric_difference(set(fact.keys())),
|
||||||
set([]))
|
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:
|
for f in fact:
|
||||||
func = fact[f][0]
|
func = fact[f][0]
|
||||||
fields = fact[f][1]
|
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):
|
def test_restore_vol_glance_meta(self):
|
||||||
fields = {}
|
fields = {}
|
||||||
@ -190,13 +206,6 @@ class BackupMetadataAPITestCase(test.TestCase):
|
|||||||
self.bak_meta_api._save_vol_meta(container, self.volume_id)
|
self.bak_meta_api._save_vol_meta(container, self.volume_id)
|
||||||
self.bak_meta_api._restore_vol_meta(container, self.volume_id, fields)
|
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):
|
def test_filter(self):
|
||||||
metadata = {'a': 1, 'b': 2, 'c': 3}
|
metadata = {'a': 1, 'b': 2, 'c': 3}
|
||||||
self.assertEqual(metadata, self.bak_meta_api._filter(metadata, []))
|
self.assertEqual(metadata, self.bak_meta_api._filter(metadata, []))
|
||||||
|
Loading…
Reference in New Issue
Block a user