Add member-get command

It is observed that python-glanceclient was missing support for GET /v2/image/{image_id}/member/{member_id} API.
This patch adds new command `member-get` to support this missing operation.

Closes-Bug: #1938154

Change-Id: I3709f6a39535aa45bee70f468f015ac60a1375a8
This commit is contained in:
Mridula Joshi 2021-07-29 12:25:37 +00:00
parent 158d5f4248
commit cb084f5289
5 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Bug 1938154_: Added member-get command
.. _1938154: https://bugs.launchpad.net/glance/+bug/1938154

View File

@ -45,6 +45,17 @@ data_fixtures = {
)
},
'/v2/images/{image}/members/{mem}'.format(image=IMAGE, mem=MEMBER): {
'GET': (
{},
{
'image_id': IMAGE,
'member_id': MEMBER,
'status': 'pending',
'created_at': '2013-11-26T07:21:21Z',
'updated_at': '2013-11-26T07:21:21Z',
'schema': "/v2/schemas/member"
},
),
'DELETE': (
{},
None,
@ -90,6 +101,11 @@ class TestController(testtools.TestCase):
self.assertEqual(IMAGE, image_members[0].image_id)
self.assertEqual(MEMBER, image_members[0].member_id)
def test_get_image_members(self):
image_member = self.controller.get(IMAGE, MEMBER)
self.assertEqual(IMAGE, image_member.image_id)
self.assertEqual(MEMBER, image_member.member_id)
def test_delete_image_member(self):
image_id = IMAGE
member_id = MEMBER

View File

@ -2378,6 +2378,16 @@ class ShellV2Test(testtools.TestCase):
columns = ['Image ID', 'Member ID', 'Status']
utils.print_list.assert_called_once_with({}, columns)
def test_do_member_get(self):
args = self._make_args({'image_id': 'IMG-01', 'member_id': 'MEM-01'})
with mock.patch.object(self.gc.image_members, 'get') as mock_get:
mock_get.return_value = {}
test_shell.do_member_get(self.gc, args)
mock_get.assert_called_once_with('IMG-01', 'MEM-01')
utils.print_dict.assert_called_once_with({})
def test_do_member_create(self):
args = self._make_args({'image_id': 'IMG-01', 'member_id': 'MEM-01'})
with mock.patch.object(self.gc.image_members, 'create') as mock_create:

View File

@ -39,6 +39,12 @@ class Controller(object):
for member in body['members']:
yield self.model(member), resp
@utils.add_req_id_to_object()
def get(self, image_id, member_id):
url = '/v2/images/%s/members/%s' % (image_id, member_id)
resp, member = self.http_client.get(url)
return self.model(member), resp
@utils.add_req_id_to_object()
def delete(self, image_id, member_id):
resp, body = self.http_client.delete('/v2/images/%s/members/%s' %

View File

@ -490,12 +490,20 @@ def do_image_tasks(gc, args):
help=_('Image to display members of.'))
def do_member_list(gc, args):
"""Describe sharing permissions by image."""
members = gc.image_members.list(args.image_id)
columns = ['Image ID', 'Member ID', 'Status']
utils.print_list(members, columns)
@utils.arg('image_id', metavar='<IMAGE_ID>',
help=_('Image from which to display member.'))
@utils.arg('member_id', metavar='<MEMBER_ID>',
help=_('Project to display.'))
def do_member_get(gc, args):
"""Show details of an image member"""
member = gc.image_members.get(args.image_id, args.member_id)
utils.print_dict(member)
@utils.arg('image_id', metavar='<IMAGE_ID>',
help=_('Image from which to remove member.'))
@utils.arg('member_id', metavar='<MEMBER_ID>',