mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Fix verbosity
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
parent
1c951df027
commit
caf6dfa23f
5 changed files with 68 additions and 45 deletions
54
.github/workflows/test-inventory-examples.yml
vendored
54
.github/workflows/test-inventory-examples.yml
vendored
|
|
@ -186,6 +186,48 @@ jobs:
|
|||
# Default value group for missing key exists for at least one host
|
||||
test $(echo "$out" | jq 'to_entries | map(select(.key | startswith("missing"))) | length') -ge 1
|
||||
|
||||
- name: Verbose logs - podman inventory (-vvvv) name_patterns and label_selectors
|
||||
run: |
|
||||
# Create an inventory that will: match only podman-inventory-test (not test2) by name_patterns,
|
||||
# then filter it out by label_selectors; the unmatched one will be filtered by name_patterns.
|
||||
cat > ci/tmpinv/podman_verbose.yml <<'EOF'
|
||||
plugin: containers.podman.podman_containers
|
||||
include_stopped: true
|
||||
name_patterns: ['podman-inventory-test']
|
||||
label_selectors:
|
||||
role: api
|
||||
EOF
|
||||
set -o pipefail
|
||||
ANSIBLE_INVENTORY_ENABLED=containers.podman.podman_containers,yaml,ini \
|
||||
ansible-inventory -i ci/tmpinv/podman_verbose.yml --list -vvvv 1>/tmp/podman_verbose.out 2>/tmp/podman_verbose.err || true
|
||||
echo "podman_verbose.err:"
|
||||
cat /tmp/podman_verbose.err
|
||||
echo "podman_verbose.out:"
|
||||
cat /tmp/podman_verbose.out
|
||||
# Expect messages from plugin
|
||||
grep -q "Filtered out podman-inventory-test2 by name_patterns option" /tmp/podman_verbose.out
|
||||
grep -q "Filtered out podman-inventory-test by label_selectors option" /tmp/podman_verbose.out
|
||||
|
||||
- name: Verbose logs - podman inventory (-vvvv) filters include path
|
||||
run: |
|
||||
# Match only the labeled container and then filter it via filters.include
|
||||
cat > ci/tmpinv/podman_verbose_filters.yml <<'EOF'
|
||||
plugin: containers.podman.podman_containers
|
||||
include_stopped: true
|
||||
name_patterns: ['podman-inventory-test2']
|
||||
filters:
|
||||
include:
|
||||
status: 'Exited*'
|
||||
EOF
|
||||
set -o pipefail
|
||||
ANSIBLE_INVENTORY_ENABLED=containers.podman.podman_containers,yaml,ini \
|
||||
ansible-inventory -i ci/tmpinv/podman_verbose_filters.yml --list -vvvv 1>/tmp/podman_verbose2.out 2>/tmp/podman_verbose2.err || true
|
||||
echo "podman_verbose2.err:"
|
||||
cat /tmp/podman_verbose2.err
|
||||
echo "podman_verbose2.out:"
|
||||
cat /tmp/podman_verbose2.out
|
||||
grep -q "Filtered out podman-inventory-test2 by filters option" /tmp/podman_verbose2.out
|
||||
|
||||
- name: Test strict=true fails on missing keyed key
|
||||
run: |
|
||||
set +e
|
||||
|
|
@ -207,6 +249,18 @@ jobs:
|
|||
echo "$out" | jq '.'
|
||||
echo "$out" | jq -e '. | to_entries | any(.value.hosts != null and (.value.hosts | length) > 0)'
|
||||
|
||||
- name: Verbose logs - buildah inventory (-vvvv) name_patterns filter path
|
||||
run: |
|
||||
cat > ci/tmpinv/buildah_verbose.yml <<'EOF'
|
||||
plugin: containers.podman.buildah_containers
|
||||
name_patterns: ['no-such-*']
|
||||
EOF
|
||||
set -o pipefail
|
||||
ANSIBLE_INVENTORY_ENABLED=containers.podman.buildah_containers,yaml,ini \
|
||||
ansible-inventory -i ci/tmpinv/buildah_verbose.yml --list -vvvv 1>/tmp/buildah_verbose.out 2>/tmp/buildah_verbose.err || true
|
||||
cat /tmp/buildah_verbose.err
|
||||
grep -q "Filtered out hello-buildah by name_patterns option" /tmp/buildah_verbose.err
|
||||
|
||||
- name: Test buildah inventory - empty selection with name_patterns
|
||||
run: |
|
||||
cat > ci/tmpinv/buildah_empty.yml <<'EOF'
|
||||
|
|
|
|||
|
|
@ -1,48 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
function setup_venv() {
|
||||
# Create and use a Python venv compatible with ansible-test (3.10/3.11/3.12)
|
||||
for pybin in python3.12 python3.11 python3.10 python3; do
|
||||
if command -v "$pybin" >/dev/null 2>&1; then
|
||||
PYBIN="$pybin"; break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${PYBIN:-}" ]]; then
|
||||
echo "No suitable python found (need 3.10/3.11/3.12)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VENV_DIR="${HOME}/.cache/ap-unit-venv-${PYBIN##python}"
|
||||
if [[ ! -d "$VENV_DIR" ]]; then
|
||||
"$PYBIN" -m venv "$VENV_DIR"
|
||||
fi
|
||||
source "$VENV_DIR/bin/activate"
|
||||
python -m pip install --upgrade pip >/dev/null
|
||||
# Install ansible-core which provides ansible-galaxy and ansible-test
|
||||
python -m pip install -U 'ansible-core>=2.16,<2.19' 'pytest>=7' 'pytest-xdist>=3' >/dev/null
|
||||
|
||||
export PATH="${VENV_DIR}/bin:${HOME}/.local/bin:${PATH}"
|
||||
}
|
||||
|
||||
# detect that we are in virtual environment
|
||||
if [[ -z "${VIRTUAL_ENV:-}" ]]; then
|
||||
echo "Setting up virtual environment"
|
||||
setup_venv
|
||||
else
|
||||
echo "Already in virtual environment, skipping setup"
|
||||
fi
|
||||
|
||||
mkdir -p /tmp/ansible-lint-installs
|
||||
mkdir -p /tmp/ansible-lint-collection
|
||||
rm -rf /tmp/ansible-lint-collection/*
|
||||
|
||||
ansible-galaxy collection build --output-path /tmp/ansible-lint-collection --force
|
||||
pushd /tmp/ansible-lint-collection/ >/dev/null
|
||||
pushd /tmp/ansible-lint-collection/
|
||||
ansible-galaxy collection install -vvv --force $(ls /tmp/ansible-lint-collection/) -p /tmp/ansible-lint-installs
|
||||
pushd /tmp/ansible-lint-installs/ansible_collections/containers/podman >/dev/null
|
||||
ansible-test units --python $(python -V | sed "s/Python //g" | awk -F"." {'print $1"."$2'}) -vvv
|
||||
popd >/dev/null
|
||||
popd >/dev/null
|
||||
pushd /tmp/ansible-lint-installs/ansible_collections/containers/podman
|
||||
ansible-test units --python 3.12 -vvv
|
||||
popd
|
||||
popd
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable, Constructable):
|
|||
|
||||
# 'buildah containers -a --format json' lists working containers
|
||||
args = [buildah_path, "containers", "-a", "--json"]
|
||||
output = ''
|
||||
output = ""
|
||||
containers = []
|
||||
try:
|
||||
output = subprocess.check_output(args, stderr=subprocess.STDOUT)
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable, Constructable):
|
|||
if include_stopped:
|
||||
args.insert(2, "-a")
|
||||
|
||||
output = ''
|
||||
output = ""
|
||||
containers = []
|
||||
try:
|
||||
output = subprocess.check_output(args, stderr=subprocess.STDOUT)
|
||||
|
|
|
|||
|
|
@ -355,7 +355,13 @@ def test_keyed_groups_leading_trailing_separators(mock_which):
|
|||
mod = InventoryModule()
|
||||
cfg = {
|
||||
"keyed_groups": [
|
||||
{"key": "labels.num", "prefix": "p", "separator": "-", "leading_separator": True, "trailing_separator": True}
|
||||
{
|
||||
"key": "labels.num",
|
||||
"prefix": "p",
|
||||
"separator": "-",
|
||||
"leading_separator": True,
|
||||
"trailing_separator": True,
|
||||
}
|
||||
]
|
||||
}
|
||||
with patch.object(mod, "_read_config_data", return_value=cfg):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue