The patch adds option --show-parameters to both fuel and fuel2

Now commands like:
     fuel2 task history show <:deployment_task_id> --tasks-names <:deployment_task_name>
           --nodes <:node_id> --statuses <:task_status> --show-parameters
is possible

Flag --show-parameters for both fuel and fuel2 clients that is
telling CLI to show deployment tasks parameters.

Change-Id: I999ef997969940ba5150a63d9f4c163e9a974fdf
Closes-Bug: #1587862
(cherry picked from commit b8daca8431)
This commit is contained in:
Ilya Kutukov 2016-06-01 20:48:47 +03:00 committed by Vladimir Kuklin
parent 9bac34427a
commit 5aa87cfbc2
9 changed files with 197 additions and 26 deletions

View File

@ -41,6 +41,9 @@ class DeploymentTasksAction(Action):
Args.get_tasks_names_arg(
"Show deployment history for specific deployment tasks names "
"and group output by task"
),
Args.get_show_parameters_arg(
"Show deployment tasks parameters"
)
]
self.flag_func_map = (
@ -66,10 +69,13 @@ class DeploymentTasksAction(Action):
fuel deployment-tasks --task-id 5
--task-name task-name1,task-name2
To display tasks parameters use:
fuel deployment-tasks --task-id 5 --show-parameters
"""
client = DeploymentHistoryClient()
tasks_names = getattr(params, 'task-name', None)
group_by_tasks = bool(tasks_names)
show_parameters = getattr(params, 'show-parameters')
statuses = params.status.split(',') if params.status else []
nodes = params.node.split(',') if params.node else []
tasks_names = tasks_names.split(',') if tasks_names else []
@ -79,10 +85,10 @@ class DeploymentTasksAction(Action):
nodes=nodes,
statuses=statuses,
tasks_names=tasks_names,
group_by_tasks=group_by_tasks
show_parameters=show_parameters
)
if group_by_tasks:
if show_parameters:
table_keys = client.tasks_records_keys
else:
table_keys = client.history_records_keys

View File

@ -763,3 +763,11 @@ def get_tasks_names_arg(help_msg):
"help": help_msg
}
return get_arg("task-name", **default_kwargs)
def get_show_parameters_arg(help_msg):
default_kwargs = {
"flags": ("-p", "--show-parameters",),
"help": help_msg
}
return get_boolean_arg("show-parameters", **default_kwargs)

View File

@ -148,12 +148,7 @@ class TaskHistoryShow(TaskMixIn, base.BaseListCommand):
entity_name = 'deployment_history'
columns = (
'task_name',
'node_id',
'status',
'time_start',
'time_end')
columns = ()
def get_parser(self, prog_name):
parser = super(TaskHistoryShow, self).get_parser(prog_name)
@ -182,17 +177,29 @@ class TaskHistoryShow(TaskMixIn, base.BaseListCommand):
nargs='+',
help='Show deployment history for specific deployment tasks names')
parser.add_argument(
'-p',
'--show-parameters',
action='store_true',
default=False,
help='Show deployment tasks parameters')
return parser
def take_action(self, parsed_args):
# print parser
show_parameters = parsed_args.show_parameters
data = self.client.get_all(
transaction_id=parsed_args.id,
nodes=parsed_args.nodes,
statuses=parsed_args.statuses,
tasks_names=parsed_args.tasks_names)
tasks_names=parsed_args.tasks_names,
show_parameters=show_parameters
)
if show_parameters:
self.columns = self.client.tasks_records_keys
else:
self.columns = self.client.history_records_keys
data = data_utils.get_display_data_multi(self.columns, data)
return self.columns, data

View File

@ -44,7 +44,7 @@ class TestDeploymentTasksAction(base.UnitTestCase):
acceptable_keys=DeploymentHistoryClient.history_records_keys))
@patch.object(Serializer, 'print_to_output')
def test_show_tasks_history(self, print_mock):
def test_show_tasks_history_with_parameters(self, print_mock):
tasks_after_facade = [
{
'task_name': 'controller-remaining-tasks',
@ -83,7 +83,8 @@ class TestDeploymentTasksAction(base.UnitTestCase):
['fuel', 'deployment-tasks',
'--tid', '1',
'--task-name', 'controller-remaining-tasks,pending-task',
'--node', '1,2']
'--node', '1,2',
'--show-parameters']
)
print_mock.assert_called_once_with(
tasks_after_facade,

View File

@ -20,6 +20,7 @@ import yaml
from fuelclient.tests.unit.v2.cli import test_engine
from fuelclient.tests import utils
from fuelclient.v1.deployment_history import DeploymentHistoryClient
class TestTaskCommand(test_engine.BaseCLITest):
@ -61,12 +62,15 @@ class TestTaskCommand(test_engine.BaseCLITest):
self.m_client.get_all.assert_called_once_with(transaction_id=task_id,
nodes=None,
statuses=None,
tasks_names=None)
tasks_names=None,
show_parameters=False)
def test_task_history_parameters(self):
task_id = 42
args = 'task history show {task_id} --tasks-names task1 task2 ' \
'--statuses ready error --nodes 1 2'.format(task_id=task_id)
args = 'task history show {task_id} ' \
'--tasks-names task1 task2 ' \
'--statuses ready error --nodes 1 2 ' \
'--show-parameters'.format(task_id=task_id)
self.m_client.get_all.return_value = \
utils.get_fake_deployment_history()
@ -76,7 +80,8 @@ class TestTaskCommand(test_engine.BaseCLITest):
mock.ANY)
self.m_client.get_all.assert_called_once_with(
transaction_id=task_id, nodes=['1', '2'],
statuses=['ready', 'error'], tasks_names=['task1', 'task2'])
statuses=['ready', 'error'], tasks_names=['task1', 'task2'],
show_parameters=True)
def _test_cmd(self, cmd, method, cmd_line, client,
return_data, expected_file_path, expected_kwargs):
@ -121,3 +126,73 @@ class TestTaskCommand(test_engine.BaseCLITest):
"{0}/network_configuration_1.yaml".format(
self.current_path),
dict(transaction_id=1))
class TestDeploymentTasksAction(test_engine.BaseCLITest):
@mock.patch('cliff.formatters.table.TableFormatter.emit_list')
def test_show_tasks_history_with_parameters(self, m_formatter):
tasks_after_facade = utils.get_fake_deployment_history_w_params()
expected_fields = ('task_name', 'task_parameters', 'status_by_node')
expected_data = [
[
'controller-remaining-tasks',
'parameters: {puppet_manifest: /etc/puppet/modules/osnailyfact'
'er/modular/globals/globals.pp,\n puppet_modules: /etc/'
'puppet/modules, timeout: 3600}\nrole: [controller]\ntype: '
'puppet\nversion: 2.0.0\n',
'1 - ready - 2016-03-25T17:22:10 - 2016-03-25T17:22:30\n'
'2 - ready - 2016-03-25T17:22:10 - 2016-03-25T17:22:30'
],
[
'pending-task',
'parameters: {puppet_manifest: /etc/puppet/modules/osnailyfact'
'er/modular/globals/globals.pp,\n puppet_modules: /etc/puppet'
'/modules, timeout: 3600}\nrole: [controller]\ntype: '
'puppet\nversion: 2.0.0\n',
'1 - pending - not started - not ended\n'
'2 - pending - not started - not ended'
],
[
'ironic-compute',
'parameters: {puppet_manifest: /etc/puppet/modules/osnailyfact'
'er/modular/globals/globals.pp,\n puppet_modules: /etc/'
'puppet/modules, timeout: 3600}\nrole: [controller]\ntype: '
'puppet\nversion: 2.0.0\n',
'1 - skipped - 2016-03-25T17:23:37 - 2016-03-25T17:23:37\n'
'2 - skipped - 2016-03-25T17:23:37 - 2016-03-25T17:23:37'
]
]
self.m_client.get_all.return_value = tasks_after_facade
self.m_client.tasks_records_keys = \
DeploymentHistoryClient.tasks_records_keys
self.m_client.history_records_keys = \
DeploymentHistoryClient.history_records_keys
self.exec_command(
' '.join((
'task history show', '1',
'--nodes', '1 2',
'--statuses', 'ready',
'--tasks-names', 'taskname1 taskname2',
'--show-parameters'
))
)
self.m_client.get_all.assert_called_with(
nodes=['1', '2'],
statuses=['ready'],
tasks_names=['taskname1', 'taskname2'],
transaction_id=1,
show_parameters=True)
m_formatter.assert_called_once_with(expected_fields,
expected_data,
mock.ANY,
mock.ANY)

View File

@ -50,20 +50,52 @@ class TestDeploymentHistoryFacade(test_api.BaseLibTest):
self.assertTrue(matcher.called)
def test_deployment_history(self):
matcher = self.m_request.get(
self.get_url(
nodes='1,2',
statuses='ready,error,pending',
tasks_names='controller-remaining-tasks,'
'ironic-compute,pending-task'
), json=self.fake_history)
tasks_after_facade = self.client.get_all(
transaction_id=self.transaction_id,
nodes=['1', '2'],
statuses=['ready', 'error', 'pending'],
tasks_names=['controller-remaining-tasks',
'ironic-compute', 'pending-task'],
show_parameters=False
)
self.assertTrue(matcher.called)
self.assertItemsEqual(
utils.get_fake_deployment_history(convert_legacy_fields=True),
tasks_after_facade)
def test_deployment_history_parameters(self):
matcher = self.m_request.get(
self.get_url(
nodes='1,2',
statuses='ready,error',
tasks_names='custom_task1,custom_task12'
), json=self.fake_history)
statuses='ready,error,pending',
tasks_names='controller-remaining-tasks,'
'ironic-compute,pending-task'
),
json=utils.get_fake_deployment_history(add_task_data=True),
)
self.client.get_all(
tasks_after_facade = self.client.get_all(
transaction_id=self.transaction_id,
nodes=['1', '2'],
statuses=['ready', 'error'],
tasks_names=['custom_task1', 'custom_task12']
statuses=['ready', 'error', 'pending'],
tasks_names=['controller-remaining-tasks',
'ironic-compute', 'pending-task'],
show_parameters=True
)
self.assertTrue(matcher.called)
self.assertItemsEqual(
utils.get_fake_deployment_history_w_params(),
tasks_after_facade)

View File

@ -23,6 +23,8 @@ from fuelclient.tests.utils.fake_additional_info \
import get_fake_yaml_network_conf
from fuelclient.tests.utils.fake_deployment_history \
import get_fake_deployment_history
from fuelclient.tests.utils.fake_deployment_history \
import get_fake_deployment_history_w_params
from fuelclient.tests.utils.fake_net_conf import get_fake_interface_config
from fuelclient.tests.utils.fake_net_conf import get_fake_network_config
from fuelclient.tests.utils.fake_network_group import get_fake_network_group
@ -37,6 +39,7 @@ from fuelclient.tests.utils.fake_openstack_config \
__all__ = (get_fake_deployment_history,
get_fake_deployment_history_w_params,
get_fake_yaml_cluster_settings,
get_fake_yaml_deployment_info,
get_fake_yaml_network_conf,

View File

@ -111,3 +111,42 @@ def get_fake_deployment_history(
record['task_name'] = record['deployment_graph_task_name']
record.pop('deployment_graph_task_name', None)
return result
def get_fake_deployment_history_w_params():
return [
{
'task_name': 'controller-remaining-tasks',
'task_parameters': 'parameters: {puppet_manifest: /etc/puppet/'
'modules/osnailyfacter/modular/globals/'
'globals.pp,\n puppet_modules: /etc/'
'puppet/modules, timeout: 3600}\nrole: '
'[controller]\ntype: puppet\nversion: 2.0.0'
'\n',
'status_by_node': '1 - ready - 2016-03-25T17:22:10 - '
'2016-03-25T17:22:30\n'
'2 - ready - 2016-03-25T17:22:10 - '
'2016-03-25T17:22:30'
},
{
'task_name': 'pending-task',
'task_parameters': 'parameters: {puppet_manifest: /etc/puppet/'
'modules/osnailyfacter/modular/globals/'
'globals.pp,\n puppet_modules: /etc/puppet'
'/modules, timeout: 3600}\nrole: '
'[controller]\ntype: puppet\nversion: 2.0.0'
'\n',
'status_by_node': '1 - pending - not started - not ended\n'
'2 - pending - not started - not ended'
},
{
'task_name': 'ironic-compute',
'status_by_node': '1 - skipped - 2016-03-25T17:23:37 - '
'2016-03-25T17:23:37\n2 - skipped - '
'2016-03-25T17:23:37 - 2016-03-25T17:23:37',
'task_parameters': 'parameters: {puppet_manifest: /etc/puppet/'
'modules/osnailyfacter/modular/globals/'
'globals.pp,\n puppet_modules: /etc/'
'puppet/modules, timeout: 3600}\nrole: '
'[controller]\ntype: puppet\nversion: 2.0.0\n'},
]

View File

@ -34,7 +34,7 @@ class DeploymentHistoryClient(base_v1.BaseV1Client):
_entity_wrapper = objects.Environment
def get_all(self, transaction_id, nodes=None, statuses=None,
tasks_names=None, group_by_tasks=False):
tasks_names=None, show_parameters=False):
parameters = {
'statuses': statuses,
'nodes': nodes,
@ -78,7 +78,7 @@ class DeploymentHistoryClient(base_v1.BaseV1Client):
history_records.append(history_record)
history_records_by_task[task_name].append(history_record)
if group_by_tasks:
if show_parameters:
result = []
for task_name, value in sorted(six.iteritems(tasks_parameters)):
statuses_by_node = []