示例#1
0
def test_get_repository_address_lack_of_conf_file(mocker):
    mocker.patch("util.config.Config.get_config_path", return_value="")
    mocker.patch("os.path.isfile").return_value = False

    repository_location = get_repository_address()

    assert not repository_location
示例#2
0
def test_get_repository_address_incorrect_file(mocker):
    mocker.patch("util.config.Config.get_config_path", return_value="")
    mocker.patch("os.path.isfile").return_value = True

    with patch("builtins.open", mock_open(read_data=INCORRECT_CONF_FILE)):
        repository_location = get_repository_address()

    assert not repository_location
示例#3
0
def test_get_repository_address_success(mocker):
    mocker.patch("util.config.Config.get_config_path", return_value="")
    mocker.patch("os.path.isfile").return_value = True

    with patch("builtins.open", mock_open(read_data=CORRECT_CONF_FILE)):
        repository_location = get_repository_address()

    assert repository_location == REPOSITORY_ADDRESS
示例#4
0
def install(ctx: click.Context, template_name: str):
    packs_location = os.path.join(Config.get_config_path(), "packs")
    chart_file_location = os.path.join(packs_location, template_name)
    repository_address = get_repository_address()

    with spinner(
            text=Texts.GETTING_LIST_OF_TEMPLATES_MSG) as templates_spinner:
        try:
            remote_template = load_remote_template(
                template_name, repository_address=repository_address)
        except Exception:
            templates_spinner.stop()
            handle_error(logger,
                         user_msg=Texts.FAILED_TO_LOAD_TEMPLATE.format(
                             template_name=template_name),
                         log_msg=Texts.FAILED_TO_LOAD_TEMPLATE.format(
                             template_name=template_name),
                         add_verbosity_msg=ctx.obj.verbosity == 0)
            sys.exit(1)

        if not remote_template:
            templates_spinner.stop()
            handle_error(logger,
                         user_msg=Texts.REMOTE_TEMPLATE_NOT_FOUND.format(
                             template_name=template_name),
                         log_msg=Texts.REMOTE_TEMPLATE_NOT_FOUND.format(
                             template_name=template_name),
                         add_verbosity_msg=ctx.obj.verbosity == 0)
            sys.exit(1)

    local_templates = get_local_templates()
    local_template_counterpart = local_templates.get(template_name)

    if local_template_counterpart:
        if (not click.get_current_context().obj.force) and (not click.confirm(
                Texts.LOCAL_VERSION_ALREADY_INSTALLED.format(
                    local_version=local_template_counterpart.local_version,
                    template_name=local_template_counterpart.name,
                    remote_version=remote_template.remote_version))):
            sys.exit(0)
        # noinspection PyBroadException
        try:
            shutil.rmtree(chart_file_location)
        except Exception:
            logger.exception("failed to remove local copy of template!")

    with spinner(text=Texts.DOWNLOADING_TEMPLATE) as download_spinner:
        try:
            download_remote_template(template=remote_template,
                                     repository_address=repository_address,
                                     output_dir_path=packs_location)
        except Exception:
            download_spinner.stop()
            handle_error(logger,
                         user_msg=Texts.FAILED_TO_INSTALL_TEMPLATE.format(
                             template_name=template_name,
                             repository_name=repository_address),
                         log_msg=Texts.FAILED_TO_INSTALL_TEMPLATE.format(
                             template_name=template_name,
                             repository_name=repository_address),
                         add_verbosity_msg=ctx.obj.verbosity == 0)
            sys.exit(1)

    update_resources_in_packs()

    click.echo("successfully installed!")