Adding Glance method for listing image members and unit test
This is necessary for checking from Cinder's side whether the current project has access to an image with 'shared' visibility. Often a clone_image request will arrive at a driver with Glance pointed at the same backend and within Glance the image is set to 'shared' visibility. Currently the driver will have to call Glance directly to determine if it should continue cloning the image, or return a permissions error. Change-Id: Idb9641e136bfc38bbfa881452053056e74bd0553
This commit is contained in:
parent
baabd09f63
commit
cec233d210
|
@ -253,6 +253,16 @@ class GlanceImageService(object):
|
|||
|
||||
return _params
|
||||
|
||||
def list_members(self, context, image_id):
|
||||
"""Returns a list of dicts with image member data."""
|
||||
try:
|
||||
return self._client.call(context,
|
||||
'list',
|
||||
controller='image_members',
|
||||
image_id=image_id)
|
||||
except Exception:
|
||||
_reraise_translated_image_exception(image_id)
|
||||
|
||||
def show(self, context, image_id):
|
||||
"""Returns a dict with image data for the given opaque image id."""
|
||||
try:
|
||||
|
@ -407,8 +417,8 @@ class GlanceImageService(object):
|
|||
# is redundant, so ignore it.
|
||||
image_meta = {key: getattr(image, key)
|
||||
for key in image.keys()
|
||||
if self._image_schema.is_base_property(key) is True
|
||||
and key != 'schema'}
|
||||
if self._image_schema.is_base_property(key) is True and
|
||||
key != 'schema'}
|
||||
|
||||
# NOTE(aarefiev): nova is expected that all image properties
|
||||
# (custom or defined in schema-image.json) stores in
|
||||
|
|
|
@ -130,11 +130,46 @@ class TestGlanceImageService(test.TestCase):
|
|||
fixture.update(kwargs)
|
||||
return fixture
|
||||
|
||||
@staticmethod
|
||||
def _make_image_member_fixtures(**kwargs):
|
||||
fixtures = []
|
||||
fixture = {'status': None,
|
||||
'image_id': None,
|
||||
'member_id': None,
|
||||
'created_at': '2018-03-14T21:48:13Z',
|
||||
'updated_at': '2018-03-14T21:50:51Z',
|
||||
'schema': '/v2/schemas/member'}
|
||||
fixture.update(kwargs)
|
||||
fixtures.append(fixture)
|
||||
return fixtures
|
||||
|
||||
def _make_datetime_fixture(self):
|
||||
return self._make_fixture(created_at=self.NOW_GLANCE_FORMAT,
|
||||
updated_at=self.NOW_GLANCE_FORMAT,
|
||||
deleted_at=self.NOW_GLANCE_FORMAT)
|
||||
|
||||
def test_list_members(self):
|
||||
fixture = {'status': None,
|
||||
'image_id': None,
|
||||
'member_id': None,
|
||||
'created_at': '2018-03-14T21:48:13Z',
|
||||
'updated_at': '2018-03-14T21:50:51Z',
|
||||
'schema': '/v2/schemas/member'}
|
||||
image_id = '97c1ef11-3a64-4756-9f8c-7f9fb5abe09f'
|
||||
member_id = '50fcc79f25524744a2c34682a1a74914'
|
||||
fixture['status'] = 'accepted'
|
||||
fixture['image_id'] = image_id
|
||||
fixture['member_id'] = member_id
|
||||
with mock.patch.object(self.service, '_client') as client_mock:
|
||||
client_mock.call.return_value = self._make_image_member_fixtures(
|
||||
image_id=image_id, member_id=member_id, status='accepted')
|
||||
result = self.service.list_members(self.context, image_id)
|
||||
self.assertEqual([fixture], result)
|
||||
client_mock.call.assert_called_once_with(self.context,
|
||||
'list',
|
||||
controller='image_members',
|
||||
image_id=image_id)
|
||||
|
||||
def test_get_api_servers(self):
|
||||
result = glance.get_api_servers(self.context)
|
||||
expected = (u'example.com:9292', False)
|
||||
|
|
Loading…
Reference in New Issue