Merge "Fix VolumeAttachment OVO Volume lazy loading"

This commit is contained in:
Zuul 2017-11-21 14:15:54 +00:00 committed by Gerrit Code Review
commit 9ad305dd84
2 changed files with 12 additions and 1 deletions

View File

@ -110,7 +110,7 @@ class VolumeAttachment(base.CinderPersistentObject, base.CinderObject,
objtype=self.obj_name())
if attrname == 'volume':
volume = objects.Volume.get_by_id(self._context, self.id)
volume = objects.Volume.get_by_id(self._context, self.volume_id)
self.volume = volume
self.obj_reset_changes(fields=[attrname])

View File

@ -35,6 +35,17 @@ class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
fake.ATTACHMENT_ID)
self._compare(self, attachment_obj, attachment)
@mock.patch.object(objects.Volume, 'get_by_id')
def test_lazy_load_volume(self, volume_get_mock):
volume = objects.Volume(self.context, id=fake.VOLUME_ID)
volume_get_mock.return_value = volume
attach = objects.VolumeAttachment(self.context, id=fake.ATTACHMENT_ID,
volume_id=volume.id)
r = attach.volume
self.assertEqual(volume, r)
volume_get_mock.assert_called_once_with(self.context, volume.id)
@mock.patch('cinder.db.volume_attachment_update')
def test_save(self, volume_attachment_update):
attachment = fake_volume.fake_volume_attachment_obj(self.context)