From cb084f5289c5c23bdb9fabb413a81b32acb5a498 Mon Sep 17 00:00:00 2001 From: Mridula Joshi Date: Thu, 29 Jul 2021 12:25:37 +0000 Subject: [PATCH] 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 --- .../add-member-get-command-11c15e0a94ecd39a.yaml | 5 +++++ glanceclient/tests/unit/v2/test_members.py | 16 ++++++++++++++++ glanceclient/tests/unit/v2/test_shell_v2.py | 10 ++++++++++ glanceclient/v2/image_members.py | 6 ++++++ glanceclient/v2/shell.py | 10 +++++++++- 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 glanceclient/tests/unit/v2/releasenotes/notes/add-member-get-command-11c15e0a94ecd39a.yaml diff --git a/glanceclient/tests/unit/v2/releasenotes/notes/add-member-get-command-11c15e0a94ecd39a.yaml b/glanceclient/tests/unit/v2/releasenotes/notes/add-member-get-command-11c15e0a94ecd39a.yaml new file mode 100644 index 00000000..d5fce036 --- /dev/null +++ b/glanceclient/tests/unit/v2/releasenotes/notes/add-member-get-command-11c15e0a94ecd39a.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Bug 1938154_: Added member-get command + .. _1938154: https://bugs.launchpad.net/glance/+bug/1938154 diff --git a/glanceclient/tests/unit/v2/test_members.py b/glanceclient/tests/unit/v2/test_members.py index 7048a971..240f2b2a 100644 --- a/glanceclient/tests/unit/v2/test_members.py +++ b/glanceclient/tests/unit/v2/test_members.py @@ -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 diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index c2aa58ae..83c47273 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -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: diff --git a/glanceclient/v2/image_members.py b/glanceclient/v2/image_members.py index 780519a2..096429a5 100644 --- a/glanceclient/v2/image_members.py +++ b/glanceclient/v2/image_members.py @@ -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' % diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index c38d046c..5f83bd27 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -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='', + help=_('Image from which to display member.')) +@utils.arg('member_id', metavar='', + 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='', help=_('Image from which to remove member.')) @utils.arg('member_id', metavar='',