8000 Automatically install current collection by ssbarnea · Pull Request #2998 · ansible/molecule · GitHub
[go: up one dir, main page]

Skip to content

Automatically install current collection - #2998

Closed
ssbarnea wants to merge 1 commit into
masterfrom
devel
Closed

ssbarnea wants to merge 1 commit into
masterfrom
devel

Conversation

@ssbarnea
Copy link
Copy Markdown
Member

If run inside a collection repository dependency step will first
build and install the current collection. This avoids failure to
run test scenarios unless user already installed the collection.

Fixes: #2997

@tadeboro tadeboro left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already stated on IRC, I have a hard time justifying this functionality in the Molecule. I would much rather document how to set up a collection development environment and then let molecule run ansible from within the collection where it can automatically use the content without installing it.

Comment thread src/molecule/dependency/base.py Outdated

:return: None
"""
if os.path.isfile("galaxy.yml"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is too naive to be effective. For example, we have our molecule scenarios stored under tests/integration/molecule, which means that we run Molecule from the tests/integration collection subfolder where galaxy.yml file will never be found.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will address this because molecule already looks for repository root location as is used in config file lookup, so we should be able to re-use repo-root path and avoid depending on cwd.

Comment thread src/molecule/dependency/base.py Outdated
dist = Path(self._config.scenario.ephemeral_directory) / "dist"
dist.mkdir(parents=True, exist_ok=True)
result = util.run_command(
f"ansible-galaxy collection build -v -f --output-path {dist}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this build command is too naive because it assumes that we are running molecule from the collection root. And there is another problem: users might need to some something else before they build the collection artifact. Because ansible-galaxy collection build command is really primitive, there is usually quite a few steps we need to perform before we get to building (or we risk packaging together things like virtual environments, coverage reports - and the are huge BTW, etc.).

If run inside a collection repository dependency step will first
build and install the current collection. This avoids failure to
run test scenarios unless user already installed the collection.

Fixes: #2997
@greg-hellings
Copy link
Copy Markdown
Contributor

This will address an issue I am currently encountering where trying to get Molecule to pick up an existing collection is difficult but also causes any other collections on my development machine to be overwritten by the ansibile-galaxy command.

@greg-hellings greg-hellings left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a wonderful improvement to my current development cycle.

:return: None
"""
workdir = util.find_vcs_root(self._config.project_directory)
collection_marker = os.path.join(workdir, "galaxy.yml")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if galaxy.yml doesn't live at the root of the current VCS?

@MarkusTeufelberger
Copy link
Copy Markdown
Contributor

I think there first needs to be some consensus (and documentation) on where the molecule folder should end up in a collection repository.

@ssbarnea
Copy link
Copy Markdown
Member Author

Closing in favour of #3077 which is reusing ansible-lint prerun code.

@ssbarnea ssbarnea closed this Mar 22, 2021
@ssbarnea
ssbarnea deleted the devel branch October 25, 2021 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Molecule should auto install tested collection during dependency step

4 participants

0