X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=api%2Fresources%2Fv2%2Ftasks.py;h=25a9cf109e5376e05541c8c82bd75a875d457ca5;hb=36375f388880519336328406de1d1bbc408d4599;hp=b64f5ef247b6ffc9b96e3f1bc9bb28fc75e552f3;hpb=f6a24134a515f419090bfd73663a9b1620964123;p=yardstick.git diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py index b64f5ef24..25a9cf109 100644 --- a/api/resources/v2/tasks.py +++ b/api/resources/v2/tasks.py @@ -8,6 +8,8 @@ ############################################################################## import uuid import logging +import os +import errno from datetime import datetime from oslo_serialization import jsonutils @@ -114,7 +116,8 @@ class V2Task(ApiResource): if project.tasks: LOG.info('update tasks in project') - new_task_list = project.tasks.split(',').remove(task_id) + new_task_list = project.tasks.split(',') + new_task_list.remove(task_id) if new_task_list: new_tasks = ','.join(new_task_list) else: @@ -251,3 +254,37 @@ class V2Task(ApiResource): task_thread.start() return result_handler(consts.API_SUCCESS, {'uuid': task_id}) + + +class V2TaskLog(ApiResource): + + def get(self, task_id): + try: + uuid.UUID(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid task id') + + task_handler = V2TaskHandler() + try: + task = task_handler.get_by_uuid(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such task id') + + index = int(self._get_args().get('index', 0)) + + try: + with open(os.path.join(consts.TASK_LOG_DIR, '{}.log'.format(task_id))) as f: + f.seek(index) + data = f.readlines() + index = f.tell() + except OSError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'log file does not exist') + return result_handler(consts.API_ERROR, 'error with log file') + + return_data = { + 'index': index, + 'data': data + } + + return result_handler(task.status, return_data)