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 import ApiResource
14 from api.database.v1.handlers import TasksHandler
15 from yardstick.common import constants as consts
16 from yardstick.common.utils import result_handler
19 class V1TaskLog(ApiResource):
20 def get(self, task_id):
25 return result_handler(consts.API_ERROR, 'invalid task_id')
27 task_handler = TasksHandler()
29 task = task_handler.get_task_by_taskid(task_id)
31 return result_handler(consts.API_ERROR, 'invalid task_id')
33 index = int(self._get_args().get('index', 0))
36 with open(os.path.join(consts.TASK_LOG_DIR, '{}.log'.format(task_id))) as f:
41 if e.errno == errno.ENOENT:
42 return result_handler(consts.API_ERROR, 'log file does not exist')
43 return result_handler(consts.API_ERROR, 'error with log file')
50 return result_handler(task.status, return_data)