Adds plan-show command to CLI

Adds parameter_v2_formatter.
Adds print_plan_detail helper method.
Adds plan-show command.
Change-Id: I07b2158acf9927b42eb65d35b8f106a153a8bd62
This commit is contained in:
Petr Blaho 2014-08-29 15:56:45 +02:00
parent 1bdca4761b
commit fafdb0baf6
3 changed files with 45 additions and 0 deletions

View File

@ -121,6 +121,12 @@ def attributes_formatter(attributes):
sorted(attributes.items())) 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): def counts_formatter(counts):
"""Given a list of dicts that represent Overcloud Roles output the """Given a list of dicts that represent Overcloud Roles output the
Overcloud Role ID with the num_noces Overcloud Role ID with the num_noces

View File

@ -25,6 +25,13 @@ def empty_args():
return args return args
def mock_plan():
plan = mock.Mock()
plan.uuid = '5'
plan.name = 'My Plan'
return plan
class BasePlansShellTest(tutils.TestCase): class BasePlansShellTest(tutils.TestCase):
def setUp(self): def setUp(self):
@ -46,3 +53,15 @@ class PlansShellTest(BasePlansShellTest):
self.tuskar.plans.list.return_value, mock.ANY, mock.ANY, self.tuskar.plans.list.return_value, mock.ANY, mock.ANY,
outfile=self.outfile 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)

View File

@ -13,6 +13,7 @@
import sys import sys
import tuskarclient.common.formatting as fmt import tuskarclient.common.formatting as fmt
from tuskarclient.common import utils
def do_plan_list(tuskar, args, outfile=sys.stdout): 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) fmt.print_list(plans, fields, formatters, outfile=outfile)
@utils.arg('plan', metavar="<PLAN>",
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)