diff --git a/glance/tests/stubs.py b/glance/tests/stubs.py index 5aa027a934..583ad565e1 100644 --- a/glance/tests/stubs.py +++ b/glance/tests/stubs.py @@ -161,19 +161,6 @@ def stub_out_registry_and_store_server(stubs, base_dir, **kwargs): setattr(res, 'read', fake_reader) return res - def fake_get_connection_type(client): - """Returns the proper connection type.""" - DEFAULT_REGISTRY_PORT = 9191 - DEFAULT_API_PORT = 9292 - - if (client.port == DEFAULT_API_PORT and - client.host == '0.0.0.0'): - return FakeGlanceConnection - elif (client.port == DEFAULT_REGISTRY_PORT and - client.host == '0.0.0.0'): - rserver = kwargs.get("registry") - return FakeRegistryConnection(registry=rserver) - def fake_image_iter(self): for i in self.source.app_iter: yield i @@ -187,9 +174,5 @@ def stub_out_registry_and_store_server(stubs, base_dir, **kwargs): assert glance.common.client.SENDFILE_SUPPORTED return force - stubs.Set(glance.common.client.BaseClient, 'get_connection_type', - fake_get_connection_type) setattr(glance.common.client.BaseClient, '_stub_orig_sendable', glance.common.client.BaseClient._sendable) - stubs.Set(glance.common.client.BaseClient, '_sendable', - fake_sendable) diff --git a/glance/tests/unit/base.py b/glance/tests/unit/base.py index 69de6fa5ba..cc35342a36 100644 --- a/glance/tests/unit/base.py +++ b/glance/tests/unit/base.py @@ -103,9 +103,23 @@ class IsolatedUnitTest(StoreClearingUnitTest): group="glance_store") store.create_stores() - stubs.stub_out_registry_and_store_server(self.stubs, - self.test_dir, - registry=self.registry) + + def fake_get_conection_type(client): + DEFAULT_REGISTRY_PORT = 9191 + DEFAULT_API_PORT = 9292 + + if (client.port == DEFAULT_API_PORT and + client.host == '0.0.0.0'): + return stubs.FakeGlanceConnection + elif (client.port == DEFAULT_REGISTRY_PORT and + client.host == '0.0.0.0'): + return stubs.FakeRegistryConnection(registry=self.registry) + + self.patcher = mock.patch( + 'glance.common.client.BaseClient.get_connection_type', + fake_get_conection_type) + self.addCleanup(self.patcher.stop) + self.patcher.start() def set_policy_rules(self, rules): fap = open(CONF.oslo_policy.policy_file, 'w') @@ -127,7 +141,7 @@ class MultiIsolatedUnitTest(MultiStoreClearingUnitTest): lockutils.set_defaults(os.path.join(self.test_dir)) self.config(debug=False) - stubs.stub_out_registry_and_store_server(self.stubs, + stubs.stub_out_registry_and_store_server(self, self.test_dir, registry=self.registry) diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 0b0d143b02..774500598e 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -31,7 +31,6 @@ from oslo_config import fixture as cfg_fixture from oslo_log.fixture import logging_error as log_fixture from oslo_log import log from oslo_serialization import jsonutils -from oslotest import moxstubout import six from six.moves import BaseHTTPServer from six.moves import http_client as http @@ -78,8 +77,6 @@ class BaseTestCase(testtools.TestCase): # the following policy tests config.parse_args(args=[]) self.addCleanup(CONF.reset) - mox_fixture = self.useFixture(moxstubout.MoxStubout()) - self.stubs = mox_fixture.stubs self.mock_object(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc')