aboutsummaryrefslogtreecommitdiffstats
path: root/functest/api/resources/v1/testcases.py
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-08-22 04:01:38 +0000
committerLinda Wang <wangwulin@huawei.com>2017-08-25 01:16:21 +0000
commitdc73f1b7cb3afffcace97e3ede9dd25639def6e2 (patch)
treee60584f50b24af707b0981deb8bd1b058b98b863 /functest/api/resources/v1/testcases.py
parentad44bfd97555a7372269db539857fd53fffb0460 (diff)
Create API to get log for each task
API: /api/v1/functest/tasks/<task_id>/log METHOD: GET JIRA: FUNCTEST-867 Change-Id: I987cbf662e4da349bf7583e48da5d981a2f1e0fd Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest/api/resources/v1/testcases.py')
-rw-r--r--functest/api/resources/v1/testcases.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/functest/api/resources/v1/testcases.py b/functest/api/resources/v1/testcases.py
index f146c24c..d708cf37 100644
--- a/functest/api/resources/v1/testcases.py
+++ b/functest/api/resources/v1/testcases.py
@@ -11,10 +11,12 @@
Resources to handle testcase related requests
"""
-import os
import logging
+import os
+import pkg_resources
import uuid
+import ConfigParser
from flask import abort, jsonify
from functest.api.base import ApiResource
@@ -84,6 +86,7 @@ class V1Testcase(ApiResource):
""" The built_in function to run a test case """
case_name = args.get('testcase')
+ self._update_logging_ini(args.get('task_id'))
if not os.path.isfile(CONST.__getattribute__('env_active')):
raise Exception("Functest environment is not ready.")
@@ -113,3 +116,17 @@ class V1Testcase(ApiResource):
}
return {'result': result}
+
+ def _update_logging_ini(self, task_id): # pylint: disable=no-self-use
+ """ Update the log file for each task"""
+ config = ConfigParser.RawConfigParser()
+ config.read(
+ pkg_resources.resource_filename('functest', 'ci/logging.ini'))
+ log_path = os.path.join(CONST.__getattribute__('dir_results'),
+ '{}.log'.format(task_id))
+ config.set('handler_file', 'args', '("{}",)'.format(log_path))
+
+ with open(
+ pkg_resources.resource_filename(
+ 'functest', 'ci/logging.ini'), 'wb') as configfile:
+ config.write(configfile)