From 0249623ab94035ca0ea363d9a86847c2e7a5ee93 Mon Sep 17 00:00:00 2001 From: Panagiotis Karalis Date: Fri, 25 May 2018 12:27:12 +0300 Subject: Remove Feature logger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This class atttribute is removed as it's quite useless (it forces one module per project). All messages are now printed to xtesting.log whatever the namespace and all warnings are printed in console. Co-Authored-By: Cédric Ollivier Change-Id: I6860eaf427093ea21b3bd78650bec7939e947b2d Signed-off-by: Panagiotis Karalis Signed-off-by: Cédric Ollivier --- xtesting/ci/logging.ini | 22 +++---------------- xtesting/core/feature.py | 36 +++++++------------------------- xtesting/tests/unit/core/test_feature.py | 13 ------------ 3 files changed, 10 insertions(+), 61 deletions(-) diff --git a/xtesting/ci/logging.ini b/xtesting/ci/logging.ini index fc011ad6..5cb5e4bf 100644 --- a/xtesting/ci/logging.ini +++ b/xtesting/ci/logging.ini @@ -1,15 +1,15 @@ [loggers] -keys=root,xtesting,ci,core,energy,utils +keys=root,xtesting,ci,core [handlers] -keys=console,wconsole,file,null +keys=console,wconsole,file [formatters] keys=standard [logger_root] level=NOTSET -handlers=null +handlers=wconsole,file [logger_xtesting] level=NOTSET @@ -26,22 +26,6 @@ level=NOTSET handlers=console qualname=xtesting.core -[logger_energy] -level=NOTSET -handlers=wconsole -qualname=xtesting.energy - -[logger_utils] -level=NOTSET -handlers=wconsole -qualname=xtesting.utils - -[handler_null] -class=NullHandler -level=NOTSET -formatter=standard -args=() - [handler_console] class=StreamHandler level=INFO diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py index ed053e09..932e0230 100644 --- a/xtesting/core/feature.py +++ b/xtesting/core/feature.py @@ -27,34 +27,6 @@ class Feature(testcase.TestCase): """Base model for single feature.""" __logger = logging.getLogger(__name__) - dir_results = "/var/lib/xtesting/results" - - def __init__(self, **kwargs): - super(Feature, self).__init__(**kwargs) - self.result_file = "{}/{}.log".format(self.dir_results, self.case_name) - try: - module = kwargs['run']['module'] - self.logger = logging.getLogger(module) - except KeyError: - self.__logger.warning( - "Cannot get module name %s. Using %s as fallback", - kwargs, self.case_name) - self.logger = logging.getLogger(self.case_name) - Feature.configure_logger(self.logger, self.result_file) - - @staticmethod - def configure_logger(logger, result_file): - """Configure the logger to print in result_file.""" - handler = logging.StreamHandler() - handler.setLevel(logging.WARN) - logger.addHandler(handler) - handler = logging.FileHandler(result_file) - handler.setLevel(logging.DEBUG) - logger.addHandler(handler) - formatter = logging.Formatter( - '%(asctime)s - %(name)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - logger.addHandler(handler) def execute(self, **kwargs): """Execute the Python method. @@ -104,7 +76,6 @@ class Feature(testcase.TestCase): self.result = 100 except Exception: # pylint: disable=broad-except self.__logger.exception("%s FAILED", self.project_name) - self.__logger.info("Test result is stored in '%s'", self.result_file) self.stop_time = time.time() return exit_code @@ -114,6 +85,11 @@ class BashFeature(Feature): __logger = logging.getLogger(__name__) + def __init__(self, **kwargs): + super(BashFeature, self).__init__(**kwargs) + dir_results = "/var/lib/xtesting/results" + self.result_file = "{}/{}.log".format(dir_results, self.case_name) + def execute(self, **kwargs): """Execute the cmd passed as arg @@ -131,6 +107,8 @@ class BashFeature(Feature): proc = subprocess.Popen(cmd.split(), stdout=f_stdout, stderr=subprocess.STDOUT) ret = proc.wait() + self.__logger.info( + "Test result is stored in '%s'", self.result_file) if ret != 0: self.__logger.error("Execute command: %s failed", cmd) except KeyError: diff --git a/xtesting/tests/unit/core/test_feature.py b/xtesting/tests/unit/core/test_feature.py index 3d3b66d3..72bc488f 100644 --- a/xtesting/tests/unit/core/test_feature.py +++ b/xtesting/tests/unit/core/test_feature.py @@ -38,19 +38,6 @@ class FeatureTestingBase(unittest.TestCase): self.assertEqual(self.feature.start_time, 1) self.assertEqual(self.feature.stop_time, 2) - def test_logger_module_ko(self): - with mock.patch('six.moves.builtins.open'): - self.feature = feature.Feature( - project_name=self._project_name, case_name=self._case_name) - self.assertEqual(self.feature.logger.name, self._case_name) - - def test_logger_module(self): - with mock.patch('six.moves.builtins.open'): - self.feature = feature.Feature( - project_name=self._project_name, case_name=self._case_name, - run={'module': 'bar'}) - self.assertEqual(self.feature.logger.name, 'bar') - class FeatureTesting(FeatureTestingBase): -- cgit 1.2.3-korg