Fix bug Swift ACL which disappears on Glance v1 images

Currently, when we make an update on a public image, Swift ACL disappears.
This patch allows to avoid the ACL update if there is no change to the
is_public_attribute.
If an update is made on a Glance image without changing the public attribute
or location, then the function which modifies ACLS is not called, in order
to keep ACLS.

Closes-Bug: 1584076

Change-Id: I21e9deb9105faee87500998eff47c6faa1d02914
This commit is contained in:
Nolwenn Cauchois 2016-05-24 17:01:03 +02:00
parent 8dd23d0b9c
commit d719b3a164
2 changed files with 19 additions and 2 deletions

View File

@ -1016,8 +1016,9 @@ class Controller(controller.BaseController):
orig_or_updated_loc = location or orig_image_meta.get('location')
if orig_or_updated_loc:
try:
self.update_store_acls(req, id, orig_or_updated_loc,
public=is_public)
if is_public is not None or location is not None:
self.update_store_acls(req, id, orig_or_updated_loc,
public=is_public)
except store.BadStoreUri:
msg = _("Invalid location: %s") % location
LOG.warn(msg)

View File

@ -2262,6 +2262,22 @@ class TestGlanceAPI(base.IsolatedUnitTest):
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
@mock.patch.object(registry, 'update_image_metadata')
def test_update_without_public_attribute(self, mock_update_image_metadata):
req = webob.Request.blank("/images/%s" % UUID1)
req.context = self.context
image_meta = {'properties': {}}
image_controller = glance.api.v1.images.Controller()
with mock.patch.object(
image_controller, 'update_store_acls'
) as mock_update_store_acls:
mock_update_store_acls.return_value = None
mock_update_image_metadata.return_value = {}
image_controller.update(
req, UUID1, image_meta, None)
self.assertEqual(0, mock_update_store_acls.call_count)
def test_add_image_wrong_content_type(self):
fixture_headers = {
'x-image-meta-name': 'fake image #3',