Beispiel #1
0
 def test_given_a_list_of_done_studies_when_retrieve_all_studies_called_then_message_is_shown(
     self, ):
     # given
     study = StudyDTO("path")
     study.done = True
     study_list = [deepcopy(study), deepcopy(study)]
     display_mock = mock.Mock(spec=IDisplay)
     my_retriever = RetrieveController(
         self.data_repo,
         self.remote_env_mock,
         self.file_manager,
         display_mock,
         self.state_updater_mock,
     )
     my_retriever.repo.get_list_of_studies = mock.Mock(
         return_value=study_list)
     display_mock.show_message = mock.Mock()
     # when
     output = my_retriever.retrieve_all_studies()
     # then
     expected_message1 = "Retrieving all studies"
     expected_message2 = "Everything is done"
     calls = [
         call(expected_message1, mock.ANY),
         call(expected_message2, mock.ANY),
     ]  # , call(my_study3)]
     display_mock.show_message.assert_has_calls(calls)
     assert output is True
Beispiel #2
0
 def test_given_one_study_when_retrieve_all_studies_call_then_study_retriever_is_called_once(
         self, my_study):
     # given
     list_of_studies = [my_study]
     self.data_repo.get_list_of_studies = mock.Mock(
         return_value=list_of_studies)
     my_retriever = RetrieveController(
         self.data_repo,
         self.remote_env_mock,
         self.file_manager,
         self.display,
         self.state_updater_mock,
     )
     my_retriever.study_retriever.retrieve = mock.Mock()
     self.display.show_message = mock.Mock()
     # when
     my_retriever.retrieve_all_studies()
     # then
     self.display.show_message.assert_called_once_with(
         "Retrieving all studies", mock.ANY)
     my_retriever.study_retriever.retrieve.assert_called_once_with(my_study)
 def setup_method(self):
     connection = mock.Mock()
     connection.home_dir = "Submitted"
     slurm_script_features = SlurmScriptFeatures()
     self.env = RemoteEnvironmentWithSlurm(
         _connection=connection,
         slurm_script_features=slurm_script_features)
     state_updater = StateUpdater(env=self.env, display=mock.Mock())
     self.retrieve_controller = RetrieveController(
         repo=mock.Mock(),
         env=self.env,
         file_manager=mock.Mock(),
         display=mock.Mock(),
         state_updater=state_updater,
     )
Beispiel #4
0
 def test_given_a_list_of_done_studies_when_all_studies_done_called_then_return_true(
     self, ):
     # given
     study = StudyDTO("path")
     study.done = True
     study_list = [deepcopy(study), deepcopy(study)]
     my_retriever = RetrieveController(
         self.data_repo,
         self.remote_env_mock,
         self.file_manager,
         self.display,
         self.state_updater_mock,
     )
     my_retriever.repo.get_list_of_studies = mock.Mock(
         return_value=study_list)
     # when
     output = my_retriever.all_studies_done
     # then
     assert output is True
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()
Beispiel #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()