diff --git a/simrunner/main.py b/simrunner/main.py index b198dc93f1e50254e63b6ac822adeffcf1253e64..96b760f8ef22e9701a8925a2a59bec960bfe1029 100644 --- a/simrunner/main.py +++ b/simrunner/main.py @@ -15,7 +15,7 @@ stop_requested = False # Function to print terminal output and handle errors -def terminal_output(output, errors, return_code): +def terminal_output(output, errors, return_code, msg): if return_code > 0: logger.error(f'return code: {return_code}') if errors: @@ -23,20 +23,25 @@ def terminal_output(output, errors, return_code): if output: logger.info(output) else: - logger.info(output) + if output: + logger.info(output) + logger.info(msg) # Function to pull data from remote machines to the local machine def pull_data(source_path, desti_path): + desti = os.path.join(desti_path, 'output') + os.makedirs(desti, mode=0o777, exist_ok=True) if args.hosts: for host in args.hosts: ssh_target = f'{args.user}@{host}' - scp_cmd = f'scp -r {ssh_target}:{source_path} {desti_path}' + scp_cmd = f'scp -r {ssh_target}:{source_path}/*{host}* {desti}' subprocess.run(scp_cmd, shell=True, check=True) def rm_data(t_data_path): if args.hosts: + logger.info('remove test_data folder') host = args.hosts[0] ssh_target = f'{args.user}@{host}' rm_cmd = f'ssh {ssh_target} rm -r {t_data_path}' @@ -53,8 +58,9 @@ def handle_sigint(signum, frame): re = subprocess.run(kill_cmd, shell=True) ou = re.stdout er = re.stderr - logger.info(f'{ou} {er}') - logger.info(f'{kill_target} killed') + rc = re.returncode + terminal_msg = f'{kill_target} killed' + terminal_output(ou, er, rc, terminal_msg) # Function to run the detector simulation with the given event arguments @@ -83,14 +89,15 @@ def run_sim(e_dict, d_path, sim_path, main_path): for folder_name, host, future in futures: output, errors, result = future.result() - terminal_output(output, errors, result) + terminal_msg = f'{folder_name}_{host if host else ""} done!' + if not stop_requested: + terminal_output(output, errors, result, terminal_msg) if output: if host: stat_file_name = f'statistics_{folder_name}_{host}' else: stat_file_name = f'statistics_{folder_name}_lokal' op.write_statistics(main_path, stat_file_name, output) - logger.info(f'{folder_name}_{host if host else ""} done!') # --- MAIN ---