diff options
author | anguoming <agm_daydayup@foxmail.com> | 2022-08-12 14:05:52 +0800 |
---|---|---|
committer | anguoming <agm_daydayup@foxmail.com> | 2023-02-16 10:24:35 +0800 |
commit | 2c3442a397c97e78f53b27e44b610752035b6f09 (patch) | |
tree | 5ed5ed5b2dc0346522e4b89ac0fb53064204c1ac /glance_store/tests | |
parent | 64e25979a904e468e1e89d8727e9554662596acf (diff) | |
download | glance_store-2c3442a397c97e78f53b27e44b610752035b6f09.tar.gz |
move attachment_update to try block
move attachment_update to try block, so when there is some error calling
attachment_update the finally block will be called, then the attachment created could be deleted.
Closes-bug: #1983238
Change-Id: I2dc3888a56d802424c6d62a656b2e5fef9dabb3e
Diffstat (limited to 'glance_store/tests')
-rw-r--r-- | glance_store/tests/unit/cinder/test_cinder_base.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/glance_store/tests/unit/cinder/test_cinder_base.py b/glance_store/tests/unit/cinder/test_cinder_base.py index acdb70b..922b161 100644 --- a/glance_store/tests/unit/cinder/test_cinder_base.py +++ b/glance_store/tests/unit/cinder/test_cinder_base.py @@ -207,7 +207,8 @@ class TestCinderStoreBase(object): multipath_supported=False, enforce_multipath=False, encrypted_nfs=False, qcow2_vol=False, - multiattach=False): + multiattach=False, + update_attachment_error=None): fake_volume = mock.MagicMock(id=str(uuid.uuid4()), status='available', multiattach=multiattach) fake_volume.manager.get.return_value = fake_volume @@ -284,6 +285,9 @@ class TestCinderStoreBase(object): 'getaddrinfo') as mock_get_host_ip, \ mock.patch.object(cinder.strutils, 'mask_dict_password'): + if update_attachment_error: + attach_update.side_effect = update_attachment_error + fake_host = 'fake_host' fake_addr_info = [[0, 1, 2, 3, ['127.0.0.1']]] fake_ip = fake_addr_info[0][4][0] @@ -309,9 +313,14 @@ class TestCinderStoreBase(object): except exceptions.BackendException: attach_delete.assert_called_once_with( fake_client, fake_attachment_id) + elif update_attachment_error: + self.assertRaises(type(update_attachment_error), do_open) else: do_open() - if not (encrypted_nfs or qcow2_vol): + if update_attachment_error: + attach_delete.assert_called_once_with( + fake_client, fake_attachment_id) + elif not (encrypted_nfs or qcow2_vol): mock_conn.assert_called_once_with( root_helper, fake_ip, multipath_supported, enforce_multipath, @@ -353,8 +362,10 @@ class TestCinderStoreBase(object): def test_open_cinder_volume_ro(self): self._test_open_cinder_volume('rb', 'ro', None) - def test_open_cinder_volume_error(self): - self._test_open_cinder_volume('wb', 'rw', IOError) + def test_open_cinder_volume_update_attachment_error(self): + err = Exception("update attachment fake error") + self._test_open_cinder_volume('rb', 'ro', None, + update_attachment_error=err) def test_open_cinder_volume_nfs_encrypted(self): self._test_open_cinder_volume('rb', 'ro', None, encrypted_nfs=True) |