Ejemplo n.º 1
0
def copy(ctx: click.Context, src_template_name: str, dest_template_name: str, description: str, version: str):
    local_templates = get_local_templates()
    if not local_templates.get(src_template_name):
        click.echo(Texts.SRC_TEMPLATE_NOT_FOUND.format(src_template_name=src_template_name))
        exit(1)

    if local_templates.get(dest_template_name):
        click.echo(Texts.TEMPLATE_ALREADY_EXISTS.format(dest_template_name=dest_template_name))
        exit(1)

    if not description:
        description = None
        while not description or not description.strip():
            description = click.prompt(Texts.DESCRIPTION_PROMPT.format(max_len=MAX_TEMPLATE_DESCRIPTION_LENGTH))

        description = description[:MAX_TEMPLATE_DESCRIPTION_LENGTH]

    try:
        new_template = Template(name=dest_template_name, description=description, local_version=version)
        new_template.render_from_existing_template(src_template_name=src_template_name)
        click.echo(Texts.COPY_SUCCESS.format(dest_template_name=dest_template_name,
                                             src_template_name=src_template_name))
    except Exception:
        error_msg = Texts.COPY_FAILURE.format(src_template_name=src_template_name,
                                              dest_template_name=dest_template_name)
        logger.exception(error_msg)
        click.echo(error_msg)
        exit(1)
Ejemplo n.º 2
0
def test_update_chart_yaml(tmpdir):
    fake_chart_yaml_file = tmpdir.mkdir('template-dir').join('Chart.yaml')
    fake_chart_yaml_file.write(TEMPLATE_CHART_YAML)
    test_template = Template(name='test-template', description='Test template', local_version='1.0.0')
    test_template.update_chart_yaml(chart_yaml_path=fake_chart_yaml_file.strpath)

    with open(fake_chart_yaml_file.strpath, mode='r', encoding='utf-8') as chart_yaml_file:
        modified_chart_yaml = yaml.safe_load(chart_yaml_file)

    assert modified_chart_yaml['name'] == test_template.name
    assert modified_chart_yaml['description'] == test_template.description
    assert modified_chart_yaml['version'] == test_template.local_version
Ejemplo n.º 3
0
def test_render_from_existing_template(mocker, tmpdir):
    dlsctl_config_dir = tmpdir.mkdir('config')
    mocker.patch("util.config.Config.get_config_path", return_value=dlsctl_config_dir.strpath)

    packs_dir = dlsctl_config_dir.mkdir("packs")

    src_template_name = 'src-template'
    src_template_dir = packs_dir.mkdir(src_template_name)
    src_chart_yaml_file = src_template_dir.mkdir('charts').join('Chart.yaml')
    src_chart_yaml_file.write(TEMPLATE_CHART_YAML)

    test_template = Template(name='test-template', description='Test template', local_version='1.0.0')
    dest_template_dir = packs_dir.join(test_template.name)
    dest_chart_yaml_file = dest_template_dir.join('charts').join('Chart.yaml')

    mocker.patch.object(test_template, 'update_chart_yaml')
    test_template.render_from_existing_template(src_template_name=src_template_name)

    assert dest_template_dir.check()
    assert dest_chart_yaml_file.check()
Ejemplo n.º 4
0
CORRECT_CONF_FILE = f"model-zoo-address: {REPOSITORY_ADDRESS}\naccess-token: {ACCESS_TOKEN}"
INCORRECT_CONF_FILE = f"access-token: {ACCESS_TOKEN}"

REMOTE_TEMPLATE_NAME = "Remote template"
LOCAL_TEMPLATE_NAME = "Local template"
LOCAL_CHART_VERSION = "1.0.2"

TEMPLATE_CHART_YAML = '''
name: test_template
apiVersion: v1
description: Test template
version: 0.1.0
'''

REMOTE_TEMPLATE = Template(name=REMOTE_TEMPLATE_NAME, description=CHART_DESCRIPTION, remote_version=CHART_VERSION)
LOCAL_TEMPLATE_1 = Template(name=REMOTE_TEMPLATE_NAME, description=CHART_DESCRIPTION, local_version=LOCAL_CHART_VERSION)
LOCAL_TEMPLATE_2 = Template(name=LOCAL_TEMPLATE_NAME, description=CHART_DESCRIPTION, local_version=LOCAL_CHART_VERSION)

EXCEPTION_MESSAGE = "exception message"


def assert_template(template: Template, name: str = CHART_NAME, description: str = CHART_DESCRIPTION,
                    local_version: str = None,
                    remote_version: str = None):
    assert template.name == name
    assert template.description == description
    assert template.local_version == local_version
    assert template.remote_version == remote_version