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/core/feature.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'xtesting/core/feature.py') 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: -- cgit 1.2.3-korg