Add id and enabled param in ListIdentityProvider parser

when doing openstack identity provider list --name xyz_id,
and openstack identity provider list --enabled CLI raising
error unrecognized arguments, whereas in api-ref document [1],
user can pass name and enabled as optional query param. This
addresses the above issue, by adding param --id and --enabled in
parser of ListIdentityProvider.

[1] https://docs.openstack.org/api-ref/identity/v3-ext/?expanded=list-identity-providers-detail#list-identity-providers

Change-Id: I59ce3a5f54700ba5a735f0b3b4b3b73b3a8658fa
This commit is contained in:
Vishakha Agarwal 2020-07-24 19:22:39 +05:30
parent 82ebddca00
commit 1e053babf4
3 changed files with 81 additions and 1 deletions

View File

@ -143,10 +143,32 @@ class DeleteIdentityProvider(command.Command):
class ListIdentityProvider(command.Lister): class ListIdentityProvider(command.Lister):
_description = _("List identity providers") _description = _("List identity providers")
def get_parser(self, prog_name):
parser = super(ListIdentityProvider, self).get_parser(prog_name)
parser.add_argument(
'--id',
metavar='<id>',
help=_('The Identity Providers ID attribute'),
)
parser.add_argument(
'--enabled',
dest='enabled',
action='store_true',
help=_('The Identity Providers that are enabled will be returned'),
)
return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
columns = ('ID', 'Enabled', 'Domain ID', 'Description') columns = ('ID', 'Enabled', 'Domain ID', 'Description')
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
data = identity_client.federation.identity_providers.list()
kwargs = {}
if parsed_args.id:
kwargs['id'] = parsed_args.id
if parsed_args.enabled:
kwargs['enabled'] = True
data = identity_client.federation.identity_providers.list(**kwargs)
return (columns, return (columns,
(utils.get_item_properties( (utils.get_item_properties(
s, columns, s, columns,

View File

@ -384,6 +384,61 @@ class TestIdentityProviderList(TestIdentityProvider):
), ) ), )
self.assertListItemEqual(datalist, tuple(data)) self.assertListItemEqual(datalist, tuple(data))
def test_identity_provider_list_ID_option(self):
arglist = ['--id',
identity_fakes.idp_id]
verifylist = [
('id', identity_fakes.idp_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# In base command class Lister in cliff, abstract method take_action()
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
kwargs = {
'id': identity_fakes.idp_id
}
self.identity_providers_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
self.assertEqual(collist, columns)
datalist = ((
identity_fakes.idp_id,
True,
identity_fakes.domain_id,
identity_fakes.idp_description,
), )
self.assertListItemEqual(datalist, tuple(data))
def test_identity_provider_list_enabled_option(self):
arglist = ['--enabled']
verifylist = [
('enabled', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# In base command class Lister in cliff, abstract method take_action()
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
kwargs = {
'enabled': True
}
self.identity_providers_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
self.assertEqual(collist, columns)
datalist = ((
identity_fakes.idp_id,
True,
identity_fakes.domain_id,
identity_fakes.idp_description,
), )
self.assertListItemEqual(datalist, tuple(data))
class TestIdentityProviderSet(TestIdentityProvider): class TestIdentityProviderSet(TestIdentityProvider):

View File

@ -0,0 +1,3 @@
---
features:
- Add ``--id`` and ``--enabled`` option to ``identity provider list`` command.