aboutsummaryrefslogtreecommitdiffstats
path: root/functest_kubernetes
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-03-13 13:56:21 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-03-13 14:00:15 +0100
commit1d025732c321bfd3c9eebcba45363df17ef37d0c (patch)
tree4eb9967d5fa7772de17e0c95c4d7eab1950451b9 /functest_kubernetes
parent7e67c74f2649ee61a719061e8f35e5d9edc141ee (diff)
Refactor loggers
Only 1 logger is needed and it's updated to conform with logging.ini. Change-Id: I53465bbe9a81526ce1acaac90e47ffe4daaaa716 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest_kubernetes')
-rw-r--r--functest_kubernetes/k8stest.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/functest_kubernetes/k8stest.py b/functest_kubernetes/k8stest.py
index e5f19f95..65c8acfc 100644
--- a/functest_kubernetes/k8stest.py
+++ b/functest_kubernetes/k8stest.py
@@ -23,12 +23,11 @@ import time
from xtesting.core import testcase
-LOGGER = logging.getLogger(__name__)
-
-
class K8sTesting(testcase.TestCase):
"""Kubernetes test runner"""
+ __logger = logging.getLogger(__name__)
+
def __init__(self, **kwargs):
super(K8sTesting, self).__init__(**kwargs)
self.cmd = []
@@ -39,7 +38,7 @@ class K8sTesting(testcase.TestCase):
def run_kubetest(self): # pylint: disable=too-many-branches
"""Run the test suites"""
cmd_line = self.cmd
- LOGGER.info("Starting k8s test: '%s'.", cmd_line)
+ self.__logger.info("Starting k8s test: '%s'.", cmd_line)
process = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
@@ -47,18 +46,17 @@ class K8sTesting(testcase.TestCase):
# Remove color code escape sequences
output = re.sub(r'\x1B\[[0-?]*[ -/]*[@-~]', '', str(output))
- file_logger = logging.getLogger(self.case_name)
remarks = []
lines = output.split('\n')
i = 0
while i < len(lines):
if '[k8s.io]' in lines[i]:
if i != 0 and 'seconds' in lines[i-1]:
- file_logger.debug(lines[i-1])
+ self.__logger.debug(lines[i-1])
while lines[i] != '-'*len(lines[i]):
if lines[i].startswith('STEP:') or ('INFO:' in lines[i]):
break
- file_logger.debug(lines[i])
+ self.__logger.debug(lines[i])
i = i+1
success = 'SUCCESS!' in lines[i]
@@ -70,17 +68,17 @@ class K8sTesting(testcase.TestCase):
break
i = i+1
- file_logger.debug('-'*10)
- file_logger.debug("Remarks:")
+ self.__logger.debug('-'*10)
+ self.__logger.info("Remarks:")
for remark in remarks:
if 'seconds' in remark:
- file_logger.debug(remark)
+ self.__logger.debug(remark)
elif 'Passed' in remark:
- file_logger.debug("Passed: %s", remark.split()[0])
+ self.__logger.info("Passed: %s", remark.split()[0])
elif 'Skipped' in remark:
- file_logger.debug("Skipped: %s", remark.split()[0])
+ self.__logger.info("Skipped: %s", remark.split()[0])
elif 'Failed' in remark:
- file_logger.debug("Failed: %s", remark.split()[0])
+ self.__logger.info("Failed: %s", remark.split()[0])
if success:
self.result = 100
@@ -90,15 +88,16 @@ class K8sTesting(testcase.TestCase):
def run(self, **kwargs):
if not os.path.isfile(os.getenv('KUBECONFIG')):
- LOGGER.error("Cannot run k8s testcases. Config file not found ")
+ self.__logger.error(
+ "Cannot run k8s testcases. Config file not found ")
return self.EX_RUN_ERROR
self.start_time = time.time()
try:
self.run_kubetest()
res = self.EX_OK
- except Exception as ex: # pylint: disable=broad-except
- LOGGER.error("Error with running %s", str(ex))
+ except Exception: # pylint: disable=broad-except
+ self.__logger.exception("Error with running kubetest:")
res = self.EX_RUN_ERROR
self.stop_time = time.time()