forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[module_utils.distro] Fall back to bundled (ansible#74229)
Change: - When a "distro" package exists in PYTHONPATH but isn't what we expect, fall back to our own vendored one and use it. This prevents a traceback if someone has some random thing that provides "distro" but isn't actually the "distro" library we need. Test Plan: - new tests Tickets: - Fixes ansible#74228 Signed-off-by: Rick Elrod <[email protected]> * nuke playbook test file Signed-off-by: Rick Elrod <[email protected]> * test fixes Signed-off-by: Rick Elrod <[email protected]>
- Loading branch information
Showing
5 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- module_utils distro - when a 'distro' package/module is in PYTHONPATH but isn't the real 'distro' package/module that we expect, gracefully fall back to our own bundled distro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
shippable/posix/group3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
- setup_remote_tmp_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
# Ensure that when a non-distro 'distro' package is in PYTHONPATH, we fallback | ||
# to our bundled one. | ||
new_pythonpath="$OUTPUT_DIR/pythonpath" | ||
mkdir -p "$new_pythonpath/distro" | ||
touch "$new_pythonpath/distro/__init__.py" | ||
|
||
export PYTHONPATH="$new_pythonpath:$PYTHONPATH" | ||
|
||
# Sanity test to make sure the above worked | ||
set +e | ||
distro_id_fail="$(python -c 'import distro; distro.id' 2>&1)" | ||
set -e | ||
grep -q "AttributeError:.*has no attribute 'id'" <<< "$distro_id_fail" | ||
|
||
# ansible.module_utils.common.sys_info imports distro, and itself gets imported | ||
# in DataLoader, so all we have to do to test the fallback is run `ansible`. | ||
ansirun="$(ansible -i ../../inventory -a "echo \$PYTHONPATH" localhost)" | ||
grep -q "$new_pythonpath" <<< "$ansirun" | ||
|
||
rm -rf "$new_pythonpath" |