Trim down the output of plan-show to be more useful
The output of plan-show was far too verbose to be of any use. This trims it down to be bare essentials, and adds a --verbose flag to plan-show that exhibits the original behaviour. Change-Id: I057e5311cafec495c25ccdc6e9689cf400385b66
This commit is contained in:
parent
2bbdbb8076
commit
0863d47b7f
@ -31,7 +31,7 @@ Field 'roles' contains list of names of Roles assigned to the Plan.
|
||||
|
||||
Retrieve a Single Plan
|
||||
----------------------
|
||||
*tuskar plan-show [-h] <PLAN>*
|
||||
*tuskar plan-show [-h] [--verbose] <PLAN>*
|
||||
|
||||
Usage example:
|
||||
|
||||
@ -39,7 +39,7 @@ Usage example:
|
||||
|
||||
tuskar plan-show c367b394-7179-4c44-85ed-bf84baaf9fee
|
||||
|
||||
This command will show table with properties of the Plan and their values.
|
||||
This command will show an overview of the Plan.
|
||||
|
||||
Example:
|
||||
|
||||
@ -65,6 +65,8 @@ Example:
|
||||
| uuid | c367b394-7179-4c44-85ed-bf84baaf9fee |
|
||||
+-------------+------------------------------------------------------------------------------------------+
|
||||
|
||||
Adding the --verbose flag will display all parameters, instead of just role counts.
|
||||
|
||||
Note: Parameters are displayed similarly as Roles, ie. set of properties with values. Each Parameter/Role separated by empty line from previous.
|
||||
|
||||
Create a New Plan
|
||||
|
@ -28,10 +28,14 @@ def mock_plan():
|
||||
plan = mock.Mock()
|
||||
plan.uuid = '5'
|
||||
plan.name = 'My Plan'
|
||||
plan.to_dict.return_value = {'uuid': 5, 'name': 'My Plan'}
|
||||
plan.parameters = []
|
||||
plan.parameters.append({'name': 'compute-1::count', 'value': '2'})
|
||||
plan.parameters.append({'name': 'compute-1::Flavor', 'value': 'baremetal'})
|
||||
plan.to_dict.return_value = {
|
||||
'uuid': 5,
|
||||
'name': 'My Plan',
|
||||
'parameters': plan.parameters,
|
||||
}
|
||||
return plan
|
||||
|
||||
|
||||
@ -58,16 +62,17 @@ class PlansShellTest(BasePlansShellTest):
|
||||
)
|
||||
|
||||
@mock.patch('tuskarclient.common.utils.find_resource')
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_detail')
|
||||
def test_plan_show(self, mock_print_detail, mock_find_resource):
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_summary')
|
||||
def test_plan_show(self, mock_print_summary, mock_find_resource):
|
||||
mock_find_resource.return_value = mock_plan()
|
||||
args = empty_args()
|
||||
args.plan = '5'
|
||||
args.verbose = False
|
||||
|
||||
self.shell.do_plan_show(self.tuskar, args, outfile=self.outfile)
|
||||
mock_find_resource.assert_called_with(self.tuskar.plans, '5')
|
||||
mock_print_detail.assert_called_with(mock_find_resource.return_value,
|
||||
outfile=self.outfile)
|
||||
mock_print_summary.assert_called_with(mock_find_resource.return_value,
|
||||
outfile=self.outfile)
|
||||
|
||||
@mock.patch('tuskarclient.common.utils.find_resource')
|
||||
@mock.patch('tuskarclient.common.formatting.print_dict')
|
||||
@ -105,8 +110,8 @@ class PlansShellTest(BasePlansShellTest):
|
||||
self.assertEqual('Deleted Plan "My Plan".\n',
|
||||
self.outfile.getvalue())
|
||||
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_detail')
|
||||
def test_plan_create(self, mock_print_detail):
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_summary')
|
||||
def test_plan_create(self, mock_print_summary):
|
||||
args = empty_args()
|
||||
args.name = 'my_plan'
|
||||
args.description = 'my plan description'
|
||||
@ -116,11 +121,11 @@ class PlansShellTest(BasePlansShellTest):
|
||||
name='my_plan',
|
||||
description='my plan description'
|
||||
)
|
||||
mock_print_detail.assert_called_with(
|
||||
mock_print_summary.assert_called_with(
|
||||
self.tuskar.plans.create.return_value, outfile=self.outfile)
|
||||
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_detail')
|
||||
def test_add_role(self, mock_print_detail):
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_summary')
|
||||
def test_add_role(self, mock_print_summary):
|
||||
args = empty_args()
|
||||
args.plan_uuid = '42'
|
||||
args.role_uuid = 'role_uuid'
|
||||
@ -128,11 +133,11 @@ class PlansShellTest(BasePlansShellTest):
|
||||
self.shell.do_plan_add_role(self.tuskar, args, outfile=self.outfile)
|
||||
self.tuskar.plans.add_role.assert_called_with('42', 'role_uuid')
|
||||
|
||||
mock_print_detail.assert_called_with(
|
||||
mock_print_summary.assert_called_with(
|
||||
self.tuskar.plans.add_role.return_value, outfile=self.outfile)
|
||||
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_detail')
|
||||
def test_remove_role(self, mock_print_detail):
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_summary')
|
||||
def test_remove_role(self, mock_print_summary):
|
||||
args = empty_args()
|
||||
args.plan_uuid = '42'
|
||||
args.role_uuid = 'role_uuid'
|
||||
@ -140,7 +145,7 @@ class PlansShellTest(BasePlansShellTest):
|
||||
self.shell.do_plan_remove_role(self.tuskar, args, outfile=self.outfile)
|
||||
self.tuskar.plans.remove_role.assert_called_with('42', 'role_uuid')
|
||||
|
||||
mock_print_detail.assert_called_with(
|
||||
mock_print_summary.assert_called_with(
|
||||
self.tuskar.plans.remove_role.return_value, outfile=self.outfile)
|
||||
|
||||
@mock.patch('tuskarclient.common.utils.find_resource')
|
||||
@ -189,8 +194,8 @@ class PlansShellTest(BasePlansShellTest):
|
||||
sorted(self.tuskar.plans.patch.call_args[0][1],
|
||||
key=lambda k: k['name']))
|
||||
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_detail')
|
||||
def test_plan_patch(self, mock_print_detail):
|
||||
@mock.patch('tuskarclient.v2.plans_shell.print_plan_summary')
|
||||
def test_plan_patch(self, mock_print_summary):
|
||||
args = empty_args()
|
||||
args.plan_uuid = 'plan_uuid'
|
||||
args.attributes = ['foo_name=foo_value',
|
||||
@ -223,11 +228,22 @@ class PlansShellTest(BasePlansShellTest):
|
||||
sorted(self.tuskar.plans.patch.call_args[0][1],
|
||||
key=lambda k: k['name']))
|
||||
|
||||
@mock.patch('tuskarclient.common.utils.find_resource')
|
||||
def test_print_plan_summary(self, mock_find_resource):
|
||||
mock_find_resource.return_value = mock_plan()
|
||||
args = empty_args()
|
||||
args.plan = '5'
|
||||
args.verbose = False
|
||||
|
||||
self.shell.do_plan_show(self.tuskar, args, outfile=self.outfile)
|
||||
mock_find_resource.assert_called_with(self.tuskar.plans, '5')
|
||||
|
||||
@mock.patch('tuskarclient.common.utils.find_resource')
|
||||
def test_print_plan_detail(self, mock_find_resource):
|
||||
mock_find_resource.return_value = mock_plan()
|
||||
args = empty_args()
|
||||
args.plan = '5'
|
||||
args.verbose = True
|
||||
|
||||
self.shell.do_plan_show(self.tuskar, args, outfile=self.outfile)
|
||||
mock_find_resource.assert_called_with(self.tuskar.plans, '5')
|
||||
|
@ -33,10 +33,29 @@ def do_plan_list(tuskar, args, outfile=sys.stdout):
|
||||
|
||||
@utils.arg('plan', metavar="<PLAN>",
|
||||
help="UUID of the Plan to show.")
|
||||
@utils.arg('--verbose', default=False, action="store_true",
|
||||
help="Display full plan details")
|
||||
def do_plan_show(tuskar, args, outfile=sys.stdout):
|
||||
"""Show an individual Plan by its UUID."""
|
||||
plan = utils.find_resource(tuskar.plans, args.plan)
|
||||
print_plan_detail(plan, outfile=outfile)
|
||||
if args.verbose:
|
||||
print_plan_detail(plan, outfile=outfile)
|
||||
else:
|
||||
print_plan_summary(plan, outfile=outfile)
|
||||
|
||||
|
||||
def print_plan_summary(plan, outfile=sys.stdout):
|
||||
"""Print a summary of Plan information (for plan-show etc.)."""
|
||||
|
||||
formatters = {
|
||||
'roles': fmt.parameters_v2_formatter,
|
||||
'parameters': fmt.parameters_v2_formatter,
|
||||
}
|
||||
plan_dict = plan.to_dict()
|
||||
plan_dict['parameters'] = [param for param in
|
||||
plan_dict['parameters']
|
||||
if param['name'].endswith('::count')]
|
||||
fmt.print_dict(plan_dict, formatters, outfile=outfile)
|
||||
|
||||
|
||||
@utils.arg('plan', metavar="<PLAN>",
|
||||
@ -68,7 +87,7 @@ def filter_parameters_to_dict(parameters, param_name):
|
||||
|
||||
|
||||
def print_plan_detail(plan, outfile=sys.stdout):
|
||||
"""Print detailed Plan information (for plan-show etc.)."""
|
||||
"""Print detailed Plan information (for plan-show --verbose etc.)."""
|
||||
|
||||
formatters = {
|
||||
'roles': fmt.parameters_v2_formatter,
|
||||
@ -96,7 +115,7 @@ def do_plan_create(tuskar, args, outfile=sys.stdout):
|
||||
name=vars(args).get('name'),
|
||||
description=vars(args).get('description')
|
||||
)
|
||||
print_plan_detail(plan, outfile=outfile)
|
||||
print_plan_summary(plan, outfile=outfile)
|
||||
|
||||
|
||||
@utils.arg('plan_uuid', help="UUID of the Plan to assign role to.")
|
||||
@ -108,7 +127,7 @@ def do_plan_add_role(tuskar, args, outfile=sys.stdout):
|
||||
vars(args).get('plan_uuid'),
|
||||
vars(args).get('role_uuid')
|
||||
)
|
||||
print_plan_detail(plan, outfile=outfile)
|
||||
print_plan_summary(plan, outfile=outfile)
|
||||
|
||||
|
||||
@utils.arg('plan_uuid', help="UUID of the Plan to remove role from.")
|
||||
@ -120,7 +139,7 @@ def do_plan_remove_role(tuskar, args, outfile=sys.stdout):
|
||||
vars(args).get('plan_uuid'),
|
||||
vars(args).get('role_uuid')
|
||||
)
|
||||
print_plan_detail(plan, outfile=outfile)
|
||||
print_plan_summary(plan, outfile=outfile)
|
||||
|
||||
|
||||
@utils.arg('role_name', help="Name of role which you want scale.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user