def _run_command(context, command): context.log = "_%s_%i.log" % (context.project, context.scenariono) sonarhome = os.environ.get("SONARHOME", None) if sonarhome: context.serverlog = get_sonar_log_file(sonarhome) if getattr(context, "serverlogfd", None) is not None: context.serverlogfd.close() context.serverlogfd = open(context.serverlog, "r") context.serverlogfd.seek(0, 2) else: context.serverlogfd = None projecthome = os.path.join(TESTDATADIR, context.project) with open(context.log, "w") as logfile: proc = subprocess.Popen(command, shell=True, cwd=projecthome, stdout=logfile, stderr=subprocess.STDOUT) proc.communicate() # print log file result for debugging #if proc.returncode != 0: # with open(context.log, "r") as log: # print(RED + log.read() + RESET_ALL) context.rc = proc.returncode
def _run_command(context, command): context.log = "_%s_%i.log" % (context.project, context.scenariono) sonarhome = os.environ.get("SONARHOME", None) if sonarhome: context.serverlog = get_sonar_log_file(sonarhome) if getattr(context, "serverlogfd", None) is not None: context.serverlogfd.close() context.serverlogfd = open(context.serverlog, "r") context.serverlogfd.seek(0, 2) else: context.serverlogfd = None projecthome = os.path.join(TESTDATADIR, context.project) with open(context.log, "w") as logfile: proc = subprocess.Popen(command, shell=True, cwd=projecthome, stdout=logfile, stderr=subprocess.STDOUT) proc.communicate() # print errors and warnings from log file if proc.returncode != 0: print(RED + "cmd: " + command + RESET_ALL) with open(context.log, "r") as log: for line in log: if "WARN:" in line or "ERROR:" in line: print(RED + line + RESET_ALL) context.rc = proc.returncode
def check_logs(sonarhome): sys.stdout.write(INDENT + "logs check ... ") sys.stdout.flush() badlines, errors, warnings = analyse_log(get_sonar_log_file(sonarhome)) reslabel = GREEN + "OK\n" if errors > 0 or (errors == 0 and warnings == 0 and len(badlines) > 0): reslabel = RED + "FAILED\n" elif warnings > 0: reslabel = YELLOW + "WARNINGS\n" sys.stdout.write(reslabel + RESET) if badlines: for line in badlines: sys.stdout.write(2*INDENT + line) summary_msg = "%i errors and %i warnings\n" % (errors, warnings) print(2*INDENT + len(summary_msg) * "-") print(2*INDENT + summary_msg) return errors == 0