From 4cec17bc86f33b0968e57e551d60c305d7d2cd41 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sun, 7 Oct 2012 23:45:55 +1100 Subject: [PATCH] Correct conversion of properties in headers Resolves bug 1063217. Started life as part of I63d9c589b7604ef24801f7b3eb0ce0e4fb5d7ec2. Change-Id: I91611fdfeaf57320e65669f4e8d75f984ede4523 --- bin/glance-replicator | 2 +- glance/tests/unit/test_glance_replicator.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/glance-replicator b/bin/glance-replicator index 129040e2..bdf0d5f3 100755 --- a/bin/glance-replicator +++ b/bin/glance-replicator @@ -177,7 +177,7 @@ class ImageService(object): d = {} for (header, value) in headers: if header.startswith('x-image-meta-property-'): - prop = header.replace('x-image-meta-properties', '') + prop = header.replace('x-image-meta-property-', '') d.setdefault('properties', {}) d['properties'][prop] = value else: diff --git a/glance/tests/unit/test_glance_replicator.py b/glance/tests/unit/test_glance_replicator.py index e2091a39..849250b0 100644 --- a/glance/tests/unit/test_glance_replicator.py +++ b/glance/tests/unit/test_glance_replicator.py @@ -162,10 +162,16 @@ class ImageServiceTestCase(test_utils.BaseTestCase): self.assertEquals(body.read(), image_contents) def test_rest_header_list_to_dict(self): - i = [('x-image-meta-banana', 42), ('gerkin', 12)] + i = [('x-image-meta-banana', 42), + ('gerkin', 12), + ('x-image-meta-property-frog', 11), + ('x-image-meta-property-duck', 12)] o = glance_replicator.ImageService._header_list_to_dict(i) self.assertTrue('banana' in o) self.assertTrue('gerkin' in o) + self.assertTrue('properties' in o) + self.assertTrue('frog' in o['properties']) + self.assertTrue('duck' in o['properties']) self.assertFalse('x-image-meta-banana' in o) def test_rest_get_image_meta(self): @@ -181,10 +187,14 @@ class ImageServiceTestCase(test_utils.BaseTestCase): def test_rest_dict_to_headers(self): i = {'banana': 42, - 'gerkin': 12} + 'gerkin': 12, + 'properties': {'frog': 1} + } o = glance_replicator.ImageService._dict_to_headers(i) self.assertTrue('x-image-meta-banana' in o) self.assertTrue('x-image-meta-gerkin' in o) + self.assertTrue('x-image-meta-property-frog' in o) + self.assertFalse('properties' in o) def test_rest_add_image(self): c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')