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:
parent
1bdca4761b
commit
fafdb0baf6
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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="<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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user