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
This commit is contained in:
David Goetz 2014-07-31 10:19:10 -07:00 committed by John Dickinson
parent 9bc3b0ebd8
commit e2255fc1f4
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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):