Example #1
0
def test_validate_pack_success(mocker):
    mocker.patch("os.path.join").return_value = "Chart.yaml"
    mocker.patch("os.path.isfile").return_value = True

    with patch("builtins.open", mock_open(read_data=CHART_FILE_CONTENT)), \
         patch.object(util.config.Config, 'get_config_path', return_value=""):  # noqa
        validate_pack(PACK_NAME)
Example #2
0
def test_validate_pack_wrong_name(mocker):
    mocker.patch("os.path.join").return_value = "Chart.yaml"
    mocker.patch("os.path.isfile").return_value = False
    mocker.patch("commands.experiment.common.handle_error")

    with patch("builtins.open", mock_open(read_data=CHART_FILE_CONTENT_INCORRECT)), \
         patch.object(util.config.Config, "get_config_path", return_value=""), \
         patch('commands.experiment.common.exit') as exit_mock:  # noqa
        validate_pack(PACK_NAME)
        assert exit_mock.called
Example #3
0
def submit(state: State, script_location: str, script_folder_location: str,
           template: str, name: str, pack_param: List[Tuple[str, str]],
           parameter_range: List[Tuple[str, str]],
           parameter_set: Tuple[str, ...], env: List[str],
           script_parameters: Tuple[str, ...], requirements: Optional[str]):
    logger.debug(Texts.SUBMIT_START_LOG_MSG)
    validate_script_location(script_location)
    validate_pack_params(pack_param)
    validate_pack(template)

    if os.path.isdir(script_location):
        if not requirements:
            requirements = get_default_requirements_location(
                script_directory=script_location)
        script_location = get_default_script_location(
            script_directory=script_location)

    if script_folder_location:
        validate_script_folder_location(script_folder_location)

    click.echo(Texts.SUBMIT_START_USER_MSG)

    runs_list = None
    # noinspection PyBroadException
    try:
        runs_list, runs_errors, _ = submit_experiment(
            run_kind=RunKinds.TRAINING,
            script_location=script_location,
            script_folder_location=script_folder_location,
            template=template,
            name=name,
            pack_params=pack_param,
            parameter_range=parameter_range,
            parameter_set=parameter_set,
            script_parameters=script_parameters,
            env_variables=env,
            requirements_file=requirements)
    except K8sProxyCloseError as exe:
        handle_error(user_msg=exe.message)
        click.echo(exe.message)
        if not runs_list:
            exit(1)
    except SubmitExperimentError as exe:
        handle_error(user_msg=Texts.SUBMIT_ERROR_MSG.format(
            exception_message=exe.message))
        exit(1)
    except Exception:
        handle_error(user_msg=Texts.SUBMIT_OTHER_ERROR_MSG)
        exit(1)

    # display information about status of a training
    click.echo(
        tabulate(
            [(run.cli_representation.name, run.cli_representation.parameters,
              run.cli_representation.status,
              format_run_message(runs_errors.get(run.name, "")))
             for run in runs_list],
            headers=[RUN_NAME, RUN_PARAMETERS, RUN_STATUS, RUN_MESSAGE],
            tablefmt=TBLT_TABLE_FORMAT))

    # if there is at least one FAILED experiment - application has to return exit code != 0
    if any(run.state == RunStatus.FAILED for run in runs_list):
        handle_error(logger, Texts.FAILED_RUNS_LOG_MSG)
        exit(1)