aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-09-11 02:41:50 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-09-11 02:41:50 +0000
commit39f20c597a8a602016f5200a2e60a2ef412d8b87 (patch)
treee6057906b81f0695af5d57310e9d90340fef8730 /api
parent3d462aaa3d87a2298cf1f9a859e996d708f917fd (diff)
parent3b4e7240a5e973e52807841dc96d5886d0ff880b (diff)
Merge "Add API(v1) to get real time log"
Diffstat (limited to 'api')
-rw-r--r--api/resources/v1/tasks.py50
-rw-r--r--api/urls.py1
2 files changed, 51 insertions, 0 deletions
diff --git a/api/resources/v1/tasks.py b/api/resources/v1/tasks.py
new file mode 100644
index 000000000..52455fbf5
--- /dev/null
+++ b/api/resources/v1/tasks.py
@@ -0,0 +1,50 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import os
+import errno
+import uuid
+
+from api import ApiResource
+from api.database.v1.handlers import TasksHandler
+from yardstick.common import constants as consts
+from yardstick.common.utils import result_handler
+
+
+class V1TaskLog(ApiResource):
+ def get(self, task_id):
+
+ try:
+ uuid.UUID(task_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid task_id')
+
+ task_handler = TasksHandler()
+ try:
+ task = task_handler.get_task_by_taskid(task_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid 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)
diff --git a/api/urls.py b/api/urls.py
index 9b0040b6c..4b8e39e8f 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -20,6 +20,7 @@ urlpatterns = [
Url('/yardstick/testsuites/action', 'v1_test_suite'),
Url('/yardstick/results', 'v1_result'),
Url('/yardstick/env/action', 'v1_env'),
+ Url('/yardstick/tasks/<task_id>/log', 'v1_task_log'),
# api v2
Url('/api/v2/yardstick/environments', 'v2_environments'),