From 2850d1714fbf5100a920d65b47bb748f8394af6d Mon Sep 17 00:00:00 2001 From: Madhuri Kumari Date: Sun, 2 Apr 2017 07:53:34 +0000 Subject: [PATCH] Add the support for 'detail' flag Magnum API supports a 'detail' flag to show the list of cluster templates with details but that was not supported at client. So this patch adds the support for cluster-template-list command. Change-Id: I7df73aae1c489132aaf091d162b1d081e65f09c7 Partial-Bug: #1674314 --- magnumclient/tests/v1/test_baymodels_shell.py | 10 +++++++++- .../tests/v1/test_clustertemplates_shell.py | 11 ++++++++++- magnumclient/v1/basemodels.py | 5 +++++ magnumclient/v1/baymodels_shell.py | 13 +++++++++++-- magnumclient/v1/cluster_templates_shell.py | 13 +++++++++++-- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/magnumclient/tests/v1/test_baymodels_shell.py b/magnumclient/tests/v1/test_baymodels_shell.py index 9eb37436..200cd5d5 100644 --- a/magnumclient/tests/v1/test_baymodels_shell.py +++ b/magnumclient/tests/v1/test_baymodels_shell.py @@ -37,11 +37,12 @@ class FakeBayModel(BayModel): class ShellTest(shell_test_base.TestCommandLineArgument): def _get_expected_args_list(self, limit=None, sort_dir=None, - sort_key=None): + sort_key=None, detail=False): expected_args = {} expected_args['limit'] = limit expected_args['sort_dir'] = sort_dir expected_args['sort_key'] = sort_key + expected_args['detail'] = detail return expected_args @@ -549,6 +550,13 @@ class ShellTest(shell_test_base.TestCommandLineArgument): expected_args = self._get_expected_args_list(1, 'asc', 'uuid') mock_list.assert_called_once_with(**expected_args) + @mock.patch('magnumclient.v1.baymodels.BayModelManager.list') + def test_baymodel_list_success_detailed(self, mock_list): + self._test_arg_success('baymodel-list ' + '--detail') + expected_args = self._get_expected_args_list(detail=True) + mock_list.assert_called_once_with(**expected_args) + @mock.patch('magnumclient.v1.baymodels.BayModelManager.list') def test_baymodel_list_ignored_duplicated_field(self, mock_list): mock_list.return_value = [FakeBayModel()] diff --git a/magnumclient/tests/v1/test_clustertemplates_shell.py b/magnumclient/tests/v1/test_clustertemplates_shell.py index 9e769c6b..8a1bc6fe 100644 --- a/magnumclient/tests/v1/test_clustertemplates_shell.py +++ b/magnumclient/tests/v1/test_clustertemplates_shell.py @@ -37,11 +37,12 @@ class FakeClusterTemplate(ClusterTemplate): class ShellTest(shell_test_base.TestCommandLineArgument): def _get_expected_args_list(self, limit=None, sort_dir=None, - sort_key=None): + sort_key=None, detail=False): expected_args = {} expected_args['limit'] = limit expected_args['sort_dir'] = sort_dir expected_args['sort_key'] = sort_key + expected_args['detail'] = detail return expected_args @@ -728,6 +729,14 @@ class ShellTest(shell_test_base.TestCommandLineArgument): expected_args = self._get_expected_args_list(1, 'asc', 'uuid') mock_list.assert_called_once_with(**expected_args) + @mock.patch( + 'magnumclient.v1.cluster_templates.ClusterTemplateManager.list') + def test_cluster_template_list_success_detailed(self, mock_list): + self._test_arg_success('cluster-template-list ' + '--detail') + expected_args = self._get_expected_args_list(detail=True) + mock_list.assert_called_once_with(**expected_args) + @mock.patch( 'magnumclient.v1.cluster_templates.ClusterTemplateManager.list') def test_cluster_template_list_ignored_duplicated_field(self, mock_list): diff --git a/magnumclient/v1/basemodels.py b/magnumclient/v1/basemodels.py index d2715c25..0334b892 100644 --- a/magnumclient/v1/basemodels.py +++ b/magnumclient/v1/basemodels.py @@ -24,6 +24,11 @@ CREATION_ATTRIBUTES = ['name', 'image_id', 'flavor_id', 'master_flavor_id', 'docker_storage_driver', 'master_lb_enabled', 'floating_ip_enabled'] +OUTPUT_ATTRIBUTES = CREATION_ATTRIBUTES + ['apiserver_port', 'created_at', + 'insecure_registry', 'links', + 'updated_at', 'cluster_distro', + 'uuid'] + class BaseModel(base.Resource): # model_name needs to be overridden by any derived class. diff --git a/magnumclient/v1/baymodels_shell.py b/magnumclient/v1/baymodels_shell.py index dfd6fb06..53bf7c0b 100644 --- a/magnumclient/v1/baymodels_shell.py +++ b/magnumclient/v1/baymodels_shell.py @@ -15,6 +15,7 @@ from magnumclient.common import cliutils as utils from magnumclient.common import utils as magnum_utils from magnumclient.i18n import _ +from magnumclient.v1 import basemodels DEPRECATION_MESSAGE = ( @@ -211,6 +212,10 @@ def do_baymodel_show(cs, args): 'apiserver_port, server_type, tls_disabled, registry_enabled' ) ) +@utils.arg('--detail', + action='store_true', default=False, + help=_('Show detailed information about the baymodels.') + ) @utils.deprecated(DEPRECATION_MESSAGE) def do_baymodel_list(cs, args): """Print a list of baymodels. @@ -219,8 +224,12 @@ def do_baymodel_list(cs, args): """ nodes = cs.baymodels.list(limit=args.limit, sort_key=args.sort_key, - sort_dir=args.sort_dir) - columns = ['uuid', 'name'] + sort_dir=args.sort_dir, + detail=args.detail) + if args.detail: + columns = basemodels.OUTPUT_ATTRIBUTES + else: + columns = ['uuid', 'name'] columns += utils._get_list_table_columns_and_formatters( args.fields, nodes, exclude_fields=(c.lower() for c in columns))[0] diff --git a/magnumclient/v1/cluster_templates_shell.py b/magnumclient/v1/cluster_templates_shell.py index 6793ed14..78211a91 100644 --- a/magnumclient/v1/cluster_templates_shell.py +++ b/magnumclient/v1/cluster_templates_shell.py @@ -15,6 +15,7 @@ from magnumclient.common import cliutils as utils from magnumclient.common import utils as magnum_utils from magnumclient.i18n import _ +from magnumclient.v1 import basemodels # Maps old parameter names to their new names and whether they are required @@ -255,12 +256,20 @@ def do_cluster_template_show(cs, args): 'apiserver_port, server_type, tls_disabled, registry_enabled' ) ) +@utils.arg('--detail', + action='store_true', default=False, + help=_('Show detailed information about the cluster templates.') + ) def do_cluster_template_list(cs, args): """Print a list of cluster templates.""" nodes = cs.cluster_templates.list(limit=args.limit, sort_key=args.sort_key, - sort_dir=args.sort_dir) - columns = ['uuid', 'name'] + sort_dir=args.sort_dir, + detail=args.detail) + if args.detail: + columns = basemodels.OUTPUT_ATTRIBUTES + else: + columns = ['uuid', 'name'] columns += utils._get_list_table_columns_and_formatters( args.fields, nodes, exclude_fields=(c.lower() for c in columns))[0]