1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
13 from api.utils import influx as influx_utils
14 from api.utils import common as common_utils
15 from api.database.handlers import TasksHandler
17 logger = logging.getLogger(__name__)
21 return getResult(args)
26 task_id = args['task_id']
30 message = 'task_id must be provided'
31 return common_utils.result_handler(2, message)
33 task = TasksHandler().get_task_by_taskid(task_id)
36 return common_utils.result_handler(0, {})
39 testcases = task.details.split(',')
41 def get_data(testcase):
42 query_template = "select * from %s where task_id='%s'"
43 query_sql = query_template % (testcase, task_id)
44 data = common_utils.translate_to_str(influx_utils.query(query_sql))
47 result = _format_data({k: get_data(k) for k in testcases})
49 return common_utils.result_handler(1, result)
52 return common_utils.result_handler(2, task.error)
62 return switcher.get(status, lambda: 'nothing')()
64 return common_utils.result_handler(2, 'no such task')
67 def _format_data(data):
69 first_value = data.values()[0][0]
71 return {'criteria': 'FAIL', 'testcases': {}}
74 'deploy_scenario': first_value.get('deploy_scenario'),
75 'installer': first_value.get('installer'),
76 'pod_name': first_value.get('pod_name'),
77 'version': first_value.get('version')
79 task_id = first_value.get('task_id')
80 criteria = first_value.get('criteria')
81 testcases = {k: _get_case_data(v) for k, v in data.items()}
87 'testcases': testcases
92 def _get_case_data(data):
96 return {'tc_data': [], 'criteria': 'FAIL'}
98 tc_data = [_get_scenario_data(s) for s in data]
99 criteria = scenario.get('criteria')
100 return {'tc_data': tc_data, 'criteria': criteria}
103 def _get_scenario_data(data):
109 blacklist = {'criteria', 'deploy_scenario', 'host', 'installer',
110 'pod_name', 'runner_id', 'scenarios', 'target',
111 'task_id', 'time', 'version'}
113 keys = set(data.keys()) - set(blacklist)
115 result['data'][k] = data[k]
117 result['timestamp'] = data.get('time')