def test_given_true_run_wait_mode_when_all_studies_done_the_third_time_then_retrieve_all_studies_is_called_three_times(
     self, ):
     # given
     wait_controller = WaitController(display=mock.Mock())
     wait_controller.countdown = mock.Mock()
     antares_launcher = AntaresLauncher(
         study_list_composer=mock.Mock(),
         launch_controller=mock.Mock(),
         retrieve_controller=mock.Mock(),
         job_kill_controller=None,
         check_queue_controller=None,
         wait_controller=wait_controller,
         wait_mode=True,
         wait_time=1,
         xpansion_mode=None,
         job_id_to_kill=None,
         check_queue_bool=None,
     )
     type(antares_launcher.retrieve_controller
          ).all_studies_done = PropertyMock(
              side_effect=[False, False, True, False])
     # when
     antares_launcher.run()
     # then
     assert antares_launcher.retrieve_controller.retrieve_all_studies.call_count == 3
     assert wait_controller.countdown.call_count == 2
 def test_given_false_wait_mode_when_run_then_run_once_mode_called(self):
     # given
     antares_launcher = AntaresLauncher(
         study_list_composer=None,
         launch_controller=None,
         retrieve_controller=None,
         job_kill_controller=None,
         check_queue_controller=None,
         wait_controller=None,
         wait_mode=False,
         wait_time=None,
         xpansion_mode=None,
         job_id_to_kill=None,
         check_queue_bool=None,
     )
     antares_launcher.run_once_mode = mock.Mock()
     # when
     antares_launcher.run()
     # then
     antares_launcher.run_once_mode.assert_called_once()
 def test_given_true_check_queue_bool_when_run_then_check_queue_controller_checks_queue(
     self, ):
     # given
     dummy = Mock()
     antares_launcher = AntaresLauncher(
         study_list_composer=dummy,
         launch_controller=dummy,
         retrieve_controller=dummy,
         job_kill_controller=dummy,
         check_queue_controller=Mock(),
         wait_controller=dummy,
         wait_mode=False,
         wait_time=42,
         xpansion_mode=None,
         check_queue_bool=True,
     )
     # when
     antares_launcher.run()
     # then
     antares_launcher.check_queue_controller.check_queue.assert_called_once(
     )
 def test_given_job_id_to_kill_when_run_then_job_kill_controller_kills_job_with_good_id(
     self, ):
     # given
     job_id_to_kill = 42
     dummy = Mock()
     antares_launcher = AntaresLauncher(
         study_list_composer=dummy,
         launch_controller=dummy,
         retrieve_controller=dummy,
         job_kill_controller=mock.Mock(),
         check_queue_controller=dummy,
         wait_controller=dummy,
         wait_mode=False,
         wait_time=42,
         xpansion_mode=None,
         job_id_to_kill=job_id_to_kill,
         check_queue_bool=False,
     )
     # when
     antares_launcher.run()
     # then
     antares_launcher.job_kill_controller.kill_job.assert_called_once_with(
         job_id_to_kill)
def run_with(
    arguments: argparse.Namespace, parameters: MainParameters, show_banner=False
):
    """Instantiates all the objects necessary to antares-launcher, and runs the program"""
    if arguments.version:
        print(f"Antares_Launcher v{VERSION}")
        return

    if show_banner:
        print(ANTARES_LAUNCHER_BANNER)

    display = DisplayTerminal()
    file_manager = FileManager(display)

    db_json_file_path = parameters.json_dir / parameters.default_json_db_name

    tree_structure_initializer = TreeStructureInitializer(
        display,
        file_manager,
        arguments.studies_in,
        arguments.log_dir,
        arguments.output_dir,
    )

    tree_structure_initializer.init_tree_structure()
    logger_initializer = LoggerInitializer(
        str(Path(arguments.log_dir) / "antares_launcher.log")
    )
    logger_initializer.init_logger()

    # connection
    ssh_dict = get_ssh_config_dict(
        file_manager,
        arguments.json_ssh_config,
        parameters.default_ssh_dict,
    )
    connection = ssh_connection.SshConnection(config=ssh_dict)
    verify_connection(connection, display)

    slurm_script_features = SlurmScriptFeatures(parameters.slurm_script_path)
    environment = RemoteEnvironmentWithSlurm(connection, slurm_script_features)
    data_repo = DataRepoTinydb(
        database_file_path=db_json_file_path, db_primary_key=parameters.db_primary_key
    )
    study_list_composer = StudyListComposer(
        repo=data_repo,
        file_manager=file_manager,
        display=display,
        parameters=StudyListComposerParameters(
            studies_in_dir=arguments.studies_in,
            time_limit=arguments.time_limit,
            log_dir=arguments.log_dir,
            n_cpu=arguments.n_cpu,
            xpansion_mode=arguments.xpansion_mode,
            output_dir=arguments.output_dir,
            post_processing=arguments.post_processing,
            antares_versions_on_remote_server=parameters.antares_versions_on_remote_server,
        ),
    )
    launch_controller = LaunchController(
        repo=data_repo,
        env=environment,
        file_manager=file_manager,
        display=display,
    )
    state_updater = StateUpdater(env=environment, display=display)
    retrieve_controller = RetrieveController(
        repo=data_repo,
        env=environment,
        file_manager=file_manager,
        display=display,
        state_updater=state_updater,
    )
    slurm_queue_show = SlurmQueueShow(env=environment, display=display)
    check_queue_controller = CheckQueueController(
        slurm_queue_show=slurm_queue_show,
        state_updater=state_updater,
        repo=data_repo,
    )
    job_kill_controller = JobKillController(
        env=environment,
        display=display,
        repo=data_repo,
    )
    wait_controller = WaitController(display=display)

    launcher = AntaresLauncher(
        study_list_composer=study_list_composer,
        launch_controller=launch_controller,
        retrieve_controller=retrieve_controller,
        job_kill_controller=job_kill_controller,
        check_queue_controller=check_queue_controller,
        wait_controller=wait_controller,
        wait_mode=arguments.wait_mode,
        wait_time=arguments.wait_time,
        job_id_to_kill=arguments.job_id_to_kill,
        xpansion_mode=arguments.xpansion_mode,
        check_queue_bool=arguments.check_queue,
    )
    launcher.run()
Exemple #6
0
def run_with(arguments):
    """Instantiates all the objects necessary to antares-launcher, and runs the program"""
    if arguments.version:
        print(f"Antares_Launcher v{VERSION}")
        return

    print(ANTARES_LAUNCHER_BANNER)

    studies_in = Path(arguments.studies_in).resolve()
    display = DisplayTerminal()
    file_manager = FileManager(display)

    json_file_name = JSON_DIR / DEFAULT_JSON_DB_NAME

    tree_structure_initializer = TreeStructureInitializer(
        display,
        file_manager,
        arguments.studies_in,
        definitions.LOG_DIR,
        arguments.output_dir,
    )

    tree_structure_initializer.init_tree_structure()
    logger_initializer = LoggerInitializer(
        Path(arguments.log_dir) / "antares_launcher.log")
    logger_initializer.init_logger()

    # connection
    ssh_dict = get_ssh_config_dict(file_manager, arguments.json_ssh_config)
    connection = ssh_connection.SshConnection(config=ssh_dict)
    verify_connection(connection, display)

    slurm_script_features = SlurmScriptFeatures()
    environment = RemoteEnvironmentWithSlurm(connection, slurm_script_features)
    data_repo = DataRepoTinydb(database_name=json_file_name)
    study_list_composer = StudyListComposer(
        repo=data_repo,
        file_manager=file_manager,
        display=display,
        studies_in_dir=studies_in,
        time_limit=arguments.time_limit,
        n_cpu=arguments.n_cpu,
        log_dir=arguments.log_dir,
        output_dir=arguments.output_dir,
        xpansion_mode=arguments.xpansion_mode,
        post_processing=arguments.post_processing,
    )
    launch_controller = LaunchController(
        repo=data_repo,
        env=environment,
        file_manager=file_manager,
        display=display,
    )
    state_updater = StateUpdater(env=environment, display=display)
    retrieve_controller = RetrieveController(
        repo=data_repo,
        env=environment,
        file_manager=file_manager,
        display=display,
        state_updater=state_updater,
    )
    slurm_queue_show = SlurmQueueShow(env=environment, display=display)
    check_queue_controller = CheckQueueController(
        slurm_queue_show=slurm_queue_show,
        state_updater=state_updater,
        repo=data_repo)
    job_kill_controller = JobKillController(
        env=environment,
        display=display,
        repo=data_repo,
    )
    wait_controller = WaitController(display=display)

    launcher = AntaresLauncher(
        study_list_composer=study_list_composer,
        launch_controller=launch_controller,
        retrieve_controller=retrieve_controller,
        job_kill_controller=job_kill_controller,
        check_queue_controller=check_queue_controller,
        wait_controller=wait_controller,
        wait_mode=arguments.wait_mode,
        wait_time=arguments.wait_time,
        job_id_to_kill=arguments.job_id_to_kill,
        xpansion_mode=arguments.xpansion_mode,
        check_queue_bool=arguments.check_queue,
    )
    launcher.run()