Merge "Update service clist commands for v2 and v3"

This commit is contained in:
Jenkins 2015-01-16 20:52:07 +00:00 committed by Gerrit Code Review
commit ee62718dc8
5 changed files with 48 additions and 24 deletions

View File

@ -54,7 +54,9 @@ Delete service
os service delete
<service>
:option:`<service>`
.. _service_delete-type:
.. describe:: <service>
Service to delete (type, name or ID)
service list
@ -72,11 +74,8 @@ List services
List additional fields in output
*Identity version 2 only*
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.
Returns service fields ID, Name and Type. :option:`--long` adds Description
and Enabled (*Identity version 3 only*) to the output.
service set
-----------

View File

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

View File

@ -15,7 +15,6 @@
"""Identity v3 Service action implementations"""
import argparse
import logging
import six
@ -111,26 +110,27 @@ class ListService(lister.Lister):
log = logging.getLogger(__name__ + '.ListService')
def get_parser(self, prog_name):
"""The --long option is here for compatibility only."""
parser = super(ListService, self).get_parser(prog_name)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=argparse.SUPPRESS,
help='List additional fields in output',
)
return parser
def take_action(self, 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()
return (columns,
(utils.get_item_properties(
s, columns,
formatters={},
) for s in data))
return (
columns,
(utils.get_item_properties(s, columns) for s in data),
)
class SetService(command.Command):

View File

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

View File

@ -247,12 +247,36 @@ class TestServiceList(TestService):
self.services_mock.list.assert_called_with()
collist = ('ID', 'Name', 'Type', 'Enabled')
collist = ('ID', 'Name', 'Type')
self.assertEqual(columns, collist)
datalist = ((
identity_fakes.service_id,
identity_fakes.service_name,
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,
), )
self.assertEqual(tuple(data), datalist)