Merge "Add the support for 'detail' flag"

This commit is contained in:
Jenkins 2017-06-07 07:40:37 +00:00 committed by Gerrit Code Review
commit 7d5539f28e
5 changed files with 46 additions and 6 deletions

View File

@ -37,11 +37,12 @@ class FakeBayModel(BayModel):
class ShellTest(shell_test_base.TestCommandLineArgument): class ShellTest(shell_test_base.TestCommandLineArgument):
def _get_expected_args_list(self, limit=None, sort_dir=None, def _get_expected_args_list(self, limit=None, sort_dir=None,
sort_key=None): sort_key=None, detail=False):
expected_args = {} expected_args = {}
expected_args['limit'] = limit expected_args['limit'] = limit
expected_args['sort_dir'] = sort_dir expected_args['sort_dir'] = sort_dir
expected_args['sort_key'] = sort_key expected_args['sort_key'] = sort_key
expected_args['detail'] = detail
return expected_args return expected_args
@ -549,6 +550,13 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args = self._get_expected_args_list(1, 'asc', 'uuid') expected_args = self._get_expected_args_list(1, 'asc', 'uuid')
mock_list.assert_called_once_with(**expected_args) 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') @mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
def test_baymodel_list_ignored_duplicated_field(self, mock_list): def test_baymodel_list_ignored_duplicated_field(self, mock_list):
mock_list.return_value = [FakeBayModel()] mock_list.return_value = [FakeBayModel()]

View File

@ -37,11 +37,12 @@ class FakeClusterTemplate(ClusterTemplate):
class ShellTest(shell_test_base.TestCommandLineArgument): class ShellTest(shell_test_base.TestCommandLineArgument):
def _get_expected_args_list(self, limit=None, sort_dir=None, def _get_expected_args_list(self, limit=None, sort_dir=None,
sort_key=None): sort_key=None, detail=False):
expected_args = {} expected_args = {}
expected_args['limit'] = limit expected_args['limit'] = limit
expected_args['sort_dir'] = sort_dir expected_args['sort_dir'] = sort_dir
expected_args['sort_key'] = sort_key expected_args['sort_key'] = sort_key
expected_args['detail'] = detail
return expected_args return expected_args
@ -730,6 +731,14 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args = self._get_expected_args_list(1, 'asc', 'uuid') expected_args = self._get_expected_args_list(1, 'asc', 'uuid')
mock_list.assert_called_once_with(**expected_args) 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( @mock.patch(
'magnumclient.v1.cluster_templates.ClusterTemplateManager.list') 'magnumclient.v1.cluster_templates.ClusterTemplateManager.list')
def test_cluster_template_list_ignored_duplicated_field(self, mock_list): def test_cluster_template_list_ignored_duplicated_field(self, mock_list):

View File

@ -24,6 +24,11 @@ CREATION_ATTRIBUTES = ['name', 'image_id', 'flavor_id', 'master_flavor_id',
'docker_storage_driver', 'master_lb_enabled', 'docker_storage_driver', 'master_lb_enabled',
'floating_ip_enabled'] 'floating_ip_enabled']
OUTPUT_ATTRIBUTES = CREATION_ATTRIBUTES + ['apiserver_port', 'created_at',
'insecure_registry', 'links',
'updated_at', 'cluster_distro',
'uuid']
class BaseModel(base.Resource): class BaseModel(base.Resource):
# model_name needs to be overridden by any derived class. # model_name needs to be overridden by any derived class.

View File

@ -15,6 +15,7 @@
from magnumclient.common import cliutils as utils from magnumclient.common import cliutils as utils
from magnumclient.common import utils as magnum_utils from magnumclient.common import utils as magnum_utils
from magnumclient.i18n import _ from magnumclient.i18n import _
from magnumclient.v1 import basemodels
DEPRECATION_MESSAGE = ( DEPRECATION_MESSAGE = (
@ -211,6 +212,10 @@ def do_baymodel_show(cs, args):
'apiserver_port, server_type, tls_disabled, registry_enabled' '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) @utils.deprecated(DEPRECATION_MESSAGE)
def do_baymodel_list(cs, args): def do_baymodel_list(cs, args):
"""Print a list of baymodels. """Print a list of baymodels.
@ -219,8 +224,12 @@ def do_baymodel_list(cs, args):
""" """
nodes = cs.baymodels.list(limit=args.limit, nodes = cs.baymodels.list(limit=args.limit,
sort_key=args.sort_key, sort_key=args.sort_key,
sort_dir=args.sort_dir) sort_dir=args.sort_dir,
columns = ['uuid', 'name'] detail=args.detail)
if args.detail:
columns = basemodels.OUTPUT_ATTRIBUTES
else:
columns = ['uuid', 'name']
columns += utils._get_list_table_columns_and_formatters( columns += utils._get_list_table_columns_and_formatters(
args.fields, nodes, args.fields, nodes,
exclude_fields=(c.lower() for c in columns))[0] exclude_fields=(c.lower() for c in columns))[0]

View File

@ -15,6 +15,7 @@
from magnumclient.common import cliutils as utils from magnumclient.common import cliutils as utils
from magnumclient.common import utils as magnum_utils from magnumclient.common import utils as magnum_utils
from magnumclient.i18n import _ from magnumclient.i18n import _
from magnumclient.v1 import basemodels
# Maps old parameter names to their new names and whether they are required # Maps old parameter names to their new names and whether they are required
@ -259,12 +260,20 @@ def do_cluster_template_show(cs, args):
'apiserver_port, server_type, tls_disabled, registry_enabled' '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): def do_cluster_template_list(cs, args):
"""Print a list of cluster templates.""" """Print a list of cluster templates."""
nodes = cs.cluster_templates.list(limit=args.limit, nodes = cs.cluster_templates.list(limit=args.limit,
sort_key=args.sort_key, sort_key=args.sort_key,
sort_dir=args.sort_dir) sort_dir=args.sort_dir,
columns = ['uuid', 'name'] detail=args.detail)
if args.detail:
columns = basemodels.OUTPUT_ATTRIBUTES
else:
columns = ['uuid', 'name']
columns += utils._get_list_table_columns_and_formatters( columns += utils._get_list_table_columns_and_formatters(
args.fields, nodes, args.fields, nodes,
exclude_fields=(c.lower() for c in columns))[0] exclude_fields=(c.lower() for c in columns))[0]