diff options
author | Dmitry Tantsur <dtantsur@protonmail.com> | 2022-10-31 11:19:08 +0100 |
---|---|---|
committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2022-11-09 12:26:05 +0000 |
commit | 4de58fa80763df74672a8b6d0b73483b1e8ed3e3 (patch) | |
tree | b4c20a7d891f5497f8b27510ef4e9c49a492f65d /ironic/tests/unit/common | |
parent | 9a06744458fbab6e44ec4bd8fa9816f65a770d29 (diff) | |
download | ironic-4de58fa80763df74672a8b6d0b73483b1e8ed3e3.tar.gz |
Fix the invalid glance client test
It relied on mocking tenacity.retry, but it's executed on class
initialization. Depending on the ordering, it may do nothing or
it may replace ImageService.call with a mock.
Instead, add a new tenacity helper that loads an option in runtime.
As a nice side effect, [glance]num_retries is now mutable.
Change-Id: I2e02231d294997e824db77c998ef8d352fa69075
(cherry picked from commit cab51a9fcc022f2e4bb634277dd20e90e2dc78f7)
Diffstat (limited to 'ironic/tests/unit/common')
-rw-r--r-- | ironic/tests/unit/common/test_glance_service.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/ironic/tests/unit/common/test_glance_service.py b/ironic/tests/unit/common/test_glance_service.py index 6be0fccd9..a6dd11d3e 100644 --- a/ironic/tests/unit/common/test_glance_service.py +++ b/ironic/tests/unit/common/test_glance_service.py @@ -24,7 +24,6 @@ from glanceclient import exc as glance_exc from keystoneauth1 import loading as ks_loading from oslo_config import cfg from oslo_utils import uuidutils -import tenacity import testtools from ironic.common import context @@ -204,20 +203,18 @@ class TestGlanceImageService(base.TestCase): image_id = uuidutils.generate_uuid() writer = NullWriter() - with mock.patch.object(tenacity, 'retry', autospec=True) as mock_retry: - # When retries are disabled, we should get an exception - self.config(num_retries=0, group='glance') - self.assertRaises(exception.GlanceConnectionFailed, - stub_service.download, image_id, writer) - - # Now lets enable retries. No exception should happen now. - self.config(num_retries=1, group='glance') - importlib.reload(image_service) - stub_service = image_service.GlanceImageService(stub_client, - stub_context) - tries = [0] - stub_service.download(image_id, writer) - mock_retry.assert_called_once() + # When retries are disabled, we should get an exception + self.config(num_retries=0, group='glance') + self.assertRaises(exception.GlanceConnectionFailed, + stub_service.download, image_id, writer) + + # Now lets enable retries. No exception should happen now. + self.config(num_retries=1, group='glance') + importlib.reload(image_service) + stub_service = image_service.GlanceImageService(stub_client, + stub_context) + tries = [0] + stub_service.download(image_id, writer) def test_download_no_data(self): self.client.fake_wrapped = None |