From 6676d74f8f63e8349986cfd31bc958feda935f4c Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Thu, 4 Oct 2018 17:55:03 -0500 Subject: [PATCH] py3: everything account except the real things The the 80% of the work still remain in server and replicator, but let's knock this out. Change-Id: I1e1dee8f8c77212183b0ef2b574b57ad1051d57e --- swift/account/reaper.py | 13 +++++++++---- test/unit/account/test_reaper.py | 6 ++---- tox.ini | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 4b7c7adad9..86d6c83f51 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -270,7 +270,11 @@ class AccountReaper(Daemon): break try: for (container, _junk, _junk, _junk, _junk) in containers: - this_shard = int(md5(container).hexdigest(), 16) % \ + if six.PY3: + container_ = container.encode('utf-8') + else: + container_ = container + this_shard = int(md5(container_).hexdigest(), 16) % \ len(nodes) if container_shard not in (this_shard, None): continue @@ -393,10 +397,11 @@ class AccountReaper(Daemon): self.logger.error('ERROR: invalid storage policy index: %r' % policy_index) for obj in objects: - if isinstance(obj['name'], six.text_type): - obj['name'] = obj['name'].encode('utf8') + obj_name = obj['name'] + if isinstance(obj_name, six.text_type): + obj_name = obj_name.encode('utf8') pool.spawn(self.reap_object, account, container, part, - nodes, obj['name'], policy_index) + nodes, obj_name, policy_index) pool.waitall() except (Exception, Timeout): self.logger.exception(_('Exception with objects for container ' diff --git a/test/unit/account/test_reaper.py b/test/unit/account/test_reaper.py index ea4b5427f1..8d490e5447 100644 --- a/test/unit/account/test_reaper.py +++ b/test/unit/account/test_reaper.py @@ -841,12 +841,10 @@ class TestReaper(unittest.TestCase): r = init_reaper() with patch('swift.account.reaper.sleep', fake_sleep): with patch('swift.account.reaper.random.random', fake_random): - try: + with self.assertRaises(Exception) as raised: r.run_forever() - except Exception as err: - pass self.assertEqual(self.val, 1) - self.assertEqual(str(err), 'exit') + self.assertEqual(str(raised.exception), 'exit') if __name__ == '__main__': diff --git a/tox.ini b/tox.ini index 8f70c95d59..87824cf47d 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,9 @@ setenv = VIRTUAL_ENV={envdir} [testenv:py35] commands = nosetests {posargs:\ + test/unit/account/test_auditor.py \ test/unit/account/test_backend.py \ + test/unit/account/test_reaper.py \ test/unit/account/test_utils.py \ test/unit/cli/test_dispersion_report.py \ test/unit/cli/test_form_signature.py \