From 75f4b5a2ff78b035af552213431b9ed402a656ca Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Wed, 12 May 2021 13:10:28 -0600 Subject: [PATCH] lf_check.py : stdout and stderr placed in html-reports Signed-off-by: Chuck SmileyRekiere --- py-scripts/sandbox/lf_check.py | 55 ++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/py-scripts/sandbox/lf_check.py b/py-scripts/sandbox/lf_check.py index 2af7bf49..e91c9c0d 100755 --- a/py-scripts/sandbox/lf_check.py +++ b/py-scripts/sandbox/lf_check.py @@ -33,6 +33,8 @@ import sys #from ..lf_report import lf_report sys.path.append('../') from lf_report import lf_report +sys.path.append('/') + CONFIG_FILE = os.getcwd() + '/lf_check_config.ini' @@ -53,7 +55,8 @@ class FileAdapter(object): class lf_check(): def __init__(self, - _csv_outfile): + _csv_outfile, + _outfile): self.lf_mgr_ip = "" self.lf_mgr_port = "" self.radio_dict = {} @@ -62,7 +65,8 @@ class lf_check(): os.chdir(path_parent) self.scripts_wd = os.getcwd() self.results = "" - self.csv_outfile = _csv_outfile + self.csv_outfile = _csv_outfile, + self.outfile = _outfile # Functions in this section are/can be overridden by descendants @@ -102,7 +106,11 @@ class lf_check(): # no spaces after FACTORY_DFLT command = "./{} {}".format("scenario.py", "--load FACTORY_DFLT") - process = subprocess.run((command).split(' '), check= True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True,timeout=20) + #process = subprocess.run((command).split(' '), check= True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True,timeout=20) + process = subprocess.Popen((command).split(' '), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + # wait for the process to terminate + out, err = process.communicate() + errcode = process.returncode print("###################### STDOUT - scenario load FACTORY_DFLT #########################") print(process.stdout) print("###################### STDERR - scenario load FACTORY_DFLT #########################") @@ -158,18 +166,28 @@ class lf_check(): # Put lanforge in known state #try: - process = subprocess.run((command).split(' '), check= True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) - #process = subprocess.run((command).split(' '), check= True, capture_output=True, timeout=30 ) + if self.outfile is not None: + stdout_log_txt = self.outfile[:-4] + stdout_log_txt = stdout_log_txt + "{}-stdout.txt".format(test) + print("stdout_log_txt: {}".format(stdout_log_txt)) + stdout_log = open(stdout_log_txt, 'a') + stderr_log_txt = self.outfile[:-4] + stderr_log_txt = stderr_log_txt + "{}-stderr.txt".format(test) + print("stdout_log_txt: {}".format(stderr_log_txt)) + stderr_log = open(stderr_log_txt, 'a') + #process = subprocess.Popen((command).split(' '), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + process = subprocess.Popen((command).split(' '), shell=False, stdout=stdout_log, stderr=stderr_log, universal_newlines=True) + # wait for the process to terminate + out, err = process.communicate() + errcode = process.returncode + #pss1 = process.stdout.decode('utf-8', 'ignore') #print(pss1) - #print("###################### STDOUT #########################") - print(process.stdout) - if (process.stdout == ''): - print("stdout empty") - else: - print("stdout not empty") + #print(process.stdout) + print(stdout_log_txt) + print(stderr_log_txt) #print("###################### STDERR #########################") # if the stderr is empty the test is considered , does there need to check for pass fail print(process.stderr) @@ -197,24 +215,29 @@ Summary : for running scripts listed in lf_check_config.ini ''') - parser.add_argument('--csv_outfile', help="--csv_outfile