Use 'visibility' instead of 'is_public' when only use Glance API v2
Now cinder only uses Glance API v2, and remove Glance v1 API support. In Glance API v2, we're using 'visibility' instead of 'is_public', so there is not 'is_public' attribute for image. Change-Id: I14d2e1ecd1812fffd3be4baf9889a6250efa466b Closes-Bug: #1880062
This commit is contained in:
parent
7b15790581
commit
4c6be7e47a
@ -514,7 +514,11 @@ class GlanceImageService(object):
|
|||||||
if hasattr(context, 'auth_token') and context.auth_token:
|
if hasattr(context, 'auth_token') and context.auth_token:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if image.is_public or context.is_admin:
|
if context.is_admin:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if (getattr(image, 'is_public', False) or
|
||||||
|
getattr(image, 'visibility', 'private') == 'public'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
properties = image.properties
|
properties = image.properties
|
||||||
|
@ -251,6 +251,36 @@ class TestGlanceImageService(test.TestCase):
|
|||||||
actual = self.service.show(self.context, image_id)
|
actual = self.service.show(self.context, image_id)
|
||||||
self.assertDictEqual(expected, actual)
|
self.assertDictEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_create_without_is_public(self):
|
||||||
|
"""Test Creating images without is_public.
|
||||||
|
|
||||||
|
Ensure we can create an image without is_public attribute.
|
||||||
|
"""
|
||||||
|
fixture = {'name': 'test image',
|
||||||
|
'protected': False}
|
||||||
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
'id': image_id,
|
||||||
|
'name': 'test image',
|
||||||
|
'protected': False,
|
||||||
|
'size': None,
|
||||||
|
'min_disk': None,
|
||||||
|
'min_ram': None,
|
||||||
|
'disk_format': None,
|
||||||
|
'container_format': None,
|
||||||
|
'checksum': None,
|
||||||
|
'created_at': self.NOW_DATETIME,
|
||||||
|
'updated_at': self.NOW_DATETIME,
|
||||||
|
'deleted': None,
|
||||||
|
'status': None,
|
||||||
|
'properties': {},
|
||||||
|
'owner': None,
|
||||||
|
'visibility': None,
|
||||||
|
}
|
||||||
|
actual = self.service.show(self.context, image_id)
|
||||||
|
self.assertDictEqual(expected, actual)
|
||||||
|
|
||||||
def test_show_shared_image_membership_success(self):
|
def test_show_shared_image_membership_success(self):
|
||||||
"""Test Create Shared Image Membership Success
|
"""Test Create Shared Image Membership Success
|
||||||
|
|
||||||
@ -613,6 +643,61 @@ class TestGlanceImageService(test.TestCase):
|
|||||||
}
|
}
|
||||||
self.assertEqual(expected, image_meta)
|
self.assertEqual(expected, image_meta)
|
||||||
|
|
||||||
|
def test_show_passes_when_is_admin_in_the_context(self):
|
||||||
|
fixture = self._make_fixture(name='image2')
|
||||||
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
|
self.context.auth_token = False
|
||||||
|
self.context.is_admin = True
|
||||||
|
|
||||||
|
image_meta = self.service.show(self.context, image_id)
|
||||||
|
expected = {
|
||||||
|
'id': image_id,
|
||||||
|
'name': 'image2',
|
||||||
|
'protected': None,
|
||||||
|
'size': None,
|
||||||
|
'min_disk': None,
|
||||||
|
'min_ram': None,
|
||||||
|
'disk_format': None,
|
||||||
|
'container_format': None,
|
||||||
|
'checksum': None,
|
||||||
|
'created_at': self.NOW_DATETIME,
|
||||||
|
'updated_at': self.NOW_DATETIME,
|
||||||
|
'deleted': None,
|
||||||
|
'status': None,
|
||||||
|
'properties': {'properties': {}},
|
||||||
|
'owner': None,
|
||||||
|
'visibility': None
|
||||||
|
}
|
||||||
|
self.assertEqual(expected, image_meta)
|
||||||
|
|
||||||
|
def test_show_passes_when_is_public_in_visibility_param(self):
|
||||||
|
fixture = self._make_fixture(name='image3')
|
||||||
|
fixture['visibility'] = 'public'
|
||||||
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
|
self.context.auth_token = False
|
||||||
|
self.context.is_admin = False
|
||||||
|
|
||||||
|
image_meta = self.service.show(self.context, image_id)
|
||||||
|
expected = {
|
||||||
|
'id': image_id,
|
||||||
|
'name': 'image3',
|
||||||
|
'protected': None,
|
||||||
|
'size': None,
|
||||||
|
'min_disk': None,
|
||||||
|
'min_ram': None,
|
||||||
|
'disk_format': None,
|
||||||
|
'container_format': None,
|
||||||
|
'checksum': None,
|
||||||
|
'created_at': self.NOW_DATETIME,
|
||||||
|
'updated_at': self.NOW_DATETIME,
|
||||||
|
'deleted': None,
|
||||||
|
'status': None,
|
||||||
|
'properties': {'properties': {}},
|
||||||
|
'owner': None,
|
||||||
|
'visibility': 'public'
|
||||||
|
}
|
||||||
|
self.assertEqual(expected, image_meta)
|
||||||
|
|
||||||
def test_show_raises_when_no_authtoken_in_the_context(self):
|
def test_show_raises_when_no_authtoken_in_the_context(self):
|
||||||
fixture = self._make_fixture(name='image1',
|
fixture = self._make_fixture(name='image1',
|
||||||
is_public=False,
|
is_public=False,
|
||||||
@ -624,6 +709,30 @@ class TestGlanceImageService(test.TestCase):
|
|||||||
self.context,
|
self.context,
|
||||||
image_id)
|
image_id)
|
||||||
|
|
||||||
|
def test_show_raises_when_no_is_admin_in_the_context(self):
|
||||||
|
fixture = self._make_fixture(name='image2',
|
||||||
|
is_public=False,
|
||||||
|
protected=False)
|
||||||
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
|
self.context.auth_token = False
|
||||||
|
self.context.is_admin = False
|
||||||
|
self.assertRaises(exception.ImageNotFound,
|
||||||
|
self.service.show,
|
||||||
|
self.context,
|
||||||
|
image_id)
|
||||||
|
|
||||||
|
def test_show_raises_when_is_private_in_visibility_param(self):
|
||||||
|
fixture = self._make_fixture(name='image3',
|
||||||
|
protected=False)
|
||||||
|
fixture['visibility'] = 'private'
|
||||||
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
|
self.context.auth_token = False
|
||||||
|
self.context.is_admin = False
|
||||||
|
self.assertRaises(exception.ImageNotFound,
|
||||||
|
self.service.show,
|
||||||
|
self.context,
|
||||||
|
image_id)
|
||||||
|
|
||||||
def test_detail_passes_through_to_client(self):
|
def test_detail_passes_through_to_client(self):
|
||||||
fixture = self._make_fixture(name='image10', is_public=True)
|
fixture = self._make_fixture(name='image10', is_public=True)
|
||||||
image_id = self.service.create(self.context, fixture)['id']
|
image_id = self.service.create(self.context, fixture)['id']
|
||||||
@ -1041,8 +1150,8 @@ class TestGlanceImageServiceClient(test.TestCase):
|
|||||||
self.flags(auth_strategy='keystone')
|
self.flags(auth_strategy='keystone')
|
||||||
self.flags(glance_request_timeout=None)
|
self.flags(glance_request_timeout=None)
|
||||||
|
|
||||||
class MyGlanceStubClient(object):
|
class MyGlanceStubClient(test.TestCase):
|
||||||
def __init__(inst, version, *args, **kwargs):
|
def __init__(self, version, *args, **kwargs):
|
||||||
self.assertEqual('2', version)
|
self.assertEqual('2', version)
|
||||||
self.assertEqual("http://fake_host:9292", args[0])
|
self.assertEqual("http://fake_host:9292", args[0])
|
||||||
self.assertNotIn('timeout', kwargs)
|
self.assertNotIn('timeout', kwargs)
|
||||||
@ -1073,8 +1182,8 @@ class TestGlanceImageServiceClient(test.TestCase):
|
|||||||
self.flags(
|
self.flags(
|
||||||
glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')
|
glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')
|
||||||
|
|
||||||
class MyGlanceStubClient(object):
|
class MyGlanceStubClient(test.TestCase):
|
||||||
def __init__(inst, version, *args, **kwargs):
|
def __init__(self, version, *args, **kwargs):
|
||||||
self.assertEqual('2', version)
|
self.assertEqual('2', version)
|
||||||
self.assertEqual("https://fake_host:9292", args[0])
|
self.assertEqual("https://fake_host:9292", args[0])
|
||||||
self.assertNotIn('timeout', kwargs)
|
self.assertNotIn('timeout', kwargs)
|
||||||
@ -1103,8 +1212,8 @@ class TestGlanceImageServiceClient(test.TestCase):
|
|||||||
self.flags(
|
self.flags(
|
||||||
glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')
|
glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')
|
||||||
|
|
||||||
class MyGlanceStubClient(object):
|
class MyGlanceStubClient(test.TestCase):
|
||||||
def __init__(inst, version, *args, **kwargs):
|
def __init__(self, version, *args, **kwargs):
|
||||||
self.assertEqual('2', version)
|
self.assertEqual('2', version)
|
||||||
self.assertEqual('https://fake_host:9292', args[0])
|
self.assertEqual('https://fake_host:9292', args[0])
|
||||||
self.assertEqual(60, kwargs['timeout'])
|
self.assertEqual(60, kwargs['timeout'])
|
||||||
@ -1124,8 +1233,8 @@ class TestGlanceImageServiceClient(test.TestCase):
|
|||||||
self.flags(auth_strategy='noauth')
|
self.flags(auth_strategy='noauth')
|
||||||
self.flags(glance_request_timeout=None)
|
self.flags(glance_request_timeout=None)
|
||||||
|
|
||||||
class MyGlanceStubClient(object):
|
class MyGlanceStubClient(test.TestCase):
|
||||||
def __init__(inst, version, *args, **kwargs):
|
def __init__(self, version, *args, **kwargs):
|
||||||
self.assertEqual('2', version)
|
self.assertEqual('2', version)
|
||||||
self.assertEqual("http://fake_host:9292", args[0])
|
self.assertEqual("http://fake_host:9292", args[0])
|
||||||
self.assertNotIn('timeout', kwargs)
|
self.assertNotIn('timeout', kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user