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
This commit is contained in:
Dean Troyer 2015-01-16 10:54:00 -06:00
parent 9057cedfd4
commit c2c3f2e0f2
5 changed files with 48 additions and 24 deletions

View File

@ -54,7 +54,9 @@ Delete service
os service delete os service delete
<service> <service>
:option:`<service>` .. _service_delete-type:
.. describe:: <service>
Service to delete (type, name or ID) Service to delete (type, name or ID)
service list service list
@ -72,11 +74,8 @@ List services
List additional fields in output List additional fields in output
*Identity version 2 only* Returns service fields ID, Name and Type. :option:`--long` adds Description
and Enabled (*Identity version 3 only*) to the output.
Returns service fields ID and Name, `--long` adds Type and Description
to the output. When Identity API version 3 is selected all columns are
always displayed, `--long` is silently accepted for backward-compatibility.
service set service set
----------- -----------

View File

@ -125,7 +125,8 @@ class ListService(lister.Lister):
'--long', '--long',
action='store_true', action='store_true',
default=False, default=False,
help=_('List additional fields in output')) help=_('List additional fields in output'),
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -134,13 +135,12 @@ class ListService(lister.Lister):
if parsed_args.long: if parsed_args.long:
columns = ('ID', 'Name', 'Type', 'Description') columns = ('ID', 'Name', 'Type', 'Description')
else: else:
columns = ('ID', 'Name') columns = ('ID', 'Name', 'Type')
data = self.app.client_manager.identity.services.list() data = self.app.client_manager.identity.services.list()
return (columns, return (
(utils.get_item_properties( columns,
s, columns, (utils.get_item_properties(s, columns) for s in data),
formatters={}, )
) for s in data))
class ShowService(show.ShowOne): class ShowService(show.ShowOne):

View File

@ -15,7 +15,6 @@
"""Identity v3 Service action implementations""" """Identity v3 Service action implementations"""
import argparse
import logging import logging
import six import six
@ -111,26 +110,27 @@ class ListService(lister.Lister):
log = logging.getLogger(__name__ + '.ListService') log = logging.getLogger(__name__ + '.ListService')
def get_parser(self, prog_name): def get_parser(self, prog_name):
"""The --long option is here for compatibility only."""
parser = super(ListService, self).get_parser(prog_name) parser = super(ListService, self).get_parser(prog_name)
parser.add_argument( parser.add_argument(
'--long', '--long',
action='store_true', action='store_true',
default=False, default=False,
help=argparse.SUPPRESS, help='List additional fields in output',
) )
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args) self.log.debug('take_action(%s)', parsed_args)
columns = ('ID', 'Name', 'Type', 'Enabled') if parsed_args.long:
columns = ('ID', 'Name', 'Type', 'Description', 'Enabled')
else:
columns = ('ID', 'Name', 'Type')
data = self.app.client_manager.identity.services.list() data = self.app.client_manager.identity.services.list()
return (columns, return (
(utils.get_item_properties( columns,
s, columns, (utils.get_item_properties(s, columns) for s in data),
formatters={}, )
) for s in data))
class SetService(command.Command): class SetService(command.Command):

View File

@ -235,11 +235,12 @@ class TestServiceList(TestService):
self.services_mock.list.assert_called_with() self.services_mock.list.assert_called_with()
collist = ('ID', 'Name') collist = ('ID', 'Name', 'Type')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = (( datalist = ((
identity_fakes.service_id, identity_fakes.service_id,
identity_fakes.service_name, identity_fakes.service_name,
identity_fakes.service_type,
), ) ), )
self.assertEqual(tuple(data), datalist) self.assertEqual(tuple(data), datalist)

View File

@ -247,12 +247,36 @@ class TestServiceList(TestService):
self.services_mock.list.assert_called_with() self.services_mock.list.assert_called_with()
collist = ('ID', 'Name', 'Type', 'Enabled') collist = ('ID', 'Name', 'Type')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = (( datalist = ((
identity_fakes.service_id, identity_fakes.service_id,
identity_fakes.service_name, identity_fakes.service_name,
identity_fakes.service_type, identity_fakes.service_type,
), )
self.assertEqual(tuple(data), datalist)
def test_service_list_long(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.services_mock.list.assert_called_with()
collist = ('ID', 'Name', 'Type', 'Description', 'Enabled')
self.assertEqual(columns, collist)
datalist = ((
identity_fakes.service_id,
identity_fakes.service_name,
identity_fakes.service_type,
identity_fakes.service_description,
True, True,
), ) ), )
self.assertEqual(tuple(data), datalist) self.assertEqual(tuple(data), datalist)