Add name and enabled param in ListDomain parser
when doing openstack domain list --name xyz_id, and openstack domain 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 --name and --enabled in parser of ListDomain. [1]https://docs.openstack.org/api-ref/identity/v3/?expanded=list-domains-detail#list-domains Change-Id: I3cdb511d3c7059ddfb802ca025188d8976c9302c
This commit is contained in:
parent
82ebddca00
commit
8628e52de7
@ -126,9 +126,30 @@ class DeleteDomain(command.Command):
|
|||||||
class ListDomain(command.Lister):
|
class ListDomain(command.Lister):
|
||||||
_description = _("List domains")
|
_description = _("List domains")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListDomain, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--name',
|
||||||
|
metavar='<name>',
|
||||||
|
help=_('The domain name'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--enabled',
|
||||||
|
dest='enabled',
|
||||||
|
action='store_true',
|
||||||
|
help=_('The domains that are enabled will be returned'),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
kwargs = {}
|
||||||
|
if parsed_args.name:
|
||||||
|
kwargs['name'] = parsed_args.name
|
||||||
|
if parsed_args.enabled:
|
||||||
|
kwargs['enabled'] = True
|
||||||
|
|
||||||
columns = ('ID', 'Name', 'Enabled', 'Description')
|
columns = ('ID', 'Name', 'Enabled', 'Description')
|
||||||
data = self.app.client_manager.identity.domains.list()
|
data = self.app.client_manager.identity.domains.list(**kwargs)
|
||||||
return (columns,
|
return (columns,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
s, columns,
|
s, columns,
|
||||||
|
@ -293,6 +293,61 @@ class TestDomainList(TestDomain):
|
|||||||
), )
|
), )
|
||||||
self.assertEqual(datalist, tuple(data))
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_domain_list_with_option_name(self):
|
||||||
|
arglist = ['--name',
|
||||||
|
self.domain.name]
|
||||||
|
verifylist = [
|
||||||
|
('name', self.domain.name)
|
||||||
|
]
|
||||||
|
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 = {
|
||||||
|
'name': self.domain.name
|
||||||
|
}
|
||||||
|
self.domains_mock.list.assert_called_with(**kwargs)
|
||||||
|
|
||||||
|
collist = ('ID', 'Name', 'Enabled', 'Description')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
datalist = ((
|
||||||
|
self.domain.id,
|
||||||
|
self.domain.name,
|
||||||
|
True,
|
||||||
|
self.domain.description,
|
||||||
|
), )
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_domain_list_with_option_enabled(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.domains_mock.list.assert_called_with(**kwargs)
|
||||||
|
|
||||||
|
collist = ('ID', 'Name', 'Enabled', 'Description')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
datalist = ((
|
||||||
|
self.domain.id,
|
||||||
|
self.domain.name,
|
||||||
|
True,
|
||||||
|
self.domain.description,
|
||||||
|
), )
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestDomainSet(TestDomain):
|
class TestDomainSet(TestDomain):
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add ``--name`` and ``--domain`` option to ``domain list`` command.
|
Loading…
Reference in New Issue
Block a user