Deployment history --include-summary

Depends-on: I9683e733901cc22d6ef69b09d51a00726c803c40
Change-Id: I8b9496a7ebb898ea8ef73ff3696a8057d747826d
This commit is contained in:
Anastasiia Guzikova 2016-08-29 17:31:14 +03:00
parent bff20a7123
commit 294208500e
8 changed files with 111 additions and 10 deletions

View File

@ -44,7 +44,10 @@ class DeploymentTasksAction(Action):
), ),
Args.get_show_parameters_arg( Args.get_show_parameters_arg(
"Show deployment tasks parameters" "Show deployment tasks parameters"
) ),
Args.get_include_summary_arg(
"Show deployment tasks summary"
),
] ]
self.flag_func_map = ( self.flag_func_map = (
(None, self.list), (None, self.list),
@ -79,19 +82,23 @@ class DeploymentTasksAction(Action):
statuses = params.status.split(',') if params.status else [] statuses = params.status.split(',') if params.status else []
nodes = params.node.split(',') if params.node else [] nodes = params.node.split(',') if params.node else []
tasks_names = tasks_names.split(',') if tasks_names else [] tasks_names = tasks_names.split(',') if tasks_names else []
include_summary = getattr(params, 'include-summary')
data = client.get_all( data = client.get_all(
transaction_id=params.task, transaction_id=params.task,
nodes=nodes, nodes=nodes,
statuses=statuses, statuses=statuses,
tasks_names=tasks_names, tasks_names=tasks_names,
show_parameters=show_parameters show_parameters=show_parameters,
include_summary=include_summary
) )
if show_parameters: if show_parameters:
table_keys = client.tasks_records_keys table_keys = client.tasks_records_keys
else: else:
table_keys = client.history_records_keys table_keys = client.history_records_keys
if include_summary:
table_keys += ('summary',)
self.serializer.print_to_output( self.serializer.print_to_output(
data, data,
format_table( format_table(

View File

@ -767,3 +767,11 @@ def get_show_parameters_arg(help_msg):
"help": help_msg "help": help_msg
} }
return get_boolean_arg("show-parameters", **default_kwargs) return get_boolean_arg("show-parameters", **default_kwargs)
def get_include_summary_arg(help_msg):
default_kwargs = {
"flags": ("--include-summary",),
"help": help_msg
}
return get_boolean_arg("include-summary", **default_kwargs)

View File

@ -205,22 +205,31 @@ class TaskHistoryShow(TaskMixIn, base.BaseListCommand):
action='store_true', action='store_true',
default=False, default=False,
help='Show deployment tasks parameters') help='Show deployment tasks parameters')
parser.add_argument(
'--include-summary',
action='store_true',
default=False,
help='Show deployment tasks summary')
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
# print parser # print parser
show_parameters = parsed_args.show_parameters show_parameters = parsed_args.show_parameters
include_summary = parsed_args.include_summary
data = self.client.get_all( data = self.client.get_all(
transaction_id=parsed_args.id, transaction_id=parsed_args.id,
nodes=parsed_args.nodes, nodes=parsed_args.nodes,
statuses=parsed_args.statuses, statuses=parsed_args.statuses,
tasks_names=parsed_args.tasks_names, tasks_names=parsed_args.tasks_names,
include_summary=include_summary,
show_parameters=show_parameters show_parameters=show_parameters
) )
if show_parameters: if show_parameters:
self.columns = self.client.tasks_records_keys self.columns = self.client.tasks_records_keys
else: else:
self.columns = self.client.history_records_keys self.columns = self.client.history_records_keys
if include_summary:
self.columns += ('summary',)
data = data_utils.get_display_data_multi(self.columns, data) data = data_utils.get_display_data_multi(self.columns, data)
return self.columns, data return self.columns, data

View File

@ -43,6 +43,28 @@ class TestDeploymentTasksAction(base.UnitTestCase):
utils.get_fake_deployment_history(convert_legacy_fields=True), utils.get_fake_deployment_history(convert_legacy_fields=True),
acceptable_keys=DeploymentHistoryClient.history_records_keys)) acceptable_keys=DeploymentHistoryClient.history_records_keys))
@patch.object(Serializer, 'print_to_output')
def test_show_full_history_include_summary(self, print_mock):
self.m_history_api = self.m_request.get(
'/api/v1/transactions/1/deployment_history/?'
'nodes=&'
'statuses=&'
'include_summary=1&'
'tasks_names=',
json=utils.get_fake_deployment_history(include_summary=True))
self.execute(
['fuel', 'deployment-tasks', '--tid', '1', '--include-summary']
)
print_mock.assert_called_once_with(
utils.get_fake_deployment_history(convert_legacy_fields=True,
include_summary=True),
format_table(
utils.get_fake_deployment_history(convert_legacy_fields=True,
include_summary=True),
acceptable_keys=(DeploymentHistoryClient.history_records_keys +
('summary',))))
@patch.object(Serializer, 'print_to_output') @patch.object(Serializer, 'print_to_output')
def test_show_tasks_history_with_parameters(self, print_mock): def test_show_tasks_history_with_parameters(self, print_mock):
tasks_after_facade = [ tasks_after_facade = [

View File

@ -81,6 +81,25 @@ class TestTaskCommand(test_engine.BaseCLITest):
nodes=None, nodes=None,
statuses=None, statuses=None,
tasks_names=None, tasks_names=None,
include_summary=False,
show_parameters=False)
def test_task_history_show_include_summary(self):
task_id = 42
args = 'task history show {task_id} '.format(task_id=task_id)
args += '--include-summary '
self.m_client.get_all.return_value = \
utils.get_fake_deployment_history(include_summary=True)
self.exec_command(args)
self.m_get_client.assert_called_once_with('deployment_history',
mock.ANY)
self.m_client.get_all.assert_called_once_with(transaction_id=task_id,
nodes=None,
statuses=None,
tasks_names=None,
include_summary=True,
show_parameters=False) show_parameters=False)
def test_task_history_parameters(self): def test_task_history_parameters(self):
@ -99,6 +118,7 @@ class TestTaskCommand(test_engine.BaseCLITest):
self.m_client.get_all.assert_called_once_with( self.m_client.get_all.assert_called_once_with(
transaction_id=task_id, nodes=['1', '2'], transaction_id=task_id, nodes=['1', '2'],
statuses=['ready', 'error'], tasks_names=['task1', 'task2'], statuses=['ready', 'error'], tasks_names=['task1', 'task2'],
include_summary=False,
show_parameters=True) show_parameters=True)
def _test_cmd(self, cmd, method, cmd_line, client, def _test_cmd(self, cmd, method, cmd_line, client,
@ -208,6 +228,7 @@ class TestDeploymentTasksAction(test_engine.BaseCLITest):
statuses=['ready'], statuses=['ready'],
tasks_names=['taskname1', 'taskname2'], tasks_names=['taskname1', 'taskname2'],
transaction_id=1, transaction_id=1,
include_summary=False,
show_parameters=True) show_parameters=True)
m_formatter.assert_called_once_with(expected_fields, m_formatter.assert_called_once_with(expected_fields,

View File

@ -73,6 +73,32 @@ class TestDeploymentHistoryFacade(test_api.BaseLibTest):
utils.get_fake_deployment_history(convert_legacy_fields=True), utils.get_fake_deployment_history(convert_legacy_fields=True),
tasks_after_facade) tasks_after_facade)
def test_deployment_history_include_summary(self):
fake_history = utils.get_fake_deployment_history(include_summary=True)
matcher = self.m_request.get(
self.get_url(
nodes='1,2',
statuses='ready,error,pending',
tasks_names='controller-remaining-tasks,'
'ironic-compute,pending-task'
) + '&include_summary=1', json=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'],
include_summary=True,
show_parameters=False
)
self.assertTrue(matcher.called)
self.assertItemsEqual(
utils.get_fake_deployment_history(convert_legacy_fields=True,
include_summary=True),
tasks_after_facade)
def test_deployment_history_parameters(self): def test_deployment_history_parameters(self):
matcher = self.m_request.get( matcher = self.m_request.get(

View File

@ -17,7 +17,8 @@ import itertools
def get_fake_deployment_history( def get_fake_deployment_history(
add_task_data=False, convert_legacy_fields=False): add_task_data=False, convert_legacy_fields=False,
include_summary=False):
"""Create a fake deployment history. """Create a fake deployment history.
Returns the serialized and parametrized representation of a dumped Fuel Returns the serialized and parametrized representation of a dumped Fuel
@ -33,7 +34,7 @@ def get_fake_deployment_history(
:rtype: list[dict] :rtype: list[dict]
""" """
if add_task_data: if add_task_data:
return list(itertools.chain(*[[ result = list(itertools.chain(*[[
{ {
'status': 'ready', 'status': 'ready',
'time_start': '2016-03-25T17:22:10.687135', 'time_start': '2016-03-25T17:22:10.687135',
@ -48,7 +49,7 @@ def get_fake_deployment_history(
'/modular/globals/globals.pp', '/modular/globals/globals.pp',
'puppet_modules': '/etc/puppet/modules', 'puppet_modules': '/etc/puppet/modules',
'timeout': 3600 'timeout': 3600
} },
}, },
{ {
'status': 'skipped', 'status': 'skipped',
@ -89,7 +90,7 @@ def get_fake_deployment_history(
'time_start': '2016-03-25T17:22:10.687135', 'time_start': '2016-03-25T17:22:10.687135',
'time_end': '2016-03-25T17:22:30.830701', 'time_end': '2016-03-25T17:22:30.830701',
'node_id': node_id, 'node_id': node_id,
'deployment_graph_task_name': 'controller-remaining-tasks' 'deployment_graph_task_name': 'controller-remaining-tasks',
}, },
{ {
'status': 'skipped', 'status': 'skipped',
@ -110,7 +111,10 @@ def get_fake_deployment_history(
for record in result: for record in result:
record['task_name'] = record['deployment_graph_task_name'] record['task_name'] = record['deployment_graph_task_name']
record.pop('deployment_graph_task_name', None) record.pop('deployment_graph_task_name', None)
return result if include_summary:
for record in result:
record['summary'] = '{}'
return result
def get_fake_deployment_history_w_params(): def get_fake_deployment_history_w_params():

View File

@ -31,11 +31,13 @@ class DeploymentHistoryClient(base_v1.BaseV1Client):
_entity_wrapper = objects.Environment _entity_wrapper = objects.Environment
def get_all(self, transaction_id, nodes=None, statuses=None, def get_all(self, transaction_id, nodes=None, statuses=None,
tasks_names=None, show_parameters=False): tasks_names=None, show_parameters=False,
include_summary=False):
parameters = { parameters = {
'statuses': statuses, 'statuses': statuses,
'nodes': nodes, 'nodes': nodes,
'tasks_names': tasks_names 'tasks_names': tasks_names,
'include_summary': (str(int(include_summary)),),
} }
# remove unused parameters or parameters with empty list as value # remove unused parameters or parameters with empty list as value
parameters = {k: v for k, v in six.iteritems(parameters) parameters = {k: v for k, v in six.iteritems(parameters)
@ -70,10 +72,12 @@ class DeploymentHistoryClient(base_v1.BaseV1Client):
continue continue
history_record = {} history_record = {}
for key in record: for key in record:
if key in self.history_records_keys: if key in self.history_records_keys or key == 'summary':
history_record[key] = record[key] history_record[key] = record[key]
else: else:
tasks_parameters[task_name][key] = record[key] tasks_parameters[task_name][key] = record[key]
if include_summary:
history_record['summary'] = history_record.get('summary', None)
history_records.append(history_record) history_records.append(history_record)
history_records_by_task[task_name].append(history_record) history_records_by_task[task_name].append(history_record)