From fafdb0baf6c3f0b89f1afde759639c80af1cd612 Mon Sep 17 00:00:00 2001 From: Petr Blaho Date: Fri, 29 Aug 2014 15:56:45 +0200 Subject: [PATCH] Adds plan-show command to CLI Adds parameter_v2_formatter. Adds print_plan_detail helper method. Adds plan-show command. Change-Id: I07b2158acf9927b42eb65d35b8f106a153a8bd62 --- tuskarclient/common/formatting.py | 6 ++++++ tuskarclient/tests/v2/test_plans_shell.py | 19 +++++++++++++++++++ tuskarclient/v2/plans_shell.py | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/tuskarclient/common/formatting.py b/tuskarclient/common/formatting.py index 957cdd9..701353f 100644 --- a/tuskarclient/common/formatting.py +++ b/tuskarclient/common/formatting.py @@ -121,6 +121,12 @@ def attributes_formatter(attributes): sorted(attributes.items())) +def parameters_v2_formatter(parameters): + """Given a list of dicts format parameters output.""" + return u"\n".join(attributes_formatter(parameter) + for parameter in parameters) + + def counts_formatter(counts): """Given a list of dicts that represent Overcloud Roles output the Overcloud Role ID with the num_noces diff --git a/tuskarclient/tests/v2/test_plans_shell.py b/tuskarclient/tests/v2/test_plans_shell.py index 95bca67..664daaf 100644 --- a/tuskarclient/tests/v2/test_plans_shell.py +++ b/tuskarclient/tests/v2/test_plans_shell.py @@ -25,6 +25,13 @@ def empty_args(): return args +def mock_plan(): + plan = mock.Mock() + plan.uuid = '5' + plan.name = 'My Plan' + return plan + + class BasePlansShellTest(tutils.TestCase): def setUp(self): @@ -46,3 +53,15 @@ class PlansShellTest(BasePlansShellTest): self.tuskar.plans.list.return_value, mock.ANY, mock.ANY, outfile=self.outfile ) + + @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_find_resource.return_value = mock_plan() + args = empty_args() + args.plan = '5' + + 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) diff --git a/tuskarclient/v2/plans_shell.py b/tuskarclient/v2/plans_shell.py index d3035cc..a802705 100644 --- a/tuskarclient/v2/plans_shell.py +++ b/tuskarclient/v2/plans_shell.py @@ -13,6 +13,7 @@ import sys import tuskarclient.common.formatting as fmt +from tuskarclient.common import utils def do_plan_list(tuskar, args, outfile=sys.stdout): @@ -25,3 +26,22 @@ def do_plan_list(tuskar, args, outfile=sys.stdout): } fmt.print_list(plans, fields, formatters, outfile=outfile) + + +@utils.arg('plan', metavar="", + help="UUID of the Plan to show.") +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) + + +def print_plan_detail(plan, outfile=sys.stdout): + """Print detailed Plan information (for plan-show etc.).""" + + formatters = { + 'roles': fmt.parameters_v2_formatter, + 'parameters': fmt.parameters_v2_formatter, + } + plan_dict = plan.to_dict() + fmt.print_dict(plan_dict, formatters, outfile=outfile)