aboutsummaryrefslogtreecommitdiffstats
path: root/functest/core/testcase_base.py
diff options
context:
space:
mode:
authorwu.zhihui <wu.zhihui1@zte.com.cn>2016-12-21 09:49:19 +0800
committerwu.zhihui <wu.zhihui1@zte.com.cn>2017-01-17 14:33:24 +0800
commitee21af78fbfc93e888acda121f08d2b216dd0159 (patch)
tree0c32d9a79fc6180c40bee95453577101d83e7dc3 /functest/core/testcase_base.py
parent9277dab7fc82030a5f3d7b55ea7b2a741a51a8a3 (diff)
write test results to a local file
Write test result to a file or push it to DB depends on the value format of test_db_url which is defined in config_functest.yaml. Meanwhile, test_db_url can be set by os envrion value "RESULT_STORE". If test_db_url is a url, e.g. http:// or https://, then push result to DB. If test_db_url is a file location, e.g. file:///, then write results to a file with json data. One result record, one line. JIRA: FUNCTEST-657 Change-Id: I579087cd2c24d61a79142b5d67003fb486b6c723 Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
Diffstat (limited to 'functest/core/testcase_base.py')
-rw-r--r--functest/core/testcase_base.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/functest/core/testcase_base.py b/functest/core/testcase_base.py
index 838b6398..ec46bc64 100644
--- a/functest/core/testcase_base.py
+++ b/functest/core/testcase_base.py
@@ -9,6 +9,7 @@
import os
+from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
@@ -17,7 +18,7 @@ class TestcaseBase(object):
EX_OK = os.EX_OK
EX_RUN_ERROR = os.EX_SOFTWARE
- EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
+ EX_PUBLISH_RESULT_FAILED = os.EX_SOFTWARE - 1
EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
logger = ft_logger.Logger(__name__).getLogger()
@@ -43,21 +44,45 @@ class TestcaseBase(object):
self.logger.error("Run must be implemented")
return TestcaseBase.EX_RUN_ERROR
- def push_to_db(self):
+ def publish_report(self):
+ if "RESULTS_STORE" in os.environ:
+ CONST.results_test_db_url = os.environ['RESULTS_STORE']
+
try:
assert self.project_name
assert self.case_name
assert self.criteria
assert self.start_time
assert self.stop_time
- if ft_utils.push_results_to_db(
- self.project_name, self.case_name, self.start_time,
- self.stop_time, self.criteria, self.details):
- self.logger.info("The results were successfully pushed to DB")
- return TestcaseBase.EX_OK
+ if CONST.results_test_db_url.lower().startswith(
+ ("http://", "https://")):
+ self.push_to_db()
+ elif CONST.results_test_db_url.lower().startswith("file://"):
+ self.write_to_file()
else:
- self.logger.error("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ self.logger.error("Please check parameter test_db_url and "
+ "OS environ variable RESTULTS_STORE")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
except Exception:
- self.logger.exception("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ self.logger.exception("The results cannot be stored")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+
+ def write_to_file(self):
+ if ft_utils.write_results_to_file(
+ self.project_name, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully written to a file")
+ return TestcaseBase.EX_OK
+ else:
+ self.logger.error("write results to a file failed")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+
+ def push_to_db(self):
+ if ft_utils.push_results_to_db(
+ self.project_name, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully pushed to DB")
+ return TestcaseBase.EX_OK
+ else:
+ self.logger.error("The results cannot be pushed to DB")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED