Set purge-props header correctly in image update
Currently when an image is updated, the purge property header is only set to true in some cases, but when required it isn't set to false Change-Id: I885a82643d2620f393f21c36b3ad95cb7ed43f2c Closes-Bug: 1318079
This commit is contained in:
@@ -305,13 +305,12 @@ class ImageManager(base.ManagerWithFind):
|
|||||||
kwargs.setdefault('size', image_size)
|
kwargs.setdefault('size', image_size)
|
||||||
|
|
||||||
hdrs = {}
|
hdrs = {}
|
||||||
try:
|
purge_props = 'false'
|
||||||
purge_props = 'true' if kwargs.pop('purge_props') else 'false'
|
purge_props_bool = kwargs.pop('purge_props', None)
|
||||||
except KeyError:
|
if purge_props_bool:
|
||||||
pass
|
purge_props = 'true'
|
||||||
else:
|
|
||||||
hdrs['x-glance-registry-purge-props'] = purge_props
|
|
||||||
|
|
||||||
|
hdrs['x-glance-registry-purge-props'] = purge_props
|
||||||
fields = {}
|
fields = {}
|
||||||
for field in kwargs:
|
for field in kwargs:
|
||||||
if field in UPDATE_PARAMS:
|
if field in UPDATE_PARAMS:
|
||||||
|
@@ -703,6 +703,7 @@ class ImageManagerTest(testtools.TestCase):
|
|||||||
'x-image-meta-property-a': 'b',
|
'x-image-meta-property-a': 'b',
|
||||||
'x-image-meta-property-c': 'd',
|
'x-image-meta-property-c': 'd',
|
||||||
'x-image-meta-deleted': 'False',
|
'x-image-meta-deleted': 'False',
|
||||||
|
'x-glance-registry-purge-props': 'false',
|
||||||
}
|
}
|
||||||
expect = [('PUT', '/v1/images/1', expect_hdrs, None)]
|
expect = [('PUT', '/v1/images/1', expect_hdrs, None)]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
@@ -715,7 +716,8 @@ class ImageManagerTest(testtools.TestCase):
|
|||||||
def test_update_with_data(self):
|
def test_update_with_data(self):
|
||||||
image_data = six.StringIO('XXX')
|
image_data = six.StringIO('XXX')
|
||||||
self.mgr.update('1', data=image_data)
|
self.mgr.update('1', data=image_data)
|
||||||
expect_headers = {'x-image-meta-size': '3'}
|
expect_headers = {'x-image-meta-size': '3',
|
||||||
|
'x-glance-registry-purge-props': 'false'}
|
||||||
expect = [('PUT', '/v1/images/1', expect_headers, image_data)]
|
expect = [('PUT', '/v1/images/1', expect_headers, image_data)]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
|
||||||
@@ -725,6 +727,12 @@ class ImageManagerTest(testtools.TestCase):
|
|||||||
expect = [('PUT', '/v1/images/1', expect_headers, None)]
|
expect = [('PUT', '/v1/images/1', expect_headers, None)]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
|
||||||
|
def test_update_with_purge_props_false(self):
|
||||||
|
self.mgr.update('1', purge_props=False)
|
||||||
|
expect_headers = {'x-glance-registry-purge-props': 'false'}
|
||||||
|
expect = [('PUT', '/v1/images/1', expect_headers, None)]
|
||||||
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
|
||||||
def test_update_req_id(self):
|
def test_update_req_id(self):
|
||||||
fields = {
|
fields = {
|
||||||
'purge_props': True,
|
'purge_props': True,
|
||||||
@@ -817,6 +825,7 @@ class ImageManagerTest(testtools.TestCase):
|
|||||||
'x-image-meta-name': 'bar',
|
'x-image-meta-name': 'bar',
|
||||||
'x-image-meta-container_format': 'bare',
|
'x-image-meta-container_format': 'bare',
|
||||||
'x-image-meta-disk_format': 'qcow2',
|
'x-image-meta-disk_format': 'qcow2',
|
||||||
|
'x-glance-registry-purge-props': 'false',
|
||||||
}
|
}
|
||||||
expect = [('PUT', '/v1/images/v2_created_img', expect_hdrs, None)]
|
expect = [('PUT', '/v1/images/v2_created_img', expect_hdrs, None)]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
@@ -849,7 +858,9 @@ class ImageTest(testtools.TestCase):
|
|||||||
expect = [
|
expect = [
|
||||||
('HEAD', '/v1/images/1', {}, None),
|
('HEAD', '/v1/images/1', {}, None),
|
||||||
('HEAD', '/v1/images/1', {}, None),
|
('HEAD', '/v1/images/1', {}, None),
|
||||||
('PUT', '/v1/images/1', {'x-image-meta-name': 'image-5'}, None),
|
('PUT', '/v1/images/1',
|
||||||
|
{'x-image-meta-name': 'image-5',
|
||||||
|
'x-glance-registry-purge-props': 'false'}, None),
|
||||||
]
|
]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user