Merge "solve failure testcases are not pushed to testDB problem"
[functest.git] / functest / core / TestCasesBase.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 import os
11
12 import functest.utils.functest_logger as ft_logger
13 import functest.utils.functest_utils as ft_utils
14
15
16 class TestCasesBase(object):
17
18     EX_OK = os.EX_OK
19     EX_RUN_ERROR = os.EX_SOFTWARE
20     EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
21     EX_SKIP = os.EX_SOFTWARE - 2
22
23     logger = ft_logger.Logger(__name__).getLogger()
24
25     def __init__(self):
26         self.functest_repo = ft_utils.FUNCTEST_REPO
27         self.details = {}
28         self.project_name = "functest"
29         self.case_name = ""
30         self.criteria = ""
31         self.start_time = ""
32         self.stop_time = ""
33
34     def run(self, **kwargs):
35         self.logger.error("Run must be implemented")
36         return TestCasesBase.EX_RUN_ERROR
37
38     def push_to_db(self):
39         try:
40             assert self.project_name
41             assert self.case_name
42             assert self.criteria
43             assert self.start_time
44             assert self.stop_time
45             if ft_utils.push_results_to_db(
46                     self.project_name, self.case_name, self.start_time,
47                     self.stop_time, self.criteria, self.details):
48                 self.logger.info("The results were successfully pushed to DB")
49                 return TestCasesBase.EX_OK
50             else:
51                 self.logger.error("The results cannot be pushed to DB")
52                 return TestCasesBase.EX_PUSH_TO_DB_ERROR
53         except Exception:
54             self.logger.exception("The results cannot be pushed to DB")
55             return TestCasesBase.EX_PUSH_TO_DB_ERROR