コード例 #1
0
 def test_func_raises_not_a_directory_if_scenario_log_dir_is_not_a_directory(self, tmp_path):
     f = tmp_path.joinpath("scenarios")
     f.mkdir(parents=True)
     f= f.joinpath("wolohoo")
     f.write_text("something")
     with pytest.raises(NotADirectoryError):
         verify_scenario_log_dir("wolohoo", tmp_path)
コード例 #2
0
def pack_logs(ctx, scenario_file, post_to_rocket, pack_n_latest, target_dir):
    data_path: Path = ctx.obj["data_path"].absolute()
    scenario_file = Path(scenario_file.name).absolute()
    scenario_name = Path(scenario_file.name).stem

    log_file_name = construct_log_file_name("pack-logs", data_path,
                                            scenario_file)
    configure_logging_for_subcommand(log_file_name)

    # The logs are located at .raiden/scenario-player/scenarios/<scenario-name>
    # - make sure the path exists.
    scenarios_path, scenario_log_dir = verify_scenario_log_dir(
        scenario_name, data_path)

    # List all node folders which fall into the range of pack_n_latest
    folders = pack_n_latest_node_logs_in_dir(scenario_log_dir, pack_n_latest)
    # List all files that match the filters `scenario_name` and the `pack_n_latest` counter.
    files = pack_n_latest_logs_for_scenario_in_dir(scenario_name,
                                                   scenario_log_dir,
                                                   pack_n_latest)

    # Now that we have all our files, create a tar archive at the requested location.
    archive_fpath = target_dir.joinpath(
        f'Scenario_player_Logs-{scenario_name}-{pack_n_latest or "all"}-latest'
        f"-{datetime.today():%Y-%m-%d}.tar.gz")

    with tarfile.open(str(archive_fpath), mode="w:gz") as archive:
        for obj in chain(folders, files):
            archive.add(str(obj), arcname=str(obj.relative_to(scenarios_path)))

    # Print some feedback to stdout. This is also a sanity check,
    # asserting the archive is readable.
    # Race conditions are ignored.
    print(f"Created archive at {archive_fpath}")
    print(f"- {archive_fpath}")
    with tarfile.open(str(archive_fpath)) as f:
        for name in f.getnames():
            print(f"- - {name}")

    if post_to_rocket:
        rc_message = {"msg": None, "description": None}
        if pack_n_latest == 1:
            # Index 0 will always return the latest log file for the scenario.
            rc_message["text"] = construct_rc_message(target_dir,
                                                      archive_fpath, files[0])
            rc_message[
                "description"] = f"Log files for scenario {scenario_name}"
        post_to_rocket_chat(archive_fpath, **rc_message)
コード例 #3
0
 def test_func_returns_exepcted_paths(self, tmp_path):
     f = tmp_path.joinpath("scenarios", "test_scenario")
     f.mkdir(parents=True)
     scenarios_dir, log_dir = verify_scenario_log_dir("test_scenario", tmp_path)
     assert scenarios_dir == tmp_path.joinpath("scenarios")
     assert log_dir == tmp_path.joinpath("scenarios", "test_scenario")
コード例 #4
0
 def test_func_raises_file_not_found_if_log_dir_does_not_exist(self, tmp_path):
     with pytest.raises(FileNotFoundError):
         verify_scenario_log_dir("wolohoo", tmp_path)