Fix Snapshot object metadata loading

The Snapshot object will fail to correctly load
metadata.  Initialize the object fully so that
obj_what_changed() works as intended.

This prevents the error:
   AttributeError: 'Snapshot' object has no
   attribute '_obj_metadata'

Closes-Bug: #1805790

Co-Author: Gorka Eguileor <geguileo@redhat.com>
Change-Id: Idee4836ee3e4f9b9f4099e7a1a3d7a4bada3f7b8
This commit is contained in:
Eric Harney 2019-01-28 12:51:00 -05:00
parent c8976b726a
commit 7ad0b0660c
2 changed files with 2 additions and 1 deletions

View File

@ -95,7 +95,7 @@ class Snapshot(cleanable.CinderCleanableObject, base.CinderObject,
def __init__(self, *args, **kwargs):
super(Snapshot, self).__init__(*args, **kwargs)
self._orig_metadata = {}
self.metadata = kwargs.get('metadata', {})
self._reset_metadata_tracking()

View File

@ -167,6 +167,7 @@ class TestSnapshot(test_objects.BaseObjectsTestCase):
self.assertEqual(volume, snapshot.volume)
volume_get_by_id.assert_called_once_with(self.context,
snapshot.volume_id)
self.assertEqual(snapshot.metadata, {})
# Test cgsnapshot lazy-loaded field
cgsnapshot = objects.CGSnapshot(context=self.context,
id=fake.CGSNAPSHOT_ID)