From 5389151567d189fb65fcded344929dcc319f2db3 Mon Sep 17 00:00:00 2001 From: Vincent Danno Date: Mon, 7 Jun 2021 20:53:10 +0200 Subject: MTS inherits BashFeature Signed-off-by: Vincent Danno Change-Id: Ifa3a5d5946c29863905490de5f875e17026744a5 --- xtesting/core/mts.py | 68 ++++++---------------------------------------------- 1 file changed, 7 insertions(+), 61 deletions(-) (limited to 'xtesting/core/mts.py') diff --git a/xtesting/core/mts.py b/xtesting/core/mts.py index f1cf80ac..b9f605b8 100644 --- a/xtesting/core/mts.py +++ b/xtesting/core/mts.py @@ -15,13 +15,12 @@ import csv import logging import os import shutil -import subprocess -import sys import time from lxml import etree import prettytable +from xtesting.core import feature from xtesting.core import testcase @@ -29,7 +28,7 @@ __author__ = ("Vincent Mahe , " "Cedric Ollivier ") -class MTSLauncher(testcase.TestCase): +class MTSLauncher(feature.BashFeature): """Class designed to run MTS tests.""" __logger = logging.getLogger(__name__) @@ -45,7 +44,6 @@ class MTSLauncher(testcase.TestCase): def __init__(self, **kwargs): super(MTSLauncher, self).__init__(**kwargs) - self.result_file = "{}/{}.log".format(self.res_dir, self.case_name) # Location of the HTML report generated by MTS self.mts_stats_dir = os.path.join(self.res_dir, 'mts_stats_report') # Location of the log files generated by MTS for each test. @@ -164,25 +162,11 @@ class MTSLauncher(testcase.TestCase): return True def execute(self, **kwargs): # pylint: disable=too-many-locals - """Execute the cmd passed as arg - - Args: - kwargs: Arbitrary keyword arguments. - - Returns: - 0 if cmd returns 0, - -1 otherwise. - """ try: - console = kwargs["console"] if "console" in kwargs else False # Read specific parameters for MTS test_file = kwargs["test_file"] log_level = kwargs[ "log_level"] if "log_level" in kwargs else "INFO" - - # For some MTS tests, we need to force stop after N sec - max_duration = kwargs[ - "max_duration"] if "max_duration" in kwargs else None store_method = kwargs[ "store_method"] if "store_method" in kwargs else "FILE" # Must use the $HOME_MTS/bin as current working dir @@ -196,7 +180,7 @@ class MTSLauncher(testcase.TestCase): enabled_testcases_str = ' '.join(enabled_testcases) check_ok = self.check_enabled_mts_test_cases(enabled_testcases) if not check_ok: - return -2 + return -3 # Build command line to launch for MTS cmd = ("cd {} && ./startCmd.sh {} {} -sequential -levelLog:{}" @@ -229,54 +213,16 @@ class MTSLauncher(testcase.TestCase): "MTS statistics output dir: %s ", self.mts_stats_dir) self.__logger.info("MTS logs output dir: %s ", self.mts_logs_dir) - # Launch MTS as a sub-process - # and save its standard output to a file - with open(self.result_file, 'w') as f_stdout: - self.__logger.info("Calling %s", cmd) - process = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - for line in iter(process.stdout.readline, b''): - if console: - sys.stdout.write(line.decode("utf-8")) - f_stdout.write(line.decode("utf-8")) - try: - process.wait(timeout=max_duration) - except subprocess.TimeoutExpired: - process.kill() - self.__logger.info( - "Killing MTS process after %d second(s).", - max_duration) - return 3 - with open(self.result_file, 'r') as f_stdin: - self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip()) - return process.returncode + kwargs.pop("cmd", None) + return super(MTSLauncher, self).execute(cmd=cmd, **kwargs) + except KeyError: self.__logger.error("Missing mandatory arg for MTS. kwargs: %s", kwargs) return -1 def run(self, **kwargs): - """Run the feature. - - It allows executing any Python method by calling execute(). - - It sets the following attributes required to push the results - to DB: - - * result, - * start_time, - * stop_time. - - It doesn't fulfill details when pushing the results to the DB. - - Args: - kwargs: Arbitrary keyword arguments. - - Returns: - TestCase.EX_OK if execute() returns 0, - TestCase.EX_RUN_ERROR otherwise. - """ + """Runs the MTS suite""" self.start_time = time.time() exit_code = testcase.TestCase.EX_RUN_ERROR self.result = 0 -- cgit 1.2.3-korg