Skip to content

Commit e5ee4b8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Support list commands by group name keyword"
2 parents f63a9f4 + 0898eba commit e5ee4b8

5 files changed

Lines changed: 101 additions & 0 deletions

File tree

doc/source/command-objects/command.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ List recognized commands by group
1515
.. code:: bash
1616
1717
openstack command list
18+
[--group <group-keyword>]
19+
20+
.. option:: --group <group-keyword>
21+
22+
Show commands filtered by a command group, for example: identity, volume,
23+
compute, image, network and other keywords

openstackclient/common/module.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,26 @@ class ListCommand(command.Lister):
2929

3030
auth_required = False
3131

32+
def get_parser(self, prog_name):
33+
parser = super(ListCommand, self).get_parser(prog_name)
34+
parser.add_argument(
35+
'--group',
36+
metavar='<group-keyword>',
37+
help=_('Show commands filtered by a command group, for example: '
38+
'identity, volume, compute, image, network and '
39+
'other keywords'),
40+
)
41+
return parser
42+
3243
def take_action(self, parsed_args):
3344
cm = self.app.command_manager
3445
groups = cm.get_command_groups()
3546
groups = sorted(groups)
3647
columns = ('Command Group', 'Commands')
3748

49+
if parsed_args.group:
50+
groups = (group for group in groups if parsed_args.group in group)
51+
3852
commands = []
3953
for group in groups:
4054
command_names = cm.get_command_names(group)

openstackclient/tests/functional/common/test_module.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,38 @@ def test_module_list(self):
4242
cmd_output = json.loads(self.openstack('module list --all -f json'))
4343
for one_module in self.CLIENTS + self.LIBS:
4444
self.assertIn(one_module, cmd_output.keys())
45+
46+
47+
class CommandTest(base.TestCase):
48+
"""Functional tests for openstackclient command list."""
49+
GROUPS = [
50+
'openstack.volume.v2',
51+
'openstack.network.v2',
52+
'openstack.image.v2',
53+
'openstack.identity.v3',
54+
'openstack.compute.v2',
55+
'openstack.common',
56+
'openstack.cli',
57+
]
58+
59+
def test_command_list_no_option(self):
60+
cmd_output = json.loads(self.openstack('command list -f json'))
61+
group_names = [each.get('Command Group') for each in cmd_output]
62+
for one_group in self.GROUPS:
63+
self.assertIn(one_group, group_names)
64+
65+
def test_command_list_with_group(self):
66+
input_groups = [
67+
'volume',
68+
'network',
69+
'image',
70+
'identity',
71+
'compute.v2'
72+
]
73+
for each_input in input_groups:
74+
cmd_output = json.loads(self.openstack(
75+
'command list --group %s -f json' % each_input
76+
))
77+
group_names = [each.get('Command Group') for each in cmd_output]
78+
for each_name in group_names:
79+
self.assertIn(each_input, each_name)

openstackclient/tests/unit/common/test_module.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,41 @@ def test_command_list_no_options(self):
8888

8989
self.assertEqual(datalist, tuple(data))
9090

91+
def test_command_list_with_group_not_found(self):
92+
arglist = [
93+
'--group', 'not_exist',
94+
]
95+
verifylist = [
96+
('group', 'not_exist'),
97+
]
98+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
99+
100+
columns, data = self.cmd.take_action(parsed_args)
101+
102+
collist = ('Command Group', 'Commands')
103+
self.assertEqual(collist, columns)
104+
self.assertEqual([], data)
105+
106+
def test_command_list_with_group(self):
107+
arglist = [
108+
'--group', 'common',
109+
]
110+
verifylist = [
111+
('group', 'common'),
112+
]
113+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
114+
115+
columns, data = self.cmd.take_action(parsed_args)
116+
117+
collist = ('Command Group', 'Commands')
118+
self.assertEqual(collist, columns)
119+
datalist = ((
120+
'openstack.common',
121+
'limits show\nextension list'
122+
),)
123+
124+
self.assertEqual(datalist, tuple(data))
125+
91126

92127
@mock.patch.dict(
93128
'openstackclient.common.module.sys.modules',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
features:
3+
- |
4+
Support list commands by group name keyword. Add ``--group`` option to
5+
filter the commands by group name keyword, like: --group volume, list all
6+
openstack.volume.v2 (cinder) commands.
7+
That support the scenario that users need to know the current support
8+
commands of some OpenStack services(nova, neutron, cinder and so on) in
9+
OSC, and make it easier for users to find out the related commands that
10+
they care about.
11+
[Bug `1666780 <https://bugs.launchpad.net/python-openstackclient/+bug/1666780>`_]

0 commit comments

Comments
 (0)