'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
This commit is contained in:
Erno Kuvaja 2021-07-09 13:48:45 +01:00 committed by Dan Smith
parent 77be0e3e23
commit f0d891a3ed
2 changed files with 21 additions and 8 deletions

View File

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

View File

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