summaryrefslogtreecommitdiffstats
path: root/functest/api/resources/v1/testcases.py
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2017-08-25 12:14:44 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-25 12:14:44 +0000
commit6726fb16f9719b21636454c9573f0cc716ea25f4 (patch)
treeffda41263cee63e6dee67356a733a9c0e55a6f41 /functest/api/resources/v1/testcases.py
parent6e1245a7d19d62810fbe5ee1aab248a85fa2bc15 (diff)
parentdc73f1b7cb3afffcace97e3ede9dd25639def6e2 (diff)
Merge "Create API to get log for each task"
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)