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 ##############################################################################
13 from api.utils import influx as influx_utils
14 from api.utils import common as common_utils
17 logger = logging.getLogger(__name__)
21 return getResult(args)
26 measurement = args['measurement']
27 task_id = args['task_id']
29 if re.search("[^a-zA-Z0-9_-]", measurement):
30 raise ValueError('invalid measurement parameter')
34 message = 'measurement and task_id must be provided'
35 return common_utils.error_handler(message)
37 query_template = "select * from %s where task_id='%s'"
38 query_sql = query_template % ('tasklist', task_id)
39 data = common_utils.translate_to_str(influx_utils.query(query_sql))
42 return common_utils.result_handler(0, [])
45 query_sql = query_template % (conf.TEST_CASE_PRE + measurement,
47 data = common_utils.translate_to_str(influx_utils.query(query_sql))
49 query_sql = query_template % (measurement, task_id)
50 data = common_utils.translate_to_str(influx_utils.query(query_sql))
52 return common_utils.result_handler(1, data)
55 return common_utils.result_handler(2, data[0]['error'])
58 status = data[0]['status']
65 return switcher.get(status, lambda: 'nothing')()
67 return common_utils.error_handler('no such task')