diff --git a/test/unit/__init__.py b/test/unit/__init__.py index ba155b8a41..71dc8e44a5 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -41,16 +41,18 @@ import cPickle as pickle from gzip import GzipFile import mock as mocklib -DEFAULT_PATCH_POLICIES = [storage_policy.StoragePolicy(0, 'nulo', True), - storage_policy.StoragePolicy(1, 'unu')] -LEGACY_PATCH_POLICIES = [storage_policy.StoragePolicy(0, 'legacy', True)] - def patch_policies(thing_or_policies=None, legacy_only=False): if legacy_only: - default_policies = LEGACY_PATCH_POLICIES + default_policies = [storage_policy.StoragePolicy( + 0, 'legacy', True, object_ring=FakeRing())] else: - default_policies = DEFAULT_PATCH_POLICIES + default_policies = [ + storage_policy.StoragePolicy( + 0, 'nulo', True, object_ring=FakeRing()), + storage_policy.StoragePolicy( + 1, 'unu', object_ring=FakeRing()), + ] thing_or_policies = thing_or_policies or default_policies diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index 0d969b1814..b170794692 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -26,6 +26,7 @@ from test.unit import FakeLogger from eventlet.green import urllib2 from swift.common import internal_client from swift.common import swob +from swift.common.storage_policy import StoragePolicy from test.unit import with_tempdir, write_fake_ring, patch_policies from test.unit.common.middleware.helpers import FakeSwift @@ -202,7 +203,6 @@ class TestCompressingfileReader(unittest.TestCase): class TestInternalClient(unittest.TestCase): - @patch_policies(legacy_only=True) @mock.patch('swift.common.utils.HASH_PATH_SUFFIX', new='endcap') @with_tempdir def test_load_from_config(self, tempdir): @@ -232,7 +232,8 @@ class TestInternalClient(unittest.TestCase): write_fake_ring(container_ring_path) object_ring_path = os.path.join(tempdir, 'object.ring.gz') write_fake_ring(object_ring_path) - client = internal_client.InternalClient(conf_path, 'test', 1) + with patch_policies([StoragePolicy(0, 'legacy', True)]): + client = internal_client.InternalClient(conf_path, 'test', 1) self.assertEqual(client.account_ring, client.app.app.app.account_ring) self.assertEqual(client.account_ring.serialized_path, account_ring_path) diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 419b94f363..d173357fe7 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -40,8 +40,7 @@ import swift.container.server as container_server import swift.account.server as account_server from swift.common.swob import Request from swift.common import wsgi, utils -from swift.common.storage_policy import StoragePolicy, \ - StoragePolicyCollection +from swift.common.storage_policy import POLICIES from test.unit import temptree, with_tempdir, write_fake_ring, patch_policies @@ -51,16 +50,15 @@ from paste.deploy import loadwsgi def _fake_rings(tmpdir): write_fake_ring(os.path.join(tmpdir, 'account.ring.gz')) write_fake_ring(os.path.join(tmpdir, 'container.ring.gz')) - # Some storage-policy-specific fake rings. - policy = [StoragePolicy(0, 'zero'), - StoragePolicy(1, 'one', is_default=True)] - policies = StoragePolicyCollection(policy) - for pol in policies: + for policy in POLICIES: obj_ring_path = \ - os.path.join(tmpdir, pol.ring_name + '.ring.gz') + os.path.join(tmpdir, policy.ring_name + '.ring.gz') write_fake_ring(obj_ring_path) + # make sure there's no other ring cached on this policy + policy.object_ring = None +@patch_policies class TestWSGI(unittest.TestCase): """Tests for swift.common.wsgi""" @@ -757,6 +755,7 @@ class TestPipelineWrapper(unittest.TestCase): " catch_errors tempurl proxy-server") +@patch_policies @mock.patch('swift.common.utils.HASH_PATH_SUFFIX', new='endcap') class TestPipelineModification(unittest.TestCase): def pipeline_modules(self, app): @@ -1012,7 +1011,6 @@ class TestPipelineModification(unittest.TestCase): 'swift.common.middleware.dlo', 'swift.proxy.server']) - @patch_policies @with_tempdir def test_loadapp_proxy(self, tempdir): conf_path = os.path.join(tempdir, 'proxy-server.conf') @@ -1034,24 +1032,23 @@ class TestPipelineModification(unittest.TestCase): """ % tempdir with open(conf_path, 'w') as f: f.write(dedent(conf_body)) + _fake_rings(tempdir) account_ring_path = os.path.join(tempdir, 'account.ring.gz') - write_fake_ring(account_ring_path) container_ring_path = os.path.join(tempdir, 'container.ring.gz') - write_fake_ring(container_ring_path) - object_ring_path = os.path.join(tempdir, 'object.ring.gz') - write_fake_ring(object_ring_path) - object_1_ring_path = os.path.join(tempdir, 'object-1.ring.gz') - write_fake_ring(object_1_ring_path) + object_ring_paths = {} + for policy in POLICIES: + object_ring_paths[int(policy)] = os.path.join( + tempdir, policy.ring_name + '.ring.gz') + app = wsgi.loadapp(conf_path) proxy_app = app.app.app.app.app self.assertEqual(proxy_app.account_ring.serialized_path, account_ring_path) self.assertEqual(proxy_app.container_ring.serialized_path, container_ring_path) - self.assertEqual(proxy_app.get_object_ring(0).serialized_path, - object_ring_path) - self.assertEqual(proxy_app.get_object_ring(1).serialized_path, - object_1_ring_path) + for policy_index, expected_path in object_ring_paths.items(): + object_ring = proxy_app.get_object_ring(policy_index) + self.assertEqual(expected_path, object_ring.serialized_path) @with_tempdir def test_loadapp_storage(self, tempdir):