summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/resources/v1/env.py2
-rw-r--r--api/resources/v1/tasks.py50
-rw-r--r--api/resources/v2/testcases.py8
-rw-r--r--api/urls.py1
4 files changed, 59 insertions, 2 deletions
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py
index 47ea91643..04cc659c7 100644
--- a/api/resources/v1/env.py
+++ b/api/resources/v1/env.py
@@ -123,7 +123,7 @@ class V1Env(ApiResource):
"isDefault": True,
}
try:
- HttpClient().post(url, data)
+ HttpClient().post(url, data, timeout=10)
except Exception:
LOG.exception('Create datasources failed')
raise
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/resources/v2/testcases.py b/api/resources/v2/testcases.py
index 316ef2664..0edbf6285 100644
--- a/api/resources/v2/testcases.py
+++ b/api/resources/v2/testcases.py
@@ -60,7 +60,13 @@ class V2Testcase(ApiResource):
options = {k: {'description': '', 'type': v.__class__.__name__}
for k, v in jinja2schema.infer(data).items()}
-
+ # [('segmentation_id', < scalar >), ('image', < string >), ('provider', < scalar >),
+ # ('physical_network', < string >), ('packetsize', < number >)]
+ for k, v in options.items():
+ if k == 'segmentation_id':
+ options[k]['type'] = 'Number'
+ if k == 'provider':
+ options[k]['type'] = 'String'
return result_handler(consts.API_SUCCESS, {'testcase': data, 'args': options})
def delete(self, case_name):
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'),