From c2c3f2e0f23f857aa2c8ce17e310996e90ea9b54 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Fri, 16 Jan 2015 10:54:00 -0600 Subject: [PATCH] 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 --- doc/source/command-objects/service.rst | 11 ++++---- openstackclient/identity/v2_0/service.py | 14 +++++----- openstackclient/identity/v3/service.py | 18 ++++++------- .../tests/identity/v2_0/test_service.py | 3 ++- .../tests/identity/v3/test_service.py | 26 ++++++++++++++++++- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/doc/source/command-objects/service.rst b/doc/source/command-objects/service.rst index d4f63de883..352f68a0d4 100644 --- a/doc/source/command-objects/service.rst +++ b/doc/source/command-objects/service.rst @@ -54,7 +54,9 @@ Delete service os service delete -:option:`` +.. _service_delete-type: +.. describe:: + 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 ----------- diff --git a/openstackclient/identity/v2_0/service.py b/openstackclient/identity/v2_0/service.py index 208f7fbcee..f8630238b6 100644 --- a/openstackclient/identity/v2_0/service.py +++ b/openstackclient/identity/v2_0/service.py @@ -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): diff --git a/openstackclient/identity/v3/service.py b/openstackclient/identity/v3/service.py index 126292538c..d63a953789 100644 --- a/openstackclient/identity/v3/service.py +++ b/openstackclient/identity/v3/service.py @@ -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): diff --git a/openstackclient/tests/identity/v2_0/test_service.py b/openstackclient/tests/identity/v2_0/test_service.py index a0adea4e9e..73606585a6 100644 --- a/openstackclient/tests/identity/v2_0/test_service.py +++ b/openstackclient/tests/identity/v2_0/test_service.py @@ -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) diff --git a/openstackclient/tests/identity/v3/test_service.py b/openstackclient/tests/identity/v3/test_service.py index 5e4dc58508..7766a29cf2 100644 --- a/openstackclient/tests/identity/v3/test_service.py +++ b/openstackclient/tests/identity/v3/test_service.py @@ -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)