Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rpluem-vf
Copy link
Contributor

After the rewrite of util.abs_path to use pathlib instead of os.path (000d200, c20dc08) the function now resolves symlinks in the given path whereas it did not do before.
This breaks setups where the molecule.yml file in a scenario is a symlink. E.g.

/common-files/molecule.yml
/roles/role1/molecule/default/molecule.yml -> /common-files/molecule.yml
/roles/role1/molecule/some-scenario/molecule.yml -> /common-files/molecule.yml
/roles/role2/molecule/default/molecule.yml -> /common-files/molecule.yml

Where a common molecule.yml can be used for multiple roles / scenarios and where changes to this file should reflect everywhere.

In this case molecule test executed in /roles/role1 returns Scenario 'default' not found. Exiting. or molecule test -s some-scenario executed in /roles/role1 returns Scenario 'some-scenario' not found. Exiting. (see

msg = f"Scenario '{self._scenario_name}' not found. Exiting."
)

Unfortunately pathlib is not a drop-in replacement for os.path (see https://docs.python.org/3/library/pathlib.html#comparison-to-the-os-and-os-path-modules).

Path.absolute() does not resolve symlink but does not reduce /../ segments in the path. Path.resolve() does reduce /../ path elements, but also resolves symlinks.

There is no method or combination of methods in the Path object that can deliver the same functionality as os.path.abspath(). Hence the code reverts back to using os.path.abspath(), but keeps accepting Path objects as input and returns the absolute path as such in these cases.

After the rewrite of util.abs_path to use pathlib instead of
os.path the function now resolves symlinks in the given path
whereas it did not do before. This breaks setups where
the molecule.yml file in a scenario is a symlink.
Unfortunately pathlib is not a drop-in replacement for os.path
(see
https://docs.python.org/3/library/pathlib.html#comparison-to-the-os-and-os-path-modules)
Path.absolute does not resolve symlink but does not reduce
/../ segments in the path. Path.resolve does reduce /../ path
elements, but also resolves symlinks.
There is no method or combination of methods in the Path object
that can deliver the same functionality as os.path.abspath.
Hence the code reverts back to using os.path.abspath, but keeps
accepting Path objects as input and returns the absolute path
as such in these cases.

Signed-off-by: Ruediger Pluem <[email protected]>
@rpluem-vf rpluem-vf requested a review from a team as a code owner December 12, 2024 20:10
@Qalthos Qalthos added the bug label Dec 12, 2024
This is unavoidable due to incompatibilities between abspath and what pathlib can support
@Qalthos Qalthos enabled auto-merge (squash) December 12, 2024 20:15
@Qalthos
Copy link
Collaborator

Qalthos commented Dec 12, 2024

Thanks for finding this!

@rpluem-vf
Copy link
Contributor Author

This was the fastest PR review and approval I ever faced. Thank you very much 😆

@Qalthos Qalthos disabled auto-merge December 12, 2024 20:25
@Qalthos Qalthos merged commit 9026471 into ansible:main Dec 12, 2024
21 checks passed
@rpluem-vf rpluem-vf deleted the resolve_regression branch December 12, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants