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
14 from api.utils.common import result_handler
15 from api.database.v1.handlers import TasksHandler
16 from yardstick.common import constants as consts
18 logger = logging.getLogger(__name__)
19 logger.setLevel(logging.DEBUG)
23 return getResult(args)
28 task_id = args['task_id']
30 return result_handler(consts.API_ERROR, 'task_id must be provided')
35 return result_handler(consts.API_ERROR, 'invalid task_id')
37 task_handler = TasksHandler()
39 task = task_handler.get_task_by_taskid(task_id)
41 return result_handler(consts.API_ERROR, 'invalid task_id')
44 return result_handler(consts.TASK_NOT_DONE, {})
48 return result_handler(consts.TASK_DONE, json.loads(task.result))
50 return result_handler(consts.TASK_DONE, {})
53 return result_handler(consts.TASK_FAILED, task.error)
56 logger.debug('Task status is: %s', status)
58 if status not in [consts.TASK_NOT_DONE,
61 return result_handler(consts.API_ERROR, 'internal server error')
64 consts.TASK_NOT_DONE: _unfinished,
65 consts.TASK_DONE: _finished,
66 consts.TASK_FAILED: _error
69 return switcher.get(status)()