From e2255fc1f4d08993f41d3ff2eacc62a3c5f66ecd Mon Sep 17 00:00:00 2001 From: David Goetz Date: Thu, 31 Jul 2014 10:19:10 -0700 Subject: [PATCH] fix expirer bug with unicode container listings If the container names in the expirer's account are returned as unicode strings (as is the case with some json libraries), the expirer compared eg u'1' == '1', which is problematic. This patch ensures that the unicode is coerced to ascii so the comparison is correct. Change-Id: I72b322e7513f7da32e8dc75c6bf0e7e016948c88 --- swift/obj/expirer.py | 2 +- test/unit/obj/test_expirer.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/swift/obj/expirer.py b/swift/obj/expirer.py index fdf711962b..158deacf85 100644 --- a/swift/obj/expirer.py +++ b/swift/obj/expirer.py @@ -118,7 +118,7 @@ class ObjectExpirer(Daemon): obj = o['name'].encode('utf8') if processes > 0: obj_process = int( - hashlib.md5('%s/%s' % (container, obj)). + hashlib.md5('%s/%s' % (str(container), obj)). hexdigest(), 16) if obj_process % processes != process: continue diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index faa46fdb2b..1e43f9c754 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -153,11 +153,12 @@ class TestObjectExpirer(TestCase): def delete_container(*a, **kw): pass + ukey = u'3' containers = { 0: set('1-one 2-two 3-three'.split()), 1: set('2-two 3-three 4-four'.split()), 2: set('5-five 6-six'.split()), - 3: set('7-seven'.split()), + ukey: set(u'7-seven\u2661'.split()), } x = ObjectExpirer({}) x.swift = InternalClient(containers) @@ -168,6 +169,8 @@ class TestObjectExpirer(TestCase): x.run_once() self.assertNotEqual(deleted_objects, x.deleted_objects) deleted_objects = deepcopy(x.deleted_objects) + self.assertEqual(containers[ukey].pop(), + deleted_objects[ukey].pop().decode('utf8')) self.assertEqual(containers, deleted_objects) def test_delete_object(self):