Debian Codegraph @

test/integration/targets/module_utils_distro/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux
4
5 # Ensure that when a non-distro 'distro' package is in PYTHONPATH, we fallback
6 # to our bundled one.
7 new_pythonpath="$OUTPUT_DIR/pythonpath"
8 mkdir -p "$new_pythonpath/distro"
9 touch "$new_pythonpath/distro/__init__.py"
10
11 export PYTHONPATH="$new_pythonpath:$PYTHONPATH"
12
13 # Sanity test to make sure the above worked
14 set +e
15 distro_id_fail="$(python -c 'import distro; distro.id' 2>&1)"
16 set -e
17 grep -q "AttributeError:.*has no attribute 'id'" <<< "$distro_id_fail"
18
19 # ansible.module_utils.common.sys_info imports distro, and itself gets imported
20 # in DataLoader, so all we have to do to test the fallback is run `ansible`.
21 ansirun="$(ansible -i ../../inventory -a "echo \$PYTHONPATH" localhost)"
22 grep -q "$new_pythonpath" <<< "$ansirun"
23
24 rm -rf "$new_pythonpath"