Merge "NotLocal exception after refresh"

This commit is contained in:
Zuul 2020-04-23 17:22:35 +00:00 committed by Gerrit Code Review
commit 602c9f71c2
3 changed files with 44 additions and 0 deletions

View File

@ -622,6 +622,7 @@ class Volume(NamedObject):
last_self.snapshots
if self._connections is not None:
last_self.connections
last_self.local_attach = self.local_attach
vars(self).clear()
vars(self).update(vars(last_self))

View File

@ -521,3 +521,41 @@ class BasePersistenceTest(helper.TestHelper):
result = self.persistence.db._volume_admin_metadata_get(self.context,
vols[0].id)
self.assertDictEqual({'k': 'v'}, result)
@mock.patch('cinderlib.objects.Volume.get_by_id')
@mock.patch('cinderlib.objects.Volume.snapshots',
new_callable=mock.PropertyMock)
@mock.patch('cinderlib.objects.Volume.connections',
new_callable=mock.PropertyMock)
def test_volume_refresh(self, get_conns_mock, get_snaps_mock, get_mock):
vol = self.create_n_volumes(1)[0]
vol_id = vol.id
# This is to simulate situation where the persistence does lazy loading
vol._snapshots = vol._connections = None
get_mock.return_value = cinderlib.Volume(vol)
vol.refresh()
get_mock.assert_called_once_with(vol_id)
get_conns_mock.assert_not_called()
get_snaps_mock.assert_not_called()
self.assertIsNone(vol.local_attach)
@mock.patch('cinderlib.objects.Volume.get_by_id')
@mock.patch('cinderlib.objects.Volume.snapshots',
new_callable=mock.PropertyMock)
@mock.patch('cinderlib.objects.Volume.connections',
new_callable=mock.PropertyMock)
def test_volume_refresh_with_conn_and_snaps(self, get_conns_mock,
get_snaps_mock, get_mock):
vol = self.create_n_volumes(1)[0]
vol_id = vol.id
vol.local_attach = mock.sentinel.local_attach
get_mock.return_value = cinderlib.Volume(vol)
vol.refresh()
get_mock.assert_called_once_with(vol_id)
get_conns_mock.assert_called_once_with()
get_snaps_mock.assert_called_once_with()
self.assertIs(mock.sentinel.local_attach, vol.local_attach)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Bug #1868153: Volume refresh will no longer forget if the volume is locally
attached.