Exemple #1
0
    def create(self):
        component = Component(
            name=self.slug,
            repo=None,
            version='master',
            repo_url=f"[email protected]:{self.github_owner}/component-{self.slug}.git",
        )
        if component.target_directory.exists():
            raise click.ClickException(
                f"Unable to add component {self.name}: {component.target_directory} already exists.")
        click.secho(f"Adding component {self.name}...", bold=True)
        component_template = __install_dir__ / 'component-template'
        cookiecutter(str(component_template.resolve()), no_input=True,
                     output_dir='dependencies',
                     extra_context=self.cookiecutter_args())

        repo = git.create_repository(component.target_directory)
        component = component._replace(repo=repo)
        git.add_remote(repo, 'origin', component.repo_url)
        index = repo.index
        index.add('*')
        index.add('.github')
        index.add('.*.yml')
        git.commit(repo, 'Initial commit', self.config)

        click.echo(' > Installing component')
        create_component_symlinks(self.config, component)

        targetfile = P('inventory', 'targets', 'cluster.yml')
        target = yaml_load(targetfile)
        target['classes'].append(f"components.{self.slug}")
        target['classes'].insert(0, f"defaults.{self.slug}")
        yaml_dump(target, targetfile)

        click.secho(f"Component {self.name} successfully added 🎉", bold=True)
def test_create_component_symlinks_fails(data: Config, tmp_path: Path):
    os.chdir(tmp_path)
    component = Component(
        name='my-component',
        repo=None,
        version='master',
        repo_url=None,
    )
    with pytest.raises(click.ClickException) as excinfo:
        dependency_mgmt.create_component_symlinks(data, component)
    assert component.name in str(excinfo)
Exemple #3
0
    def create(self):
        component = Component(
            name=self.slug,
            repo=None,
            version="master",
            repo_url=
            f"[email protected]:{self.github_owner}/component-{self.slug}.git",
        )
        if component.target_directory.exists():
            raise click.ClickException(
                f"Unable to add component {self.name}: {component.target_directory} already exists."
            )
        click.secho(f"Adding component {self.name}...", bold=True)
        component_template = __install_dir__ / "component-template"
        cookiecutter(
            str(component_template.resolve()),
            no_input=True,
            output_dir="dependencies",
            extra_context=self.cookiecutter_args(),
        )

        repo = git.create_repository(component.target_directory)
        component = component._replace(repo=repo)
        git.add_remote(repo, "origin", component.repo_url)
        index = repo.index
        index.add("*")
        index.add(".github")
        index.add(".gitignore")
        index.add(".*.yml")
        index.add(".editorconfig")
        git.commit(repo, "Initial commit", self.config)

        click.echo(" > Installing component")
        try:
            create_component_symlinks(self.config, component)

            targetfile = P("inventory", "targets", "cluster.yml")
            insert_into_inventory_targets_cluster(targetfile, self.slug)
            insert_into_jsonnetfile(P("jsonnetfile.json"),
                                    component.target_directory)
            # call fetch_jsonnet_libraries after updating jsonnetfile to
            # symlink new component into vendor/
            fetch_jsonnet_libraries()
        except FileNotFoundError:
            # TODO: This should maybe cleanup the "dependencies" subdirectory
            # (since we just created it).
            click.echo("Cannot find catalog files. Did you forget to run "
                       "'catalog compile' in the current directory?")
        else:
            click.secho(f"Component {self.name} successfully added 🎉",
                        bold=True)
def test_create_legacy_component_symlinks(capsys, data: Config, tmp_path):
    os.chdir(tmp_path)
    component = Component(
        name='my-component',
        repo=None,
        version='master',
        repo_url=None,
    )
    target_dir = Path('inventory/classes/components')
    target_dir.mkdir(parents=True, exist_ok=True)
    dependency_mgmt.create_component_symlinks(data, component)
    capture = capsys.readouterr()
    assert (target_dir / f"{component.name}.yml").is_symlink()
    assert 'Old-style component detected.' in capture.out
def test_create_component_symlinks(capsys, data: Config, tmp_path):
    os.chdir(tmp_path)
    component = Component(
        name='my-component',
        repo=None,
        version='master',
        repo_url=None,
    )
    class_dir = Path('dependencies') / component.name / 'class'
    class_dir.mkdir(parents=True, exist_ok=True)
    (class_dir / f"{component.name}.yml").touch()
    (class_dir / 'defaults.yml').touch()
    target_dir = Path('inventory/classes/components')
    target_dir.mkdir(parents=True, exist_ok=True)
    target_defaults = Path('inventory/classes/defaults')
    target_defaults.mkdir(parents=True, exist_ok=True)
    dependency_mgmt.create_component_symlinks(data, component)
    capture = capsys.readouterr()
    assert (target_dir / f"{component.name}.yml").is_symlink()
    assert (target_defaults / f"{component.name}.yml").is_symlink()
    assert capture.out == ''