From 5dea649c478ef2b9f0e4f16f1cdafa48cbdfe740 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 22 Mar 2021 14:37:35 +0000 Subject: [PATCH] Backup manager: Synchronously call remove_export_snapshot Similar to the fix in I482c3d552, wait for remove_export_snapshot() to complete before returning from _detach_volume(). Related-Bug: #1920237 Change-Id: Ibf81c839fc9015051edcdb625e1018b817a9c675 --- cinder/backup/manager.py | 2 +- cinder/tests/unit/backup/test_backup.py | 6 +++++- cinder/volume/rpcapi.py | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index 1d58c73d3a4..4457ce32bfd 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -1072,7 +1072,7 @@ class BackupManager(manager.SchedulerDependentManager): else: rpcapi.terminate_connection_snapshot(ctxt, device, properties, force=force) - rpcapi.remove_export_snapshot(ctxt, device) + rpcapi.remove_export_snapshot(ctxt, device, sync=True) def is_working(self): return self.is_initialized diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index 6e5a76d9a7d..8a489e22cfe 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -901,6 +901,7 @@ class BackupTestCase(BaseBackupTest): self.assertRaises(exception.InvalidSnapshot, self.backup_mgr.create_backup, self.ctxt, backup) + @mock.patch('cinder.volume.rpcapi.VolumeAPI.remove_export_snapshot') @mock.patch('cinder.volume.volume_utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') @@ -910,7 +911,8 @@ class BackupTestCase(BaseBackupTest): mock_open, mock_temporary_chown, mock_get_backup_device, - mock_get_conn): + mock_get_conn, + mock_remove_export_snapshot): """Test backup in-use volume using temp snapshot.""" self.override_config('backup_use_same_host', True) vol_size = 1 @@ -952,6 +954,8 @@ class BackupTestCase(BaseBackupTest): mock_get_conn.assert_called_once_with() mock_terminate_connection_snapshot.assert_called_once_with( self.ctxt, snap, properties, force=True) + mock_remove_export_snapshot.assert_called_once_with( + self.ctxt, mock.ANY, sync=True) vol = objects.Volume.get_by_id(self.ctxt, vol_id) self.assertEqual('in-use', vol['status']) self.assertEqual('backing-up', vol['previous_status']) diff --git a/cinder/volume/rpcapi.py b/cinder/volume/rpcapi.py index 9b72583bca9..e5cdb4c546b 100644 --- a/cinder/volume/rpcapi.py +++ b/cinder/volume/rpcapi.py @@ -438,9 +438,12 @@ class VolumeAPI(rpc.RPCAPI): connector=connector, force=force) @rpc.assert_min_rpc_version('3.13') - def remove_export_snapshot(self, ctxt, snapshot): + def remove_export_snapshot(self, ctxt, snapshot, sync=False): cctxt = self._get_cctxt(snapshot.service_topic_queue, version='3.13') - cctxt.cast(ctxt, 'remove_export_snapshot', snapshot_id=snapshot.id) + if sync: + cctxt.call(ctxt, 'remove_export_snapshot', snapshot_id=snapshot.id) + else: + cctxt.cast(ctxt, 'remove_export_snapshot', snapshot_id=snapshot.id) @rpc.assert_min_rpc_version('3.9') def attachment_update(self, ctxt, vref, connector, attachment_id):