Skip to content

Commit c2c3f2e

Browse files
author
Dean Troyer
committed
Update service clist commands for v2 and v3
Changes to the 'service list' commands for Identity v2 and v3: * Document support for --long * Add Description to v3 output with --long * v3 output is now (ID, Name, Type), with (Description, Enabled) added with --long * Change v2 output to match v3 output, with the absense of Enabled. * Update doc to match Closes-Bug: #1411337 Change-Id: I999e3df22f61350cdeba63bbb7d01145c2ffeeaf
1 parent 9057ced commit c2c3f2e

5 files changed

Lines changed: 48 additions & 24 deletions

File tree

‎doc/source/command-objects/service.rst‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Delete service
5454
os service delete
5555
<service>
5656
57-
:option:`<service>`
57+
.. _service_delete-type:
58+
.. describe:: <service>
59+
5860
Service to delete (type, name or ID)
5961

6062
service list
@@ -72,11 +74,8 @@ List services
7274

7375
List additional fields in output
7476

75-
*Identity version 2 only*
76-
77-
Returns service fields ID and Name, `--long` adds Type and Description
78-
to the output. When Identity API version 3 is selected all columns are
79-
always displayed, `--long` is silently accepted for backward-compatibility.
77+
Returns service fields ID, Name and Type. :option:`--long` adds Description
78+
and Enabled (*Identity version 3 only*) to the output.
8079

8180
service set
8281
-----------

‎openstackclient/identity/v2_0/service.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ def get_parser(self, prog_name):
125125
'--long',
126126
action='store_true',
127127
default=False,
128-
help=_('List additional fields in output'))
128+
help=_('List additional fields in output'),
129+
)
129130
return parser
130131

131132
def take_action(self, parsed_args):
@@ -134,13 +135,12 @@ def take_action(self, parsed_args):
134135
if parsed_args.long:
135136
columns = ('ID', 'Name', 'Type', 'Description')
136137
else:
137-
columns = ('ID', 'Name')
138+
columns = ('ID', 'Name', 'Type')
138139
data = self.app.client_manager.identity.services.list()
139-
return (columns,
140-
(utils.get_item_properties(
141-
s, columns,
142-
formatters={},
143-
) for s in data))
140+
return (
141+
columns,
142+
(utils.get_item_properties(s, columns) for s in data),
143+
)
144144

145145

146146
class ShowService(show.ShowOne):

‎openstackclient/identity/v3/service.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
"""Identity v3 Service action implementations"""
1717

18-
import argparse
1918
import logging
2019
import six
2120

@@ -111,26 +110,27 @@ class ListService(lister.Lister):
111110
log = logging.getLogger(__name__ + '.ListService')
112111

113112
def get_parser(self, prog_name):
114-
"""The --long option is here for compatibility only."""
115113
parser = super(ListService, self).get_parser(prog_name)
116114
parser.add_argument(
117115
'--long',
118116
action='store_true',
119117
default=False,
120-
help=argparse.SUPPRESS,
118+
help='List additional fields in output',
121119
)
122120
return parser
123121

124122
def take_action(self, parsed_args):
125123
self.log.debug('take_action(%s)', parsed_args)
126124

127-
columns = ('ID', 'Name', 'Type', 'Enabled')
125+
if parsed_args.long:
126+
columns = ('ID', 'Name', 'Type', 'Description', 'Enabled')
127+
else:
128+
columns = ('ID', 'Name', 'Type')
128129
data = self.app.client_manager.identity.services.list()
129-
return (columns,
130-
(utils.get_item_properties(
131-
s, columns,
132-
formatters={},
133-
) for s in data))
130+
return (
131+
columns,
132+
(utils.get_item_properties(s, columns) for s in data),
133+
)
134134

135135

136136
class SetService(command.Command):

‎openstackclient/tests/identity/v2_0/test_service.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ def test_service_list_no_options(self):
235235

236236
self.services_mock.list.assert_called_with()
237237

238-
collist = ('ID', 'Name')
238+
collist = ('ID', 'Name', 'Type')
239239
self.assertEqual(columns, collist)
240240
datalist = ((
241241
identity_fakes.service_id,
242242
identity_fakes.service_name,
243+
identity_fakes.service_type,
243244
), )
244245
self.assertEqual(tuple(data), datalist)
245246

‎openstackclient/tests/identity/v3/test_service.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,36 @@ def test_service_list_no_options(self):
247247

248248
self.services_mock.list.assert_called_with()
249249

250-
collist = ('ID', 'Name', 'Type', 'Enabled')
250+
collist = ('ID', 'Name', 'Type')
251251
self.assertEqual(columns, collist)
252252
datalist = ((
253253
identity_fakes.service_id,
254254
identity_fakes.service_name,
255255
identity_fakes.service_type,
256+
), )
257+
self.assertEqual(tuple(data), datalist)
258+
259+
def test_service_list_long(self):
260+
arglist = [
261+
'--long',
262+
]
263+
verifylist = [
264+
('long', True),
265+
]
266+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
267+
268+
# DisplayCommandBase.take_action() returns two tuples
269+
columns, data = self.cmd.take_action(parsed_args)
270+
271+
self.services_mock.list.assert_called_with()
272+
273+
collist = ('ID', 'Name', 'Type', 'Description', 'Enabled')
274+
self.assertEqual(columns, collist)
275+
datalist = ((
276+
identity_fakes.service_id,
277+
identity_fakes.service_name,
278+
identity_fakes.service_type,
279+
identity_fakes.service_description,
256280
True,
257281
), )
258282
self.assertEqual(tuple(data), datalist)

0 commit comments

Comments
 (0)