aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/__init__.py2
-rw-r--r--api/resources/v1/env.py4
-rw-r--r--api/resources/v2/pods.py3
-rw-r--r--api/resources/v2/tasks.py36
-rw-r--r--api/urls.py1
5 files changed, 41 insertions, 5 deletions
diff --git a/api/__init__.py b/api/__init__.py
index c5aefffe8..323502232 100644
--- a/api/__init__.py
+++ b/api/__init__.py
@@ -35,13 +35,11 @@ class ApiResource(Resource):
pass
args.update({k: v for k, v in request.form.items()})
- LOG.debug('Input args is: action: %s, args: %s', action, args)
return action, args
def _get_args(self):
args = common_utils.translate_to_str(request.args)
- LOG.debug('Input args is: args: %s', args)
return args
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py
index 8367fa9eb..98b8ec7e4 100644
--- a/api/resources/v1/env.py
+++ b/api/resources/v1/env.py
@@ -31,7 +31,7 @@ from yardstick.common import utils
from yardstick.common.utils import result_handler
from yardstick.common import openstack_utils
from yardstick.common.httpClient import HttpClient
-
+from yardstick.common.yaml_loader import yaml_load
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
@@ -393,7 +393,7 @@ class V1Env(ApiResource):
return result_handler(consts.API_ERROR, 'file must be provided')
LOG.info('Checking file')
- data = yaml.safe_load(pod_file.read())
+ data = yaml_load(pod_file.read())
if not isinstance(data, collections.Mapping):
return result_handler(consts.API_ERROR, 'invalid yaml file')
diff --git a/api/resources/v2/pods.py b/api/resources/v2/pods.py
index f2316d353..d98238ca1 100644
--- a/api/resources/v2/pods.py
+++ b/api/resources/v2/pods.py
@@ -18,6 +18,7 @@ from api.database.v2.handlers import V2EnvironmentHandler
from yardstick.common import constants as consts
from yardstick.common.utils import result_handler
from yardstick.common.task_template import TaskTemplate
+from yardstick.common.yaml_loader import yaml_load
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
@@ -48,7 +49,7 @@ class V2Pods(ApiResource):
upload_file.save(consts.POD_FILE)
with open(consts.POD_FILE) as f:
- data = yaml.safe_load(TaskTemplate.render(f.read()))
+ data = yaml_load(TaskTemplate.render(f.read()))
LOG.debug('pod content is: %s', data)
LOG.info('create pod in database')
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py
index 885a190c6..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
@@ -252,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)
diff --git a/api/urls.py b/api/urls.py
index 3fef91af8..83cf4daf9 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -48,6 +48,7 @@ urlpatterns = [
Url('/api/v2/yardstick/tasks', 'v2_tasks'),
Url('/api/v2/yardstick/tasks/action', 'v2_tasks'),
Url('/api/v2/yardstick/tasks/<task_id>', 'v2_task'),
+ Url('/api/v2/yardstick/tasks/<task_id>/log', 'v2_task_log'),
Url('/api/v2/yardstick/testcases', 'v2_testcases'),
Url('/api/v2/yardstick/testcases/action', 'v2_testcases'),