Clean up HASH_PATH_* patching

Previously, we'd sometimes shove strings into HASH_PATH_PREFIX or
HASH_PATH_SUFFIX, which would blow up on py3. Now, always use bytes.

Change-Id: Icab9981e8920da505c2395eb040f8261f2da6d2e
This commit is contained in:
Tim Burke 2018-11-01 17:49:35 +00:00
parent a13e44b39d
commit 3420921a33
12 changed files with 27 additions and 29 deletions

View File

@ -109,8 +109,8 @@ class TestRunDaemon(unittest.TestCase):
def setUp(self):
for patcher in [
mock.patch.object(utils, 'HASH_PATH_PREFIX', 'startcap'),
mock.patch.object(utils, 'HASH_PATH_SUFFIX', 'endcap'),
mock.patch.object(utils, 'HASH_PATH_PREFIX', b'startcap'),
mock.patch.object(utils, 'HASH_PATH_SUFFIX', b'endcap'),
mock.patch.object(utils, 'drop_privileges', lambda *args: None),
mock.patch.object(utils, 'capture_stdio', lambda *args: None),
]:

View File

@ -226,7 +226,7 @@ class TestCompressingfileReader(unittest.TestCase):
class TestInternalClient(unittest.TestCase):
@mock.patch('swift.common.utils.HASH_PATH_SUFFIX', new='endcap')
@mock.patch('swift.common.utils.HASH_PATH_SUFFIX', new=b'endcap')
@with_tempdir
def test_load_from_config(self, tempdir):
conf_path = os.path.join(tempdir, 'interal_client.conf')

View File

@ -70,7 +70,6 @@ class TestWSGI(unittest.TestCase):
"""Tests for swift.common.wsgi"""
def setUp(self):
utils.HASH_PATH_PREFIX = 'startcap'
if six.PY2:
self._orig_parsetype = mimetools.Message.parsetype
@ -1818,7 +1817,6 @@ class TestPipelineWrapper(unittest.TestCase):
@patch_policies
@mock.patch('swift.common.utils.HASH_PATH_SUFFIX', new='endcap')
class TestPipelineModification(unittest.TestCase):
def pipeline_modules(self, app):
# This is rather brittle; it'll break if a middleware stores its app

View File

@ -31,8 +31,8 @@ from swift.common.storage_policy import StoragePolicy
import test
from test.unit import patch_policies, with_tempdir
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'endcap'
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b'endcap'
class FakeRing(object):

View File

@ -37,8 +37,8 @@ from test import listen_zero
class TestContainerUpdater(unittest.TestCase):
def setUp(self):
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'startcap'
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b'startcap'
self.testdir = os.path.join(mkdtemp(), 'tmp_test_container_updater')
rmtree(self.testdir, ignore_errors=1)
os.mkdir(self.testdir)

View File

@ -147,8 +147,8 @@ class TestDiskFileModuleMethods(unittest.TestCase):
def setUp(self):
skip_if_no_xattrs()
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b''
# Setup a test ring per policy (stolen from common/test_ring.py)
self.testdir = tempfile.mkdtemp()
self.devices = os.path.join(self.testdir, 'node')

View File

@ -154,8 +154,8 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase):
_create_test_rings(self.testdir)
POLICIES[0].object_ring = ring.Ring(self.testdir, ring_name='object')
POLICIES[1].object_ring = ring.Ring(self.testdir, ring_name='object-1')
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b''
self.devices = os.path.join(self.testdir, 'node')
os.makedirs(self.devices)
os.mkdir(os.path.join(self.devices, 'sda1'))

View File

@ -224,8 +224,8 @@ class TestObjectReplicator(unittest.TestCase):
def setUp(self):
skip_if_no_xattrs()
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b''
# recon cache path
self.recon_cache = tempfile.mkdtemp()
rmtree(self.recon_cache, ignore_errors=1)

View File

@ -139,8 +139,8 @@ class TestObjectController(unittest.TestCase):
def setUp(self):
"""Set up for testing swift.object.server.ObjectController"""
skip_if_no_xattrs()
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'startcap'
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b'startcap'
self.tmpdir = mkdtemp()
self.testdir = os.path.join(self.tmpdir,
'tmp_test_object_server_ObjectController')
@ -958,7 +958,7 @@ class TestObjectController(unittest.TestCase):
headers=put_headers, body='test')
with mock.patch('swift.obj.server.http_connect', fake_http_connect), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', b''), \
fake_spawn():
resp = req.get_response(self.object_controller)
@ -1002,7 +1002,7 @@ class TestObjectController(unittest.TestCase):
headers=post_headers)
with mock.patch('swift.obj.server.http_connect', fake_http_connect), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', b''), \
fake_spawn():
resp = req.get_response(self.object_controller)
@ -1112,7 +1112,7 @@ class TestObjectController(unittest.TestCase):
'X-Backend-Redirect-Timestamp': next(self.ts).internal}
with mocked_http_conn(301, headers=[resp_headers]) as conn, \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''),\
mock.patch('swift.common.utils.HASH_PATH_PREFIX', b''),\
fake_spawn():
resp = req.get_response(self.object_controller)
@ -5088,7 +5088,7 @@ class TestObjectController(unittest.TestCase):
policy = random.choice(list(POLICIES))
self._stage_tmp_dir(policy)
_prefix = utils.HASH_PATH_PREFIX
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_PREFIX = b''
def fake_http_connect(*args):
raise Exception('test')
@ -5119,7 +5119,7 @@ class TestObjectController(unittest.TestCase):
policy = random.choice(list(POLICIES))
self._stage_tmp_dir(policy)
_prefix = utils.HASH_PATH_PREFIX
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_PREFIX = b''
def fake_http_connect(status):
@ -5164,7 +5164,7 @@ class TestObjectController(unittest.TestCase):
def test_async_update_does_not_save_on_2xx(self):
_prefix = utils.HASH_PATH_PREFIX
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_PREFIX = b''
def fake_http_connect(status):
@ -5200,7 +5200,7 @@ class TestObjectController(unittest.TestCase):
policy = random.choice(list(POLICIES))
self._stage_tmp_dir(policy)
_prefix = utils.HASH_PATH_PREFIX
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_PREFIX = b''
def fake_http_connect():

View File

@ -44,8 +44,8 @@ class TestReceiver(unittest.TestCase):
def setUp(self):
skip_if_no_xattrs()
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'startcap'
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b'startcap'
# Not sure why the test.unit stuff isn't taking effect here; so I'm
# reinforcing it.
self.testdir = os.path.join(

View File

@ -68,8 +68,8 @@ _mocked_policies = [StoragePolicy(0, 'zero', False),
class TestObjectUpdater(unittest.TestCase):
def setUp(self):
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = ''
utils.HASH_PATH_SUFFIX = b'endcap'
utils.HASH_PATH_PREFIX = b''
self.testdir = mkdtemp()
ring_file = os.path.join(self.testdir, 'container.ring.gz')
with closing(GzipFile(ring_file, 'wb')) as f:

View File

@ -1223,7 +1223,7 @@ class TestProxyServerLoading(unittest.TestCase):
def setUp(self):
self._orig_hash_suffix = utils.HASH_PATH_SUFFIX
utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_SUFFIX = b'endcap'
self.tempdir = mkdtemp()
def tearDown(self):