mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-19 17:34:52 +00:00
support testing/linting module_utils code
This does not directly affect network because network has its own solution for dealing with testing/linting module_utils code, but it gets network to feature/code parity with the template and other repos. Defines a shell function in utils.sh - lsr_setup_module_utils - that allows configuring a tox venv installed ansible to have the repo module_utils code in the default pythonpath for the venv, which allows testing and linting the module_utils code without having to otherwise munge or mock the pythonpath. Projects needing this functionality can set in `.travis/config.sh` the variable `RUN_PYTEST_SETUP_MODULE_UTILS` to setup module_utils/ for pytest, and `RUN_PYLINT_SETUP_MODULE_UTILS` to setup module_utils/ for pylint.
This commit is contained in:
parent
11a03f0ceb
commit
dec163940e
6 changed files with 90 additions and 0 deletions
41
tests/setup_module_utils.sh
Executable file
41
tests/setup_module_utils.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ -n "${DEBUG:-}" ] ; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [ ! -d "${1:-}" ] ; then
|
||||
echo Either ansible is not installed, or there is no ansible/module_utils
|
||||
echo in $1 - Skipping
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d "${2:-}" ] ; then
|
||||
echo Role has no module_utils - Skipping
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# we need absolute path for $2
|
||||
absmoddir=$( readlink -f "$2" )
|
||||
|
||||
# clean up old links to module_utils
|
||||
for item in "$1"/* ; do
|
||||
if lnitem=$( readlink "$item" ) && test -n "$lnitem" ; then
|
||||
case "$lnitem" in
|
||||
*"${2}"*) rm -f "$item" ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
# add new links to module_utils
|
||||
for item in "$absmoddir"/* ; do
|
||||
case "$item" in
|
||||
*__pycache__) continue;;
|
||||
*.pyc) continue;;
|
||||
esac
|
||||
bnitem=$( basename "$item" )
|
||||
ln -s "$item" "$1/$bnitem"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue