diff --git a/cinder/tests/unit/volume/drivers/test_remotefs.py b/cinder/tests/unit/volume/drivers/test_remotefs.py index 44961dca60f..6748a0fa609 100644 --- a/cinder/tests/unit/volume/drivers/test_remotefs.py +++ b/cinder/tests/unit/volume/drivers/test_remotefs.py @@ -74,7 +74,7 @@ class RemoteFsSnapDriverTestCase(test.TestCase): self._fake_snap_c = fake_snapshot.fake_snapshot_obj(self.context) self._fake_snap_c.volume = self.volume_c self.volume_c_path = os.path.join(self._FAKE_MNT_POINT, - self._fake_snap_c.name) + self.volume_c.name) self._fake_snap_c_path = (self.volume_c_path + '.' + self._fake_snap_c.id) @@ -356,6 +356,18 @@ class RemoteFsSnapDriverTestCase(test.TestCase): snapshot.volume.status = 'backing-up' snapshot.volume.attach_status = 'attached' expected_method_called = '_create_snapshot_online' + conn_info = ('{"driver_volume_type": "nfs",' + '"export": "localhost:/srv/nfs1",' + '"name": "old_name"}') + attachment = fake_volume.volume_attachment_ovo( + self.context, connection_info=conn_info) + snapshot.volume.volume_attachment.objects.append(attachment) + mock_save = self.mock_object(attachment, 'save') + + # After the snapshot the connection info should change the name of + # the file + expected = copy.deepcopy(attachment.connection_info) + expected['name'] = snapshot.volume.name + '.' + snapshot.id else: expected_method_called = '_do_create_snapshot' @@ -372,6 +384,11 @@ class RemoteFsSnapDriverTestCase(test.TestCase): mock.sentinel.fake_info_path, expected_snapshot_info) + if volume_in_use: + mock_save.assert_called_once() + changed_fields = attachment.cinder_obj_get_changes() + self.assertEqual(expected, changed_fields['connection_info']) + @ddt.data({'encryption': True}, {'encryption': False}) def test_create_snapshot_volume_available(self, encryption): self._test_create_snapshot(encryption=encryption) diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py index 01c04adb305..9f25032916e 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -1637,18 +1637,25 @@ class RemoteFSSnapDriverBase(RemoteFSDriver): backing_filename = self.get_active_image_from_info( snapshot.volume) new_snap_path = self._get_new_snap_path(snapshot) + active = os.path.basename(new_snap_path) if self._is_volume_attached(snapshot.volume): self._create_snapshot_online(snapshot, backing_filename, new_snap_path) + # Update reference in the only attachment (no multi-attach support) + attachment = snapshot.volume.volume_attachment[0] + attachment.connection_info['name'] = active + # Let OVO know it has been updated + attachment.connection_info = attachment.connection_info + attachment.save() else: self._do_create_snapshot(snapshot, backing_filename, new_snap_path) - snap_info['active'] = os.path.basename(new_snap_path) - snap_info[snapshot.id] = os.path.basename(new_snap_path) + snap_info['active'] = active + snap_info[snapshot.id] = active self._write_info_file(info_path, snap_info) def _create_snapshot_online(self, snapshot, backing_filename, diff --git a/releasenotes/notes/nfs-online-snapshot-c05e6c8113bbded6.yaml b/releasenotes/notes/nfs-online-snapshot-c05e6c8113bbded6.yaml new file mode 100644 index 00000000000..1aab2005164 --- /dev/null +++ b/releasenotes/notes/nfs-online-snapshot-c05e6c8113bbded6.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + NFS driver `bug #1860913 + `_: Fixed instance uses + base image file when it is rebooted after online snapshot creation.