diff --git a/cinderlib/objects.py b/cinderlib/objects.py index da3c3a5..af9d74d 100644 --- a/cinderlib/objects.py +++ b/cinderlib/objects.py @@ -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)) diff --git a/cinderlib/tests/unit/persistence/base.py b/cinderlib/tests/unit/persistence/base.py index d88dde1..0127fce 100644 --- a/cinderlib/tests/unit/persistence/base.py +++ b/cinderlib/tests/unit/persistence/base.py @@ -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) diff --git a/releasenotes/notes/fix-not-local-a8cf22a2092c8a98.yaml b/releasenotes/notes/fix-not-local-a8cf22a2092c8a98.yaml new file mode 100644 index 0000000..a7fdbb3 --- /dev/null +++ b/releasenotes/notes/fix-not-local-a8cf22a2092c8a98.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Bug #1868153: Volume refresh will no longer forget if the volume is locally + attached.