From f0d891a3edbf9978f8c427df05e8c912fce54cf4 Mon Sep 17 00:00:00 2001 From: Erno Kuvaja Date: Fri, 9 Jul 2021 13:48:45 +0100 Subject: [PATCH] 'community' images need to be treated as public Even though 'community' images are not listed by default their behaviour is like public images otherwise. This means that the image data needs to be available for everyone and thus the acls for the file/object should be like public too. Change-Id: I79683c81233b35f2399119128a63d33d69c50eeb Closes-bug: #1885928 --- glance/location.py | 4 ++-- glance/tests/unit/v2/test_images_resource.py | 25 +++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/glance/location.py b/glance/location.py index 3c20cf86b7..8484017062 100644 --- a/glance/location.py +++ b/glance/location.py @@ -51,7 +51,7 @@ class ImageRepoProxy(glance.domain.proxy.Repo): self.db_api = glance.db.get_api() def _set_acls(self, image): - public = image.visibility == 'public' + public = image.visibility in ['public', 'community'] member_ids = [] if image.locations and not public: member_repo = _get_member_repo_for_store(image, @@ -624,7 +624,7 @@ class ImageMemberRepoProxy(glance.domain.proxy.Repo): super(ImageMemberRepoProxy, self).__init__(repo) def _set_acls(self): - public = self.image.visibility == 'public' + public = self.image.visibility in ['public', 'community'] if self.image.locations and not public: member_ids = [m.member_id for m in self.repo.list()] for location in self.image.locations: diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index 2f34c2bef3..2318f55b69 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -2307,12 +2307,13 @@ class TestImagesController(base.IsolatedUnitTest): @mock.patch.object(glance.location.ImageRepoProxy, '_set_acls') @mock.patch.object(store, 'get_size_from_uri_and_backend') @mock.patch.object(store, 'get_size_from_backend') - def test_add_location_on_queued(self, - mock_get_size, - mock_get_size_uri, - mock_set_acls, - mock_check_loc, - mock_calc): + def _test_add_location_on_queued(self, + visibility, + mock_get_size, + mock_get_size_uri, + mock_set_acls, + mock_check_loc, + mock_calc): mock_calc.return_value = 1 mock_get_size.return_value = 1 mock_get_size_uri.return_value = 1 @@ -2323,6 +2324,7 @@ class TestImagesController(base.IsolatedUnitTest): name='1', disk_format='raw', container_format='bare', + visibility=visibility, status='queued'), ] self.db.image_create(None, self.images[0]) @@ -2336,6 +2338,17 @@ class TestImagesController(base.IsolatedUnitTest): self.assertEqual(1, len(output.locations)) self.assertEqual(new_location, output.locations[0]) self.assertEqual('active', output.status) + self.assertEqual(visibility, output.visibility) + mock_set_acls.assert_called_once() + + def test_add_location_on_queued_shared(self): + self._test_add_location_on_queued('shared') + + def test_add_location_on_queued_community(self): + self._test_add_location_on_queued('community') + + def test_add_location_on_queued_public(self): + self._test_add_location_on_queued('public') @mock.patch.object(glance.quota, '_calc_required_size') @mock.patch.object(glance.location, '_check_image_location')