Compare commits
21
Commits
4dc221c17f
...
v1.10.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f4178b0da | ||
|
|
7b6183f869 | ||
|
|
0a9ea21f77 | ||
|
|
20bad9c95b | ||
|
|
b105c3c864 | ||
|
|
efc12897f5 | ||
|
|
a1779c0aba | ||
|
|
344adbfb7a | ||
|
|
c19c7abb20 | ||
|
|
fabbe7d977 | ||
|
|
43fcc382c6 | ||
|
|
4d3ed96ed4 | ||
|
|
1ab01b6e3a | ||
|
|
f77586dc60 | ||
|
|
fdb3f8c1df | ||
|
|
00c6cbeba4 | ||
|
|
5c8b8f5342 | ||
|
|
b49c953e8d | ||
|
|
5f2003e07f | ||
|
|
03ed536a14 | ||
|
|
00bac19705 |
No files matched your search
@@ -84,18 +84,24 @@ issue.
|
|||||||
too, until #166 removes that trigger. *Why:* a pull request runs only its selection, so
|
too, until #166 removes that trigger. *Why:* a pull request runs only its selection, so
|
||||||
drift in the other roles shows up here. *Held:* review.
|
drift in the other roles shows up here. *Held:* review.
|
||||||
- **A new commit cancels the pull request's running Molecule run, and the run step first removes
|
- **A new commit cancels the pull request's running Molecule run, and the run step first removes
|
||||||
the containers a cancelled run left.** Two runs never overlap only because the runner has a
|
the containers a cancelled run left.** The scenarios of one run overlap
|
||||||
single slot, and the scenarios' container names are fixed; raising the runner's capacity needs
|
(`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time), so no two scenarios may share a
|
||||||
per-run container names first (#166). *Why:* a cancelled run is killed before it can destroy
|
platform name. Two runs never overlap only because the runner has a single slot, and the
|
||||||
its instances, and two runs would collide on the same names. *Held:* review.
|
scenarios' container names are fixed; raising the runner's capacity needs per-run container
|
||||||
|
names first (#166). *Why:* a cancelled run is killed before it can remove its instances, and
|
||||||
|
two overlapping scenarios or runs would collide on the same names. *Held:* review; that no two
|
||||||
|
scenarios share a platform name is held by the test the `test_sequence` rule below names.
|
||||||
- **Molecule tests the pull request's pins, as Lint and Build do.** *Why:* the pull request that
|
- **Molecule tests the pull request's pins, as Lint and Build do.** *Why:* the pull request that
|
||||||
raises the ansible-core floor must be behaviour-tested on the new core before it automerges.
|
raises the ansible-core floor must be behaviour-tested on the new core before it automerges.
|
||||||
*Held:* aspirational until #225 runs Molecule from the `ci` image with the pin comparison
|
*Held:* aspirational until #225 runs Molecule from the `ci` image with the pin comparison
|
||||||
against `/opt/ci-pins.sha256`; today it runs from the runner's own venv.
|
against `/opt/ci-pins.sha256`; today it runs from the runner's own venv.
|
||||||
- **Every scenario sets `scenario.test_sequence` to molecule's default minus the leading
|
- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy`
|
||||||
`destroy`;** copy it into a new scenario. *Why:* the workflow clears stale containers first,
|
steps, and names its platforms literally in its `molecule.yml`;** copy it into a new scenario.
|
||||||
and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none
|
*Why:* the workflow clears stale containers first and removes each scenario's containers by
|
||||||
behind. *Held:* review.
|
those names as soon as it ends, which skips the driver's destroy wait, and the molecule state
|
||||||
|
lives in each scenario's own `ANSIBLE_HOME` in the job tree, so a killed run leaves none
|
||||||
|
behind. *Held:* control: `tests/scripts/test_run_molecule_scenarios.py` fails a `destroy` in a
|
||||||
|
sequence, and a platform name that is not unique or not matched by the stale-container filter.
|
||||||
- **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that
|
- **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that
|
||||||
must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or
|
must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or
|
||||||
`${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in
|
`${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
|
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
|
||||||
container:
|
container:
|
||||||
image: git.rkdr.net/mortis/ci:0.2.32@sha256:3282337dd3ccb20172e519d11fa996bfad2df09f3f5de14e2706d9d368af9923
|
image: git.rkdr.net/mortis/ci:0.2.33@sha256:2020686a819c5bdac6f773237479083ccc291a00351a6647c26a2dec5341de43
|
||||||
env:
|
env:
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the
|
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the
|
||||||
# release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
|
# release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
|
||||||
container:
|
container:
|
||||||
image: git.rkdr.net/mortis/ci:0.2.32@sha256:3282337dd3ccb20172e519d11fa996bfad2df09f3f5de14e2706d9d368af9923
|
image: git.rkdr.net/mortis/ci:0.2.33@sha256:2020686a819c5bdac6f773237479083ccc291a00351a6647c26a2dec5341de43
|
||||||
steps:
|
steps:
|
||||||
# The container has no Node, so JavaScript actions such as actions/checkout
|
# The container has no Node, so JavaScript actions such as actions/checkout
|
||||||
# cannot run; clone with git and the job token.
|
# cannot run; clone with git and the job token.
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ jobs:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||||
- name: ci
|
- name: ci
|
||||||
version: 0.2.33
|
version: 0.2.34
|
||||||
subpath: ""
|
subpath: ""
|
||||||
dockerfile: images/ci/Dockerfile
|
dockerfile: images/ci/Dockerfile
|
||||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ jobs:
|
|||||||
# The tag says which release, the digest is what is enforced (bump both together
|
# The tag says which release, the digest is what is enforced (bump both together
|
||||||
# when image.yml publishes a new version).
|
# when image.yml publishes a new version).
|
||||||
container:
|
container:
|
||||||
image: git.rkdr.net/mortis/ci:0.2.32@sha256:3282337dd3ccb20172e519d11fa996bfad2df09f3f5de14e2706d9d368af9923
|
image: git.rkdr.net/mortis/ci:0.2.33@sha256:2020686a819c5bdac6f773237479083ccc291a00351a6647c26a2dec5341de43
|
||||||
env:
|
env:
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||||
PRE_COMMIT_HOME: /opt/pre-commit
|
PRE_COMMIT_HOME: /opt/pre-commit
|
||||||
|
|||||||
@@ -44,10 +44,11 @@ permissions:
|
|||||||
|
|
||||||
# A pull request run is cancelled when a newer commit is pushed to the same pull request (the
|
# A pull request run is cancelled when a newer commit is pushed to the same pull request (the
|
||||||
# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the
|
# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the
|
||||||
# commit SHA. Scenarios use fixed container names on the runner's shared Docker daemon, so two
|
# commit SHA. The scenarios of one run overlap (scripts/run_molecule_scenarios.sh), which is safe
|
||||||
# runs must not overlap. The group no longer guarantees that (it is per pull request now): the
|
# because no two share a container name; but the names are fixed on the runner's shared Docker
|
||||||
# runner's single slot does. Raise the runner's capacity and this needs a lock or a shared
|
# daemon, so two runs must not overlap. The group no longer guarantees that (it is per pull
|
||||||
# group again.
|
# request now): the runner's single slot does. Raise the runner's capacity and this needs
|
||||||
|
# per-run container names first (#166), or a lock or a shared group again.
|
||||||
concurrency:
|
concurrency:
|
||||||
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
|
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
|
||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
@@ -127,10 +128,9 @@ jobs:
|
|||||||
echo "KAMINO_COLLECTIONS=$dest" >> "$GITHUB_ENV"
|
echo "KAMINO_COLLECTIONS=$dest" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
||||||
# explains the rules); a push to main and a manual dispatch run all of them.
|
# explains the rules); a push to main and a manual dispatch run all of them, a few at a time.
|
||||||
# molecule test destroys its instance on success and on failure; a cancelled run is killed
|
# scripts/run_molecule_scenarios.sh runs them and removes each scenario's containers as soon as
|
||||||
# before it can, so the step first removes what such a run left, since the next run may not
|
# it ends; a cancelled run is killed before it can, so the step first removes what one left.
|
||||||
# select the same scenarios.
|
|
||||||
- name: Run the scenarios
|
- name: Run the scenarios
|
||||||
working-directory: ac/ansible_collections/mortis/kamino
|
working-directory: ac/ansible_collections/mortis/kamino
|
||||||
env:
|
env:
|
||||||
@@ -148,12 +148,11 @@ jobs:
|
|||||||
# molecule calls ansible-config and ansible-playbook by name
|
# molecule calls ansible-config and ansible-playbook by name
|
||||||
export PATH="$MOLECULE_VENV/bin:$PATH"
|
export PATH="$MOLECULE_VENV/bin:$PATH"
|
||||||
# The collection under test first, then the pinned collections the roles use. molecule also
|
# The collection under test first, then the pinned collections the roles use. molecule also
|
||||||
# installs the collection under test into ANSIBLE_HOME; keep that inside the
|
# installs the collection under test into ANSIBLE_HOME, which the run script gives each
|
||||||
# job tree so no run resolves a copy another run left in the runner user's
|
# scenario inside the job tree, so no run resolves a copy another run left in the runner
|
||||||
# home (the version stays 0.1.0, so a stale copy would look current). The rm
|
# user's home (the version stays 0.1.0, so a stale copy would look current). The rm
|
||||||
# clears a copy left there by runs before this was set.
|
# clears a copy left there by runs before this was set.
|
||||||
ac_root="$(cd ../../.. && pwd)"
|
ac_root="$(cd ../../.. && pwd)"
|
||||||
export ANSIBLE_HOME="$ac_root/.ansible"
|
|
||||||
export ANSIBLE_COLLECTIONS_PATH="$ac_root:$KAMINO_COLLECTIONS"
|
export ANSIBLE_COLLECTIONS_PATH="$ac_root:$KAMINO_COLLECTIONS"
|
||||||
rm -rf "$HOME/.ansible/collections/ansible_collections/mortis"
|
rm -rf "$HOME/.ansible/collections/ansible_collections/mortis"
|
||||||
# The selector comes from the base branch, so a pull request cannot edit the rules it is
|
# The selector comes from the base branch, so a pull request cannot edit the rules it is
|
||||||
@@ -169,30 +168,4 @@ jobs:
|
|||||||
echo "::notice::no base copy of $sel; running this checkout's copy"
|
echo "::notice::no base copy of $sel; running this checkout's copy"
|
||||||
fi
|
fi
|
||||||
selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1
|
selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1
|
||||||
failed=""
|
scripts/run_molecule_scenarios.sh "$ac_root/molecule-runs" <<< "$selected"
|
||||||
ran=0
|
|
||||||
while IFS= read -r dir; do
|
|
||||||
[ -n "$dir" ] || continue
|
|
||||||
name="$(basename "$dir")"
|
|
||||||
case "$dir" in
|
|
||||||
extensions/*)
|
|
||||||
label="$name"
|
|
||||||
echo "::group::molecule test: $label"
|
|
||||||
molecule test -s "$name" </dev/null || failed="$failed $label"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
role="${dir#roles/}"
|
|
||||||
role="${role%%/*}"
|
|
||||||
label="$role/$name"
|
|
||||||
echo "::group::molecule test: $label"
|
|
||||||
(cd "roles/$role" && molecule test -s "$name" </dev/null) || failed="$failed $label"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
ran=$((ran + 1))
|
|
||||||
echo "::endgroup::"
|
|
||||||
done <<< "$selected"
|
|
||||||
echo "Scenarios run: $ran"
|
|
||||||
# A scenario that swallowed the rest of the list must not pass quietly.
|
|
||||||
want="$(grep -c . <<< "$selected" || true)"
|
|
||||||
test "$ran" -eq "$want" || { echo "::error::ran $ran of $want selected scenarios"; exit 1; }
|
|
||||||
test -z "$failed" || { echo "::error::Failed:$failed"; exit 1; }
|
|
||||||
@@ -68,7 +68,7 @@ repos:
|
|||||||
# --offline: no network audits, so a run needs no token and gives the same result everywhere.
|
# --offline: no network audits, so a run needs no token and gives the same result everywhere.
|
||||||
# Overriding args drops the hook's default, so --no-progress is repeated here.
|
# Overriding args drops the hook's default, so --no-progress is repeated here.
|
||||||
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
||||||
rev: 06a39750ec31860bb44f2acf67182c40016cd1e7 # frozen: v1.32.0
|
rev: 0eb9e4a60caf04df64b499ed1e8bef55f4440eae # frozen: v1.33.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: zizmor
|
- id: zizmor
|
||||||
args: [--no-progress, --offline]
|
args: [--no-progress, --offline]
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ mortis.kamino Release Notes
|
|||||||
|
|
||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
|
v1.10.1
|
||||||
|
=======
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- systemd_hardening - Look up the listed units with one ``systemctl show`` instead of listing every unit file. The listing can keep PID 1 busy for seconds on a host with slow storage, and the cost grows with the number of unit files. A unit is still skipped when it has no unit file. An instance name such as ``[email protected]`` is now matched when its template exists, and a template name such as ``[email protected]`` in the lists now makes the lookup fail instead of matching.
|
||||||
|
|
||||||
v1.10.0
|
v1.10.0
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
|
|||||||
Linux baseline, firewall, SSH, user management and, in later releases, Proxmox,
|
Linux baseline, firewall, SSH, user management and, in later releases, Proxmox,
|
||||||
Gitea and Gitea Actions runner roles.
|
Gitea and Gitea Actions runner roles.
|
||||||
|
|
||||||
Status: roles arrive in waves. Release 1.10.0 holds the `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `gitea`, `gitea_runner` and `traefik` call).
|
Status: roles arrive in waves. Release 1.10.1 holds the `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `gitea`, `gitea_runner` and `traefik` call).
|
||||||
|
|
||||||
## Consuming
|
## Consuming
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ name (FQCN) only, `mortis.kamino.<role>`:
|
|||||||
collections:
|
collections:
|
||||||
- name: https://git.rkdr.net/mortis/kamino.git
|
- name: https://git.rkdr.net/mortis/kamino.git
|
||||||
type: git
|
type: git
|
||||||
version: v1.10.0
|
version: v1.10.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Its dependencies (`community.general`, `ansible.posix`) are declared in `galaxy.yml`, so
|
Its dependencies (`community.general`, `ansible.posix`) are declared in `galaxy.yml`, so
|
||||||
|
|||||||
@@ -66,4 +66,4 @@ plugins:
|
|||||||
strategy: {}
|
strategy: {}
|
||||||
test: {}
|
test: {}
|
||||||
vars: {}
|
vars: {}
|
||||||
version: 1.10.0
|
version: 1.10.1
|
||||||
@@ -58,6 +58,19 @@ releases:
|
|||||||
- gitea-release-key-check.yml
|
- gitea-release-key-check.yml
|
||||||
- gitea-runner-role.yml
|
- gitea-runner-role.yml
|
||||||
release_date: '2026-11-22'
|
release_date: '2026-11-22'
|
||||||
|
1.10.1:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- systemd_hardening - Look up the listed units with one ``systemctl show`` instead
|
||||||
|
of listing every unit file. The listing can keep PID 1 busy for seconds on
|
||||||
|
a host with slow storage, and the cost grows with the number of unit files.
|
||||||
|
A unit is still skipped when it has no unit file. An instance name such as
|
||||||
|
``[email protected]`` is now matched when its template exists, and a template
|
||||||
|
name such as ``[email protected]`` in the lists now makes the lookup fail instead
|
||||||
|
of matching.
|
||||||
|
fragments:
|
||||||
|
- systemd-hardening-unit-lookup.yml
|
||||||
|
release_date: '2026-11-23'
|
||||||
1.2.0:
|
1.2.0:
|
||||||
changes:
|
changes:
|
||||||
minor_changes:
|
minor_changes:
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
bugfixes:
|
|
||||||
- >-
|
|
||||||
systemd_hardening - Look up the listed units with one ``systemctl show`` instead of listing every unit
|
|
||||||
file. The listing can keep PID 1 busy for seconds on a host with slow storage, and the cost grows with
|
|
||||||
the number of unit files. A unit is still skipped when it has no unit file. An instance name such as
|
|
||||||
``[email protected]`` is now matched when its template exists, and a template name such as
|
|
||||||
``[email protected]`` in the lists now makes the lookup fail instead of matching.
|
|
||||||
@@ -26,10 +26,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -41,4 +40,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -26,10 +26,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -41,4 +40,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
namespace: mortis
|
namespace: mortis
|
||||||
name: kamino
|
name: kamino
|
||||||
version: 1.10.0
|
version: 1.10.1
|
||||||
readme: README.md
|
readme: README.md
|
||||||
authors:
|
authors:
|
||||||
- Defame1297
|
- Defame1297
|
||||||
|
|||||||
@@ -26,10 +26,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -40,4 +39,3 @@ scenario:
|
|||||||
- check
|
- check
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -26,10 +26,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -41,4 +40,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -27,10 +27,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -42,4 +41,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -25,10 +25,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -40,4 +39,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Run by converge.yml in a child ansible-playbook process, because the mint guard
|
# Run by verify.yml in a child ansible-playbook process, because the mint guard
|
||||||
# reads the controller's environment (lookup env), which a play cannot change; the
|
# reads the controller's environment (lookup env), which a play cannot change; the
|
||||||
# child gets its environment from the task that starts it, so the result does not
|
# child gets its environment from the task that starts it, so the result does not
|
||||||
# depend on what the runner exports. With the CI variable set it fails at the CI
|
# depend on what the runner exports. With the CI variable set it fails at the CI
|
||||||
|
|||||||
@@ -1,118 +1,7 @@
|
|||||||
---
|
---
|
||||||
# Guard and no-op paths of the mint entry point (nothing is installed). Each
|
# Gitea is never installed in this scenario, so converge applies nothing; the mint guards and
|
||||||
# failure case wraps the include in block/rescue, so the play passes when the
|
# every check are in verify.yml, which runs once.
|
||||||
# guard fires, and fails when the include returns or fails with another message.
|
|
||||||
- name: Converge
|
- name: Converge
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks: []
|
||||||
- name: Mint without confirmation
|
|
||||||
block:
|
|
||||||
- name: Include the mint entry point with gitea_mint_confirm unset
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.gitea
|
|
||||||
tasks_from: mint
|
|
||||||
|
|
||||||
# Only reached when the include returned, so the guard did not fire. The message
|
|
||||||
# must not contain the guard's text, so the rescue below cannot mistake it for it.
|
|
||||||
- name: Fail because the include returned
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: The include returned without the confirm guard firing
|
|
||||||
rescue:
|
|
||||||
- name: The confirm guard fired, and nothing else failed first
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- "'mint is opt-in' in ansible_failed_result.msg"
|
|
||||||
- "'gitea_mint_confirm=true' in ansible_failed_result.msg"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Mint under each CI variable, run as a child process with only that one set
|
|
||||||
delegate_to: localhost
|
|
||||||
run_once: true
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- ansible-playbook
|
|
||||||
- -i
|
|
||||||
- localhost,
|
|
||||||
- "{{ playbook_dir }}/ci_guard.yml"
|
|
||||||
environment: "{{ {'GITHUB_ACTIONS': '', 'GITEA_ACTIONS': '', 'CI': '', 'ANSIBLE_NOCOLOR': '1'} | combine({item: 'true'}) }}"
|
|
||||||
loop:
|
|
||||||
- GITHUB_ACTIONS
|
|
||||||
- GITEA_ACTIONS
|
|
||||||
- CI
|
|
||||||
register: gitea_test_mint_ci
|
|
||||||
# The child is expected to fail (the CI guard fires). Its rc and output are asserted in the next task.
|
|
||||||
failed_when: false
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
# Ansible 2.19 prints task failures to stderr, so both streams are checked.
|
|
||||||
- name: The CI guard fired for every variable
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- item.rc != 0
|
|
||||||
- "'refuses to run under CI' in (item.stdout ~ item.stderr)"
|
|
||||||
- "'mint is opt-in' not in (item.stdout ~ item.stderr)"
|
|
||||||
quiet: true
|
|
||||||
loop: "{{ gitea_test_mint_ci.results }}"
|
|
||||||
loop_control:
|
|
||||||
label: "{{ item.item }}"
|
|
||||||
|
|
||||||
- name: Mint outside CI with the token already defined, run as a child process
|
|
||||||
delegate_to: localhost
|
|
||||||
run_once: true
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- ansible-playbook
|
|
||||||
- -i
|
|
||||||
- localhost,
|
|
||||||
- "{{ playbook_dir }}/ci_guard.yml"
|
|
||||||
- -e
|
|
||||||
- gitea_api_token=molecule-not-a-token
|
|
||||||
environment:
|
|
||||||
GITHUB_ACTIONS: ""
|
|
||||||
GITEA_ACTIONS: ""
|
|
||||||
CI: ""
|
|
||||||
ANSIBLE_NOCOLOR: "1"
|
|
||||||
register: gitea_test_mint_noop
|
|
||||||
# A child failure must not abort here; the next task asserts rc and output.
|
|
||||||
failed_when: false
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: The mint was a no-op that registered no token fact
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- gitea_test_mint_noop.rc == 0
|
|
||||||
- "'nothing to mint' in (gitea_test_mint_noop.stdout ~ gitea_test_mint_noop.stderr)"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
# An empty token counts as missing (configure.yml refuses it), so the mint must not report
|
|
||||||
# "nothing to mint". In check mode it creates nothing and registers no fact, and ends green
|
|
||||||
# (ci_guard.yml asserts that gitea_minted_api_token is not defined).
|
|
||||||
- name: Mint outside CI with an empty token in check mode, run as a child process
|
|
||||||
delegate_to: localhost
|
|
||||||
run_once: true
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- ansible-playbook
|
|
||||||
- -i
|
|
||||||
- localhost,
|
|
||||||
- "{{ playbook_dir }}/ci_guard.yml"
|
|
||||||
- --check
|
|
||||||
- -e
|
|
||||||
- gitea_api_token=
|
|
||||||
environment:
|
|
||||||
GITHUB_ACTIONS: ""
|
|
||||||
GITEA_ACTIONS: ""
|
|
||||||
CI: ""
|
|
||||||
ANSIBLE_NOCOLOR: "1"
|
|
||||||
register: gitea_test_mint_empty
|
|
||||||
# A child failure must not abort here; the next task asserts rc and output.
|
|
||||||
failed_when: false
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: An empty token was treated as missing and nothing was minted
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- gitea_test_mint_empty.rc == 0
|
|
||||||
- "'nothing to mint' not in (gitea_test_mint_empty.stdout ~ gitea_test_mint_empty.stderr)"
|
|
||||||
quiet: true
|
|
||||||
@@ -36,10 +36,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -51,4 +50,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,4 +1,123 @@
|
|||||||
---
|
---
|
||||||
|
# Guard and no-op paths of the mint entry point (nothing is installed). Each failure case
|
||||||
|
# wraps the include in block/rescue, or runs ci_guard.yml as a child process, so the play
|
||||||
|
# passes when the guard fires and fails when the include returns or fails with another message.
|
||||||
|
# First, so the assertions below also show the guards changed nothing.
|
||||||
|
- name: Verify the mint guards
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Mint without confirmation
|
||||||
|
block:
|
||||||
|
- name: Include the mint entry point with gitea_mint_confirm unset
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.gitea
|
||||||
|
tasks_from: mint
|
||||||
|
|
||||||
|
# Only reached when the include returned, so the guard did not fire. The message
|
||||||
|
# must not contain the guard's text, so the rescue below cannot mistake it for it.
|
||||||
|
- name: Fail because the include returned
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: The include returned without the confirm guard firing
|
||||||
|
rescue:
|
||||||
|
- name: The confirm guard fired, and nothing else failed first
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "'mint is opt-in' in ansible_failed_result.msg"
|
||||||
|
- "'gitea_mint_confirm=true' in ansible_failed_result.msg"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: Mint under each CI variable, run as a child process with only that one set
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: true
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- ansible-playbook
|
||||||
|
- -i
|
||||||
|
- localhost,
|
||||||
|
- "{{ playbook_dir }}/ci_guard.yml"
|
||||||
|
environment: "{{ {'GITHUB_ACTIONS': '', 'GITEA_ACTIONS': '', 'CI': '', 'ANSIBLE_NOCOLOR': '1'} | combine({item: 'true'}) }}"
|
||||||
|
loop:
|
||||||
|
- GITHUB_ACTIONS
|
||||||
|
- GITEA_ACTIONS
|
||||||
|
- CI
|
||||||
|
register: gitea_test_mint_ci
|
||||||
|
# The child is expected to fail (the CI guard fires). Its rc and output are asserted in the next task.
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
# Ansible 2.19 prints task failures to stderr, so both streams are checked.
|
||||||
|
- name: The CI guard fired for every variable
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- item.rc != 0
|
||||||
|
- "'refuses to run under CI' in (item.stdout ~ item.stderr)"
|
||||||
|
- "'mint is opt-in' not in (item.stdout ~ item.stderr)"
|
||||||
|
quiet: true
|
||||||
|
loop: "{{ gitea_test_mint_ci.results }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.item }}"
|
||||||
|
|
||||||
|
- name: Mint outside CI with the token already defined, run as a child process
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: true
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- ansible-playbook
|
||||||
|
- -i
|
||||||
|
- localhost,
|
||||||
|
- "{{ playbook_dir }}/ci_guard.yml"
|
||||||
|
- -e
|
||||||
|
- gitea_api_token=molecule-not-a-token
|
||||||
|
environment:
|
||||||
|
GITHUB_ACTIONS: ""
|
||||||
|
GITEA_ACTIONS: ""
|
||||||
|
CI: ""
|
||||||
|
ANSIBLE_NOCOLOR: "1"
|
||||||
|
register: gitea_test_mint_noop
|
||||||
|
# A child failure must not abort here; the next task asserts rc and output.
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: The mint was a no-op that registered no token fact
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- gitea_test_mint_noop.rc == 0
|
||||||
|
- "'nothing to mint' in (gitea_test_mint_noop.stdout ~ gitea_test_mint_noop.stderr)"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# An empty token counts as missing (configure.yml refuses it), so the mint must not report
|
||||||
|
# "nothing to mint". In check mode it creates nothing and registers no fact, and ends green
|
||||||
|
# (ci_guard.yml asserts that gitea_minted_api_token is not defined).
|
||||||
|
- name: Mint outside CI with an empty token in check mode, run as a child process
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: true
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- ansible-playbook
|
||||||
|
- -i
|
||||||
|
- localhost,
|
||||||
|
- "{{ playbook_dir }}/ci_guard.yml"
|
||||||
|
- --check
|
||||||
|
- -e
|
||||||
|
- gitea_api_token=
|
||||||
|
environment:
|
||||||
|
GITHUB_ACTIONS: ""
|
||||||
|
GITEA_ACTIONS: ""
|
||||||
|
CI: ""
|
||||||
|
ANSIBLE_NOCOLOR: "1"
|
||||||
|
register: gitea_test_mint_empty
|
||||||
|
# A child failure must not abort here; the next task asserts rc and output.
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: An empty token was treated as missing and nothing was minted
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- gitea_test_mint_empty.rc == 0
|
||||||
|
- "'nothing to mint' not in (gitea_test_mint_empty.stdout ~ gitea_test_mint_empty.stderr)"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
- name: Verify
|
- name: Verify
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|||||||
@@ -44,10 +44,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -59,4 +58,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -25,10 +25,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -40,4 +39,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -8,28 +8,9 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: mortis.kamino.sshd
|
- role: mortis.kamino.sshd
|
||||||
|
|
||||||
# A play without sshd_profile: the role must refuse it and leave the config
|
|
||||||
# converged above untouched. The block proves the refusal (not its wording); the play
|
|
||||||
# still passes, so the idempotence run stays clean.
|
|
||||||
- name: Converge the role without a profile
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Missing sshd_profile is rejected
|
|
||||||
block:
|
|
||||||
- name: Apply the role without sshd_profile
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
- name: Fail when the missing profile was accepted
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted a run without sshd_profile
|
|
||||||
rescue:
|
|
||||||
- name: The role refused the run
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: Rejected as expected
|
|
||||||
|
|
||||||
# The plays below only load the role's defaults and run validate.yml, which changes nothing
|
# The plays below only load the role's defaults and run validate.yml, which changes nothing
|
||||||
# on the container. They cover the profiles the converge above cannot run and the guards.
|
# on the container. They cover the profiles the converge above cannot run and the values
|
||||||
|
# the guards accept.
|
||||||
- name: Every profile passes validation and keeps its root login policy
|
- name: Every profile passes validation and keeps its root login policy
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -83,29 +64,6 @@
|
|||||||
- sshd_settings_effective.PubkeyAuthentication == "yes"
|
- sshd_settings_effective.PubkeyAuthentication == "yes"
|
||||||
quiet: true
|
quiet: true
|
||||||
|
|
||||||
- name: The lock-out guard refuses a lock-out
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: ubuntu_lxc
|
|
||||||
sshd_settings:
|
|
||||||
PubkeyAuthentication: "no"
|
|
||||||
tasks:
|
|
||||||
- name: Apply a lock-out configuration
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the lock-out was accepted
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted a lock-out configuration
|
|
||||||
rescue:
|
|
||||||
- name: The lock-out guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'lock you out' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: The Proxmox guard accepts every value that allows root key login
|
- name: The Proxmox guard accepts every value that allows root key login
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -119,116 +77,3 @@
|
|||||||
sshd_settings:
|
sshd_settings:
|
||||||
PermitRootLogin: "{{ item }}"
|
PermitRootLogin: "{{ item }}"
|
||||||
loop: [prohibit-password, without-password, "yes", Prohibit-Password]
|
loop: [prohibit-password, without-password, "yes", Prohibit-Password]
|
||||||
|
|
||||||
- name: The Proxmox guard refuses a pve profile without root login
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: pve
|
|
||||||
sshd_settings:
|
|
||||||
PermitRootLogin: "no"
|
|
||||||
tasks:
|
|
||||||
- name: Apply a pve configuration without root login
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the Proxmox guard was bypassed
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted a pve profile without root login
|
|
||||||
rescue:
|
|
||||||
- name: The Proxmox guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'needs root public-key login' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: The Proxmox guard refuses forced-commands-only
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: pve
|
|
||||||
sshd_settings:
|
|
||||||
PermitRootLogin: forced-commands-only
|
|
||||||
tasks:
|
|
||||||
- name: Apply a pve configuration with forced commands only
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the Proxmox guard was bypassed
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted forced-commands-only for the pve profile
|
|
||||||
rescue:
|
|
||||||
- name: The Proxmox guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'needs root public-key login' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: The Proxmox guard refuses a pve profile without RSA keys
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: pve
|
|
||||||
sshd_settings:
|
|
||||||
PubkeyAcceptedAlgorithms: "ssh-ed25519"
|
|
||||||
tasks:
|
|
||||||
- name: Apply a pve configuration without RSA keys
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the RSA guard was bypassed
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted a pve profile without RSA keys
|
|
||||||
rescue:
|
|
||||||
- name: The RSA guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'must both include rsa-sha2-512' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: The guard refuses SHA-1 ssh-rsa
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: pve
|
|
||||||
sshd_settings:
|
|
||||||
HostKeyAlgorithms: "ssh-ed25519, rsa-sha2-512, ssh-rsa"
|
|
||||||
tasks:
|
|
||||||
- name: Apply a configuration that allows ssh-rsa
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the ssh-rsa guard was bypassed
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted ssh-rsa
|
|
||||||
rescue:
|
|
||||||
- name: The ssh-rsa guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'must not list ssh-rsa' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: An unknown profile is refused
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
sshd_profile: not_a_profile
|
|
||||||
tasks:
|
|
||||||
- name: Apply the role with an unknown profile
|
|
||||||
block:
|
|
||||||
- name: Include the validation
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.sshd
|
|
||||||
tasks_from: validate.yml
|
|
||||||
- name: Fail when the unknown profile was accepted
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the sshd role accepted an unknown profile
|
|
||||||
rescue:
|
|
||||||
- name: The profile check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'is invalid' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
@@ -26,10 +26,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -41,4 +40,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,4 +1,162 @@
|
|||||||
---
|
---
|
||||||
|
# The refusal cases: here, not in converge.yml, because idempotence reruns converge. Each
|
||||||
|
# fails in validate.yml; they run first, so the assertions below also show the host unchanged.
|
||||||
|
|
||||||
|
# A play without sshd_profile: the role must refuse it. The block proves the refusal
|
||||||
|
# (not its wording).
|
||||||
|
- name: The role refuses a run without a profile
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Missing sshd_profile is rejected
|
||||||
|
block:
|
||||||
|
- name: Apply the role without sshd_profile
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
- name: Fail when the missing profile was accepted
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted a run without sshd_profile
|
||||||
|
rescue:
|
||||||
|
- name: The role refused the run
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: Rejected as expected
|
||||||
|
|
||||||
|
- name: The lock-out guard refuses a lock-out
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: ubuntu_lxc
|
||||||
|
sshd_settings:
|
||||||
|
PubkeyAuthentication: "no"
|
||||||
|
tasks:
|
||||||
|
- name: Apply a lock-out configuration
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the lock-out was accepted
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted a lock-out configuration
|
||||||
|
rescue:
|
||||||
|
- name: The lock-out guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'lock you out' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: The Proxmox guard refuses a pve profile without root login
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: pve
|
||||||
|
sshd_settings:
|
||||||
|
PermitRootLogin: "no"
|
||||||
|
tasks:
|
||||||
|
- name: Apply a pve configuration without root login
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the Proxmox guard was bypassed
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted a pve profile without root login
|
||||||
|
rescue:
|
||||||
|
- name: The Proxmox guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'needs root public-key login' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: The Proxmox guard refuses forced-commands-only
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: pve
|
||||||
|
sshd_settings:
|
||||||
|
PermitRootLogin: forced-commands-only
|
||||||
|
tasks:
|
||||||
|
- name: Apply a pve configuration with forced commands only
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the Proxmox guard was bypassed
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted forced-commands-only for the pve profile
|
||||||
|
rescue:
|
||||||
|
- name: The Proxmox guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'needs root public-key login' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: The Proxmox guard refuses a pve profile without RSA keys
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: pve
|
||||||
|
sshd_settings:
|
||||||
|
PubkeyAcceptedAlgorithms: "ssh-ed25519"
|
||||||
|
tasks:
|
||||||
|
- name: Apply a pve configuration without RSA keys
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the RSA guard was bypassed
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted a pve profile without RSA keys
|
||||||
|
rescue:
|
||||||
|
- name: The RSA guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'must both include rsa-sha2-512' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: The guard refuses SHA-1 ssh-rsa
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: pve
|
||||||
|
sshd_settings:
|
||||||
|
HostKeyAlgorithms: "ssh-ed25519, rsa-sha2-512, ssh-rsa"
|
||||||
|
tasks:
|
||||||
|
- name: Apply a configuration that allows ssh-rsa
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the ssh-rsa guard was bypassed
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted ssh-rsa
|
||||||
|
rescue:
|
||||||
|
- name: The ssh-rsa guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'must not list ssh-rsa' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: An unknown profile is refused
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sshd_profile: not_a_profile
|
||||||
|
tasks:
|
||||||
|
- name: Apply the role with an unknown profile
|
||||||
|
block:
|
||||||
|
- name: Include the validation
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.sshd
|
||||||
|
tasks_from: validate.yml
|
||||||
|
- name: Fail when the unknown profile was accepted
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the sshd role accepted an unknown profile
|
||||||
|
rescue:
|
||||||
|
- name: The profile check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'is invalid' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
# Lock-out signals only: the drop-in is in place, the daemon accepts the config and
|
# Lock-out signals only: the drop-in is in place, the daemon accepts the config and
|
||||||
# runs, and the effective settings keep key authentication on and passwords and
|
# runs, and the effective settings keep key authentication on and passwords and
|
||||||
# root login off. The remaining hardening values restate the role's own defaults
|
# root login off. The remaining hardening values restate the role's own defaults
|
||||||
|
|||||||
@@ -32,10 +32,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -47,4 +46,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -25,10 +25,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -40,4 +39,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
# Role variables come from the inventory group_vars in molecule.yml, so every play
|
# Role variables come from the inventory group_vars in molecule.yml, so the idempotence step
|
||||||
# renders identical configuration (idempotence).
|
# reruns converge with identical configuration; verify's plays override only what they test.
|
||||||
# The base ufw play comes first: traefik passes its rules through the mortis.kamino.ufw
|
# The base ufw play comes first: traefik passes its rules through the mortis.kamino.ufw
|
||||||
# service_rules entry point, which needs ufw installed and active. ufw_rules comes from the
|
# service_rules entry point, which needs ufw installed and active. ufw_rules comes from the
|
||||||
# same group_vars (the SSH allow rule the lock-out guard requires).
|
# same group_vars (the SSH allow rule the lock-out guard requires).
|
||||||
@@ -10,48 +10,3 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: mortis.kamino.ufw
|
- role: mortis.kamino.ufw
|
||||||
- role: mortis.kamino.traefik
|
- role: mortis.kamino.traefik
|
||||||
|
|
||||||
- name: Refuse an enabled dashboard without basicAuth users
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Run the role with the dashboard on and no users
|
|
||||||
block:
|
|
||||||
- name: Include traefik
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.traefik
|
|
||||||
vars:
|
|
||||||
traefik_dashboard_enabled: true
|
|
||||||
traefik_dashboard_basicauth_users: []
|
|
||||||
- name: Unreachable when the guard works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: traefik accepted an enabled dashboard without users
|
|
||||||
rescue:
|
|
||||||
- name: The dashboard guard, not something else, stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'unauthenticated Traefik dashboard' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Refuse a dashboard-auth middleware collision
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Run the role with a colliding middleware
|
|
||||||
block:
|
|
||||||
- name: Include traefik
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.traefik
|
|
||||||
vars:
|
|
||||||
traefik_dashboard_basicauth_users:
|
|
||||||
- "admin:$apr1$x$y"
|
|
||||||
traefik_dynamic_middlewares:
|
|
||||||
dashboard-auth:
|
|
||||||
basicAuth: {users: []}
|
|
||||||
- name: Unreachable when the check works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: traefik accepted a colliding dashboard-auth middleware
|
|
||||||
rescue:
|
|
||||||
- name: The collision check, not something else, stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'collides with the middleware' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
@@ -23,9 +23,9 @@ platforms:
|
|||||||
- apparmor=unconfined
|
- apparmor=unconfined
|
||||||
provisioner:
|
provisioner:
|
||||||
name: ansible
|
name: ansible
|
||||||
# One source for every play in converge.yml. The role renders traefik.yml before
|
# One source for every play in converge.yml and verify.yml. The role renders traefik.yml before
|
||||||
# its dashboard guard and its dashboard-auth collision check, so a play that included it with other
|
# its dashboard-auth collision check, so that guard play with other values would change it (and
|
||||||
# values would re-render the file and break the idempotence step.
|
# restart Traefik) before verify's assertions; converge's values must also stay fixed for idempotence.
|
||||||
inventory:
|
inventory:
|
||||||
group_vars:
|
group_vars:
|
||||||
all:
|
all:
|
||||||
@@ -46,10 +46,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -61,4 +60,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,4 +1,53 @@
|
|||||||
---
|
---
|
||||||
|
# The input guards. Both fail after the role's prereqs (packages already present), and the
|
||||||
|
# collision case re-renders traefik.yml from the same group_vars with the dashboard still off,
|
||||||
|
# so neither changes the host. They run first, so every assertion below also shows that; the
|
||||||
|
# remove path stays last, since after it the role would install Traefik again.
|
||||||
|
- name: Refuse an enabled dashboard without basicAuth users
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Run the role with the dashboard on and no users
|
||||||
|
block:
|
||||||
|
- name: Include traefik
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.traefik
|
||||||
|
vars:
|
||||||
|
traefik_dashboard_enabled: true
|
||||||
|
traefik_dashboard_basicauth_users: []
|
||||||
|
- name: Unreachable when the guard works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: traefik accepted an enabled dashboard without users
|
||||||
|
rescue:
|
||||||
|
- name: The dashboard guard, not something else, stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'unauthenticated Traefik dashboard' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: Refuse a dashboard-auth middleware collision
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Run the role with a colliding middleware
|
||||||
|
block:
|
||||||
|
- name: Include traefik
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.traefik
|
||||||
|
vars:
|
||||||
|
traefik_dashboard_basicauth_users:
|
||||||
|
- "admin:$apr1$x$y"
|
||||||
|
traefik_dynamic_middlewares:
|
||||||
|
dashboard-auth:
|
||||||
|
basicAuth: {users: []}
|
||||||
|
- name: Unreachable when the check works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: traefik accepted a colliding dashboard-auth middleware
|
||||||
|
rescue:
|
||||||
|
- name: The collision check, not something else, stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'collides with the middleware' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
- name: Verify
|
- name: Verify
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|||||||
@@ -1,117 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Lock-out guard: default-deny without an SSH allow rule must be refused before
|
# Only runs that apply the role; the refusal cases are in verify.yml.
|
||||||
# any policy is touched.
|
|
||||||
- name: Refuse default-deny without an SSH allow rule
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Run the role with only a non-SSH rule
|
|
||||||
block:
|
|
||||||
- name: Include ufw
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
vars:
|
|
||||||
ufw_rules:
|
|
||||||
- {rule: allow, port: 8080, proto: tcp}
|
|
||||||
- name: Unreachable when the guard works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: ufw ran without an SSH allow rule
|
|
||||||
rescue:
|
|
||||||
- name: The guard, not something else, stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'would lock this host out' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
# A delete entry removes the SSH rule it names, so it must not satisfy the guard.
|
|
||||||
- name: Run the role with an SSH rule that is only deleted
|
|
||||||
block:
|
|
||||||
- name: Include ufw
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
vars:
|
|
||||||
ufw_rules:
|
|
||||||
- {rule: allow, port: 8080, proto: tcp}
|
|
||||||
- {rule: allow, port: 22, proto: tcp, delete: true}
|
|
||||||
- name: Unreachable when the guard ignores delete entries
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: ufw counted a deleted SSH rule as the SSH allow rule
|
|
||||||
rescue:
|
|
||||||
- name: The guard stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'would lock this host out' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
# The same rule added and deleted: the delete would win (deletes run last) while the
|
|
||||||
# guard counted the add. The comment, the port's type and the written default
|
|
||||||
# direction and source do not make them different.
|
|
||||||
- name: Run the role with a rule that is both added and deleted
|
|
||||||
block:
|
|
||||||
- name: Include ufw
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
vars:
|
|
||||||
ufw_rules:
|
|
||||||
- {rule: allow, port: "22", proto: tcp, direction: in, from: any, comment: ssh}
|
|
||||||
- {rule: allow, port: 22, proto: tcp, delete: true}
|
|
||||||
- name: Unreachable when the conflict check works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: ufw accepted a rule that is both added and deleted
|
|
||||||
rescue:
|
|
||||||
- name: The conflict check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'both added and deleted' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
# Stray variable guard: variables named like <role>_ufw_rules must fail the play
|
|
||||||
# before anything changes, naming the variable. The vars sit on the include only, so they
|
|
||||||
# do not reach the plays below (the base ufw_rules and ufw_before_rules never match).
|
|
||||||
- name: Refuse stray variables named like the old *_ufw_rules
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: A stray *_ufw_rules variable
|
|
||||||
block:
|
|
||||||
- name: Include ufw with a stray rules variable
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
vars:
|
|
||||||
ufw_rules:
|
|
||||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
|
||||||
stray_ufw_rules: # noqa: var-naming[no-role-prefix]
|
|
||||||
- {rule: allow, port: 7999, proto: tcp, comment: stray}
|
|
||||||
- name: Unreachable when the stray variable guard works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: a stray *_ufw_rules variable was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The stray guard, not something else, stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- "'stray_ufw_rules' in ansible_failed_result.msg | default('')"
|
|
||||||
- "'stray_ufw_before_rules' not in ansible_failed_result.msg | default('')"
|
|
||||||
- "'service_rules' in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: A stray *_ufw_before_rules variable
|
|
||||||
block:
|
|
||||||
- name: Include ufw with a stray before-rules variable
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
vars:
|
|
||||||
ufw_rules:
|
|
||||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
|
||||||
stray_ufw_before_rules: # noqa: var-naming[no-role-prefix]
|
|
||||||
- {proto: udp, port: 7998, comment: stray}
|
|
||||||
- name: Unreachable when the stray variable guard works
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: a stray *_ufw_before_rules variable was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The stray guard, not something else, stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- "'stray_ufw_before_rules' in ansible_failed_result.msg | default('')"
|
|
||||||
- "'stray_ufw_rules' not in ansible_failed_result.msg | default('')"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Converge with an SSH rule and service rules
|
- name: Converge with an SSH rule and service rules
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
@@ -218,171 +106,6 @@
|
|||||||
ufw_service_rules:
|
ufw_service_rules:
|
||||||
- {rule: allow, port: 7602, proto: tcp, comment: desired}
|
- {rule: allow, port: 7602, proto: tcp, comment: desired}
|
||||||
|
|
||||||
# Inputs the entry point must refuse, each before it changes anything. Every block
|
|
||||||
# proves the refusal and its message; the play still passes, so the idempotence run
|
|
||||||
# stays clean and verify.yml proves no rule was left behind.
|
|
||||||
- name: Refuse invalid service rule inputs
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
vars:
|
|
||||||
# A failed looped task reports "One or more items failed" in msg and the item
|
|
||||||
# messages in results; an unlooped one has the message in msg.
|
|
||||||
ufw_converge_failure: >-
|
|
||||||
{{ ansible_failed_result.msg | default('') }}
|
|
||||||
{{ ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ') }}
|
|
||||||
tasks:
|
|
||||||
- name: An owner name outside the allowed characters
|
|
||||||
block:
|
|
||||||
- name: Include with an invalid owner name
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: Bad-Name
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 8101, proto: tcp}
|
|
||||||
- name: Unreachable when the owner name is checked
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: an invalid owner name was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The owner check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'ufw_service_name must be a string matching' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: The reserved owner base
|
|
||||||
block:
|
|
||||||
- name: Include as base
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: base
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 8102, proto: tcp}
|
|
||||||
- name: Unreachable when base is reserved
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: the reserved owner base was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The reserved name stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'reserved for the base play' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: A single quote in a comment
|
|
||||||
block:
|
|
||||||
- name: Include with a quote in the comment
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_f
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 8103, proto: tcp, comment: "it's"}
|
|
||||||
- name: Unreachable when comments are checked
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: a quote in a comment was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The comment check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'single quote' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: A rule another owner already holds
|
|
||||||
block:
|
|
||||||
- name: Include with the spec of a svc_a rule
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_f
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 8001, proto: tcp, comment: other text}
|
|
||||||
- name: Unreachable when collisions are checked
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: a rule owned by svc_a was accepted for svc_f
|
|
||||||
rescue:
|
|
||||||
- name: The collision check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'already owned by another tag' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: A rule that would retag the SSH rule
|
|
||||||
block:
|
|
||||||
- name: Include with an allow rule for the SSH port
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_f
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 22, proto: tcp}
|
|
||||||
- name: Unreachable when the SSH port is protected
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: a service rule for the SSH port was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The SSH check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'allows the SSH port' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: An unknown rule key
|
|
||||||
block:
|
|
||||||
- name: Include with a to_port key
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_f
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, to_port: 8104, proto: tcp}
|
|
||||||
- name: Unreachable when keys are checked
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: an unknown rule key was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The key check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'has an unknown key' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: An interface without a direction
|
|
||||||
block:
|
|
||||||
- name: Include with an interface and no direction
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_f
|
|
||||||
ufw_service_rules:
|
|
||||||
- {rule: allow, port: 8105, proto: tcp, interface: eth0}
|
|
||||||
- name: Unreachable when the direction is required
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: an interface without a direction was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The direction check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'interface without direction' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Purging with an empty rule list
|
|
||||||
block:
|
|
||||||
- name: Include with an empty list and ufw_purge_stale
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: service_rules
|
|
||||||
vars:
|
|
||||||
ufw_service_name: svc_a
|
|
||||||
ufw_purge_stale: true
|
|
||||||
ufw_service_rules: []
|
|
||||||
- name: Unreachable when an empty list is refused
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: an empty list with ufw_purge_stale was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The empty list stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'use ufw_service_state: absent' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
# The orphan_rules entry point. prepare.yml stored two rules of svc_o1, a rule of
|
# The orphan_rules entry point. prepare.yml stored two rules of svc_o1, a rule of
|
||||||
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
|
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
|
||||||
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
|
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
|
||||||
@@ -403,9 +126,6 @@
|
|||||||
- svc_h
|
- svc_h
|
||||||
- svc_m
|
- svc_m
|
||||||
- svc_p
|
- svc_p
|
||||||
ufw_converge_failure: >-
|
|
||||||
{{ ansible_failed_result.msg | default('') }}
|
|
||||||
{{ ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ') }}
|
|
||||||
tasks:
|
tasks:
|
||||||
# The marker is written after the purge, so the expected counts are absolute on both
|
# The marker is written after the purge, so the expected counts are absolute on both
|
||||||
# passes: svc_o1 holds 2 rules before the purge and 0 once the marker exists.
|
# passes: svc_o1 holds 2 rules before the purge and 0 once the marker exists.
|
||||||
@@ -442,27 +162,6 @@
|
|||||||
- name: Nothing was deleted with an empty list
|
- name: Nothing was deleted with an empty list
|
||||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||||
|
|
||||||
- name: An invalid managed owner
|
|
||||||
block:
|
|
||||||
- name: Include with an owner name outside the allowed characters
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: mortis.kamino.ufw
|
|
||||||
tasks_from: orphan_rules
|
|
||||||
vars:
|
|
||||||
ufw_managed_owners: [svc_a, Bad-Name]
|
|
||||||
ufw_purge_orphans: true
|
|
||||||
- name: Unreachable when the owners are checked
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: an invalid managed owner was accepted
|
|
||||||
rescue:
|
|
||||||
- name: The owner check stopped the play
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: "'ufw_managed_owners must be a list of strings matching' in ufw_converge_failure"
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Nothing was deleted after the invalid owner
|
|
||||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
|
||||||
|
|
||||||
- name: Report the orphans only
|
- name: Report the orphans only
|
||||||
ansible.builtin.include_role:
|
ansible.builtin.include_role:
|
||||||
name: mortis.kamino.ufw
|
name: mortis.kamino.ufw
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -40,4 +39,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
# Included by converge.yml after each orphan_rules case. The counts are absolute: svc_o1
|
# Included by converge.yml and verify.yml after each orphan_rules case. The counts are
|
||||||
# holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the purge, 0 after),
|
# absolute: svc_o1 holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the
|
||||||
# and the tagged total is 20 plus those. The 20: svc_a 2, svc_b 2, svc_c 1, svc_e 2, svc_g 1,
|
# purge, 0 after), and the tagged total is 20 plus those. The 20: svc_a 2, svc_b 2, svc_c 1,
|
||||||
# svc_h 2, svc_m 1, svc_o2 1, svc_o3 4 (kept orphans that may carry SSH), svc_p 4 (its
|
# svc_e 2, svc_g 1, svc_h 2, svc_m 1, svc_o2 1, svc_o3 4 (kept orphans that may carry SSH),
|
||||||
# desired rule and three kept stale rules).
|
# svc_p 4 (its desired rule and three kept stale rules).
|
||||||
- name: Read the rules ufw would load
|
- name: Read the rules ufw would load
|
||||||
ansible.builtin.command: ufw show added
|
ansible.builtin.command: ufw show added
|
||||||
register: ufw_conv_added
|
register: ufw_conv_added
|
||||||
|
|||||||
@@ -1,4 +1,317 @@
|
|||||||
---
|
---
|
||||||
|
# The refusal cases run first, so every assertion below also proves a refused run left the
|
||||||
|
# host unchanged. They are not in converge.yml because idempotence reruns it.
|
||||||
|
|
||||||
|
# Lock-out guard: default-deny without an SSH allow rule must be refused before
|
||||||
|
# any policy is touched.
|
||||||
|
- name: Refuse default-deny without an SSH allow rule
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Run the role with only a non-SSH rule
|
||||||
|
block:
|
||||||
|
- name: Include ufw
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
vars:
|
||||||
|
ufw_rules:
|
||||||
|
- {rule: allow, port: 8080, proto: tcp}
|
||||||
|
- name: Unreachable when the guard works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: ufw ran without an SSH allow rule
|
||||||
|
rescue:
|
||||||
|
- name: The guard, not something else, stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'would lock this host out' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# A delete entry removes the SSH rule it names, so it must not satisfy the guard.
|
||||||
|
- name: Run the role with an SSH rule that is only deleted
|
||||||
|
block:
|
||||||
|
- name: Include ufw
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
vars:
|
||||||
|
ufw_rules:
|
||||||
|
- {rule: allow, port: 8080, proto: tcp}
|
||||||
|
- {rule: allow, port: 22, proto: tcp, delete: true}
|
||||||
|
- name: Unreachable when the guard ignores delete entries
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: ufw counted a deleted SSH rule as the SSH allow rule
|
||||||
|
rescue:
|
||||||
|
- name: The guard stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'would lock this host out' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# The same rule added and deleted: the delete would win (deletes run last) while the
|
||||||
|
# guard counted the add. The comment, the port's type and the written default
|
||||||
|
# direction and source do not make them different.
|
||||||
|
- name: Run the role with a rule that is both added and deleted
|
||||||
|
block:
|
||||||
|
- name: Include ufw
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
vars:
|
||||||
|
ufw_rules:
|
||||||
|
- {rule: allow, port: "22", proto: tcp, direction: in, from: any, comment: ssh}
|
||||||
|
- {rule: allow, port: 22, proto: tcp, delete: true}
|
||||||
|
- name: Unreachable when the conflict check works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: ufw accepted a rule that is both added and deleted
|
||||||
|
rescue:
|
||||||
|
- name: The conflict check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'both added and deleted' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# Stray variable guard: variables named like <role>_ufw_rules must fail the play
|
||||||
|
# before anything changes, naming the variable. The vars sit on the include only, so they
|
||||||
|
# do not reach the plays below (the base ufw_rules and ufw_before_rules never match).
|
||||||
|
- name: Refuse stray variables named like the old *_ufw_rules
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: A stray *_ufw_rules variable
|
||||||
|
block:
|
||||||
|
- name: Include ufw with a stray rules variable
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
vars:
|
||||||
|
ufw_rules:
|
||||||
|
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||||
|
stray_ufw_rules: # noqa: var-naming[no-role-prefix]
|
||||||
|
- {rule: allow, port: 7999, proto: tcp, comment: stray}
|
||||||
|
- name: Unreachable when the stray variable guard works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: a stray *_ufw_rules variable was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The stray guard, not something else, stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "'stray_ufw_rules' in ansible_failed_result.msg | default('')"
|
||||||
|
- "'stray_ufw_before_rules' not in ansible_failed_result.msg | default('')"
|
||||||
|
- "'service_rules' in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: A stray *_ufw_before_rules variable
|
||||||
|
block:
|
||||||
|
- name: Include ufw with a stray before-rules variable
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
vars:
|
||||||
|
ufw_rules:
|
||||||
|
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||||
|
stray_ufw_before_rules: # noqa: var-naming[no-role-prefix]
|
||||||
|
- {proto: udp, port: 7998, comment: stray}
|
||||||
|
- name: Unreachable when the stray variable guard works
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: a stray *_ufw_before_rules variable was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The stray guard, not something else, stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "'stray_ufw_before_rules' in ansible_failed_result.msg | default('')"
|
||||||
|
- "'stray_ufw_rules' not in ansible_failed_result.msg | default('')"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# Inputs the entry point must refuse, each before it changes anything. Every block
|
||||||
|
# proves the refusal and its message; the Verify play proves no rule was left behind.
|
||||||
|
- name: Refuse invalid service rule inputs
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
# A failed looped task reports "One or more items failed" in msg and the item
|
||||||
|
# messages in results; an unlooped one has the message in msg.
|
||||||
|
ufw_verify_failure: >-
|
||||||
|
{{ ansible_failed_result.msg | default('') }}
|
||||||
|
{{ ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ') }}
|
||||||
|
tasks:
|
||||||
|
- name: An owner name outside the allowed characters
|
||||||
|
block:
|
||||||
|
- name: Include with an invalid owner name
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: Bad-Name
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 8101, proto: tcp}
|
||||||
|
- name: Unreachable when the owner name is checked
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: an invalid owner name was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The owner check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'ufw_service_name must be a string matching' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: The reserved owner base
|
||||||
|
block:
|
||||||
|
- name: Include as base
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: base
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 8102, proto: tcp}
|
||||||
|
- name: Unreachable when base is reserved
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: the reserved owner base was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The reserved name stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'reserved for the base play' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: A single quote in a comment
|
||||||
|
block:
|
||||||
|
- name: Include with a quote in the comment
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_f
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 8103, proto: tcp, comment: "it's"}
|
||||||
|
- name: Unreachable when comments are checked
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: a quote in a comment was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The comment check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'single quote' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: A rule another owner already holds
|
||||||
|
block:
|
||||||
|
- name: Include with the spec of a svc_a rule
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_f
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 8001, proto: tcp, comment: other text}
|
||||||
|
- name: Unreachable when collisions are checked
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: a rule owned by svc_a was accepted for svc_f
|
||||||
|
rescue:
|
||||||
|
- name: The collision check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'already owned by another tag' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: A rule that would retag the SSH rule
|
||||||
|
block:
|
||||||
|
- name: Include with an allow rule for the SSH port
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_f
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 22, proto: tcp}
|
||||||
|
- name: Unreachable when the SSH port is protected
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: a service rule for the SSH port was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The SSH check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'allows the SSH port' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: An unknown rule key
|
||||||
|
block:
|
||||||
|
- name: Include with a to_port key
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_f
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, to_port: 8104, proto: tcp}
|
||||||
|
- name: Unreachable when keys are checked
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: an unknown rule key was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The key check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'has an unknown key' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: An interface without a direction
|
||||||
|
block:
|
||||||
|
- name: Include with an interface and no direction
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_f
|
||||||
|
ufw_service_rules:
|
||||||
|
- {rule: allow, port: 8105, proto: tcp, interface: eth0}
|
||||||
|
- name: Unreachable when the direction is required
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: an interface without a direction was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The direction check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'interface without direction' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
- name: Purging with an empty rule list
|
||||||
|
block:
|
||||||
|
- name: Include with an empty list and ufw_purge_stale
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: service_rules
|
||||||
|
vars:
|
||||||
|
ufw_service_name: svc_a
|
||||||
|
ufw_purge_stale: true
|
||||||
|
ufw_service_rules: []
|
||||||
|
- name: Unreachable when an empty list is refused
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: an empty list with ufw_purge_stale was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The empty list stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'use ufw_service_state: absent' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# An orphan_rules input the entry point must refuse before it reads or deletes a rule.
|
||||||
|
- name: Refuse an invalid managed owner
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
ufw_verify_failure: >-
|
||||||
|
{{ ansible_failed_result.msg | default('') }}
|
||||||
|
{{ ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ') }}
|
||||||
|
tasks:
|
||||||
|
- name: An invalid managed owner
|
||||||
|
block:
|
||||||
|
- name: Include with an owner name outside the allowed characters
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: mortis.kamino.ufw
|
||||||
|
tasks_from: orphan_rules
|
||||||
|
vars:
|
||||||
|
ufw_managed_owners: [svc_a, Bad-Name]
|
||||||
|
ufw_purge_orphans: true
|
||||||
|
- name: Unreachable when the owners are checked
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: an invalid managed owner was accepted
|
||||||
|
rescue:
|
||||||
|
- name: The owner check stopped the play
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'ufw_managed_owners must be a list of strings matching' in ufw_verify_failure"
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# Converge's last play purged svc_o1 (want 0); svc_o2, svc_m and the tagged total carry the proof.
|
||||||
|
- name: Nothing was deleted after the invalid owner
|
||||||
|
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||||
|
vars:
|
||||||
|
ufw_conv_o1_want: 0
|
||||||
|
|
||||||
- name: Verify
|
- name: Verify
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -41,7 +354,7 @@
|
|||||||
vars:
|
vars:
|
||||||
ufw_verify_untagged: "{{ ufw_verify_added.stdout_lines | select('match', '^ufw ') | reject('search', 'ansible-ufw') | list }}"
|
ufw_verify_untagged: "{{ ufw_verify_added.stdout_lines | select('match', '^ufw ') | reject('search', 'ansible-ufw') | list }}"
|
||||||
|
|
||||||
# converge.yml proves the guard's message; the 7999 and 7998 absence checks are redundant confirmation that the stray rules never reached the host.
|
# The refusal play proves the guard's message; the 7999 and 7998 absence checks are redundant confirmation that the stray rules never reached the host.
|
||||||
- name: A stray *_ufw_rules variable did not reach the firewall
|
- name: A stray *_ufw_rules variable did not reach the firewall
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
|
|||||||
@@ -33,10 +33,9 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||||
# left before any scenario starts, so that destroy only waits out the
|
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
# After a local run, run `molecule destroy` yourself.
|
||||||
# `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
@@ -48,4 +47,3 @@ scenario:
|
|||||||
- side_effect
|
- side_effect
|
||||||
- verify
|
- verify
|
||||||
- cleanup
|
- cleanup
|
||||||
- destroy
|
|
||||||
Executable
+124
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# The Molecule workflow's "Run the scenarios" step: `molecule test` for each scenario directory on
|
||||||
|
# stdin, MOLECULE_LANES (default 4) at a time, each with its own log and ANSIBLE_HOME under
|
||||||
|
# <work-dir>/<n>/ (molecule reinstalls the collection there with --force). Exit 1 on a failure.
|
||||||
|
#
|
||||||
|
# scripts/run_molecule_scenarios.sh <work-dir> < scenario-dirs
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
lanes="${MOLECULE_LANES:-4}"
|
||||||
|
if ! [[ "$lanes" =~ ^[1-9][0-9]*$ ]]; then
|
||||||
|
echo "MOLECULE_LANES must be a positive integer, not '$lanes'" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "usage: $0 <work-dir> < scenario-dirs" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
work="$1"
|
||||||
|
|
||||||
|
label_of() {
|
||||||
|
case "$1" in
|
||||||
|
extensions/*) echo "${1##*/}" ;;
|
||||||
|
*) local role="${1#roles/}"; echo "${role%%/*}/${1##*/}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Removes the scenario's containers by the literal platform names in its molecule.yml, in place of
|
||||||
|
# molecule's destroy, which the scenarios leave out: its driver waits about 5.6 s per scenario for
|
||||||
|
# the deletion (about 84 s over 15), and the whole destroy phase measured about 103 s a full run.
|
||||||
|
# python3 is the molecule venv's, with PyYAML.
|
||||||
|
remove_instances() {
|
||||||
|
local names ids
|
||||||
|
local py='import sys, yaml; print(*(p["name"] for p in yaml.safe_load(open(sys.argv[1]))["platforms"]))'
|
||||||
|
names="$(python3 -I -c "$py" "$1/molecule.yml")" || return 1
|
||||||
|
[ -n "$names" ] || return 1
|
||||||
|
# shellcheck disable=SC2046,SC2086 # names and ids are one word each
|
||||||
|
ids="$(docker ps -aq $(printf -- '--filter name=^/%s$ ' $names))" || return 1
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
if [ -n "$ids" ]; then docker rm -f $ids >/dev/null || return 1; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Runs scenario $2 into $work/$1/. Its outcome is the rc file, which a lane that died lacks.
|
||||||
|
run_one() {
|
||||||
|
local out="$work/$1" dir="$2" start=$SECONDS rc=0
|
||||||
|
mkdir -p "$out/ansible"
|
||||||
|
(
|
||||||
|
export ANSIBLE_HOME="$out/ansible"
|
||||||
|
# a role scenario runs from its role's directory, as molecule expects
|
||||||
|
case "$dir" in roles/*) cd "${dir%/molecule/*}" || exit 1 ;; esac
|
||||||
|
molecule test -s "${dir##*/}"
|
||||||
|
) >"$out/log" 2>&1 </dev/null || rc=$?
|
||||||
|
if ! remove_instances "$dir" >>"$out/log" 2>&1; then
|
||||||
|
echo "could not remove the containers of $dir" >>"$out/log"
|
||||||
|
if [ "$rc" -eq 0 ]; then rc=1; fi
|
||||||
|
fi
|
||||||
|
echo "$((SECONDS - start))" >"$out/seconds"
|
||||||
|
echo "$rc" >"$out/rc"
|
||||||
|
echo "finished $(label_of "$dir"): exit $rc after $((SECONDS - start)) s"
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs=()
|
||||||
|
while IFS= read -r dir; do
|
||||||
|
if [ -n "$dir" ]; then dirs+=("$dir"); fi
|
||||||
|
done
|
||||||
|
mkdir -p "$work"
|
||||||
|
|
||||||
|
# A cancelled job must not leave lanes behind that recreate containers after the next run's
|
||||||
|
# cleanup. A signal to this script stops each lane's tree so it cannot fork, then terminates it,
|
||||||
|
# with the whole group of any descendant that leads one: ansible's workers detach into their own.
|
||||||
|
# A kill of the step's process group reaches the lanes and molecule, not those detached workers.
|
||||||
|
kill_tree() {
|
||||||
|
local child leader=""
|
||||||
|
kill -STOP "$1" 2>/dev/null || return 0
|
||||||
|
# never a group this script or its caller is in: only one a descendant leads
|
||||||
|
if [ "$(ps -o pgid= -p "$1" | tr -d ' ')" = "$1" ] && [ "$1" != "$own_group" ]; then
|
||||||
|
leader=1
|
||||||
|
kill -STOP -- "-$1" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
for child in $(ps -o pid= --ppid "$1"); do kill_tree "$child"; done
|
||||||
|
if [ -n "$leader" ]; then
|
||||||
|
kill -TERM -- "-$1" 2>/dev/null || true
|
||||||
|
kill -CONT -- "-$1" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
kill -TERM "$1" 2>/dev/null || true
|
||||||
|
kill -CONT "$1" 2>/dev/null || true
|
||||||
|
}
|
||||||
|
stop_lanes() {
|
||||||
|
# a second signal must not abort the cleanup and leave a lane stopped
|
||||||
|
trap '' TERM INT HUP
|
||||||
|
local pid
|
||||||
|
for pid in $(jobs -rp); do kill_tree "$pid"; done
|
||||||
|
wait || true
|
||||||
|
exit "$1"
|
||||||
|
}
|
||||||
|
own_group="$(ps -o pgid= -p "$$" | tr -d ' ')"
|
||||||
|
trap 'stop_lanes 143' TERM
|
||||||
|
trap 'stop_lanes 130' INT
|
||||||
|
trap 'stop_lanes 129' HUP
|
||||||
|
|
||||||
|
for n in "${!dirs[@]}"; do
|
||||||
|
while [ "$(jobs -rp | wc -l)" -ge "$lanes" ]; do wait -n || true; done
|
||||||
|
run_one "$n" "${dirs[$n]}" </dev/null &
|
||||||
|
done
|
||||||
|
wait
|
||||||
|
|
||||||
|
failed=""
|
||||||
|
ran=0
|
||||||
|
times=""
|
||||||
|
for n in "${!dirs[@]}"; do
|
||||||
|
label="$(label_of "${dirs[$n]}")"
|
||||||
|
seconds="$(cat "$work/$n/seconds" 2>/dev/null || echo '?')"
|
||||||
|
times="$times $label: $seconds s"$'\n'
|
||||||
|
echo "::group::molecule test: $label ($seconds s)"
|
||||||
|
cat "$work/$n/log" 2>/dev/null || true
|
||||||
|
echo "::endgroup::"
|
||||||
|
if [ -f "$work/$n/rc" ]; then
|
||||||
|
ran=$((ran + 1))
|
||||||
|
if [ "$(cat "$work/$n/rc")" != 0 ]; then failed="$failed $label"; fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf 'Scenarios run: %s\n%s' "$ran" "$times"
|
||||||
|
# A lane that died without a result must not pass quietly.
|
||||||
|
test "$ran" -eq "${#dirs[@]}" || { echo "::error::ran $ran of ${#dirs[@]} selected scenarios"; exit 1; }
|
||||||
|
test -z "$failed" || { echo "::error::Failed:$failed"; exit 1; }
|
||||||
@@ -13,6 +13,9 @@ Only a pull request is narrowed, and only when <base-ref> is given and EVENT_NAM
|
|||||||
|
|
||||||
* a file under roles/<role>/ selects that role's scenarios, and those of every role that
|
* a file under roles/<role>/ selects that role's scenarios, and those of every role that
|
||||||
uses it (below);
|
uses it (below);
|
||||||
|
* a file under extensions/molecule/<name>/, when that is a scenario, selects that scenario
|
||||||
|
only (the image-smoke scenarios test the images, not the roles); a shared file such as
|
||||||
|
extensions/molecule/requirements.yml is "any other file";
|
||||||
* a file on the IGNORED list (documentation, changelog, repository tooling that no
|
* a file on the IGNORED list (documentation, changelog, repository tooling that no
|
||||||
scenario reads) selects nothing;
|
scenario reads) selects nothing;
|
||||||
* any other file selects every scenario.
|
* any other file selects every scenario.
|
||||||
@@ -38,8 +41,8 @@ nothing tested. A role whose directory is gone (the role was deleted) selects no
|
|||||||
|
|
||||||
The workflow runs this script from the base branch's copy, not the pull request's, so a pull
|
The workflow runs this script from the base branch's copy, not the pull request's, so a pull
|
||||||
request cannot edit the rules it is judged by (the same reason lint.yml runs
|
request cannot edit the rules it is judged by (the same reason lint.yml runs
|
||||||
check_bot_pr_diff.py from origin/main). A change to this file therefore selects everything
|
check_bot_pr_diff.py from origin/main). No scenario runs the pull request's copy, so this file
|
||||||
under the base copy's rules, because the file is not on the IGNORED list.
|
is on the IGNORED list: its unit tests test it, and the push run after the merge runs it.
|
||||||
|
|
||||||
Exit codes: 0 ok (an empty selection from an all-ignored diff is ok), 1 no scenario exists at
|
Exit codes: 0 ok (an empty selection from an all-ignored diff is ok), 1 no scenario exists at
|
||||||
all, or a changed role has none, 2 bad usage. Notices go to stderr as `::notice::` lines, with
|
all, or a changed role has none, 2 bad usage. Notices go to stderr as `::notice::` lines, with
|
||||||
@@ -63,7 +66,8 @@ IGNORED = (
|
|||||||
"SECURITY.md",
|
"SECURITY.md",
|
||||||
"GLOSSARY.md",
|
"GLOSSARY.md",
|
||||||
"AGENTS.md",
|
"AGENTS.md",
|
||||||
"roles/AGENTS.md",
|
"*/AGENTS.md",
|
||||||
|
"roles/*/README.md",
|
||||||
"CODEOWNERS",
|
"CODEOWNERS",
|
||||||
"CHANGELOG.rst",
|
"CHANGELOG.rst",
|
||||||
"COPYING",
|
"COPYING",
|
||||||
@@ -75,6 +79,7 @@ IGNORED = (
|
|||||||
".ansible-lint",
|
".ansible-lint",
|
||||||
".ansible-lint-ignore",
|
".ansible-lint-ignore",
|
||||||
".pre-commit-config.yaml",
|
".pre-commit-config.yaml",
|
||||||
|
".python-version",
|
||||||
"requirements-dev.txt",
|
"requirements-dev.txt",
|
||||||
"requirements-dev.lock",
|
"requirements-dev.lock",
|
||||||
"ruff.toml",
|
"ruff.toml",
|
||||||
@@ -100,6 +105,8 @@ IGNORED = (
|
|||||||
"scripts/ansible-test-sanity.sh",
|
"scripts/ansible-test-sanity.sh",
|
||||||
"scripts/dev-setup.sh",
|
"scripts/dev-setup.sh",
|
||||||
"scripts/reuse_lint.py",
|
"scripts/reuse_lint.py",
|
||||||
|
"scripts/lock-requirements.sh",
|
||||||
|
"scripts/select_molecule_scenarios.py",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -189,6 +196,7 @@ def select(all_scenarios, changed, root="."):
|
|||||||
Raises ValueError when a changed role still exists but has no scenario.
|
Raises ValueError when a changed role still exists but has no scenario.
|
||||||
"""
|
"""
|
||||||
roles = set()
|
roles = set()
|
||||||
|
extensions = set()
|
||||||
for path in changed:
|
for path in changed:
|
||||||
if is_ignored(path):
|
if is_ignored(path):
|
||||||
continue
|
continue
|
||||||
@@ -196,13 +204,23 @@ def select(all_scenarios, changed, root="."):
|
|||||||
if len(parts) > 2 and parts[0] == "roles":
|
if len(parts) > 2 and parts[0] == "roles":
|
||||||
roles.add(parts[1])
|
roles.add(parts[1])
|
||||||
continue
|
continue
|
||||||
|
scenario = "/".join(parts[:3])
|
||||||
|
if (
|
||||||
|
len(parts) > 3
|
||||||
|
and parts[:2] == ["extensions", "molecule"]
|
||||||
|
and scenario in all_scenarios
|
||||||
|
):
|
||||||
|
extensions.add(scenario)
|
||||||
|
continue
|
||||||
return list(all_scenarios), f"{printable(path)} can affect every scenario"
|
return list(all_scenarios), f"{printable(path)} can affect every scenario"
|
||||||
changed_roles = roles
|
changed_roles = roles
|
||||||
roles = with_users(changed_roles, users(root, changed_roles))
|
roles = with_users(changed_roles, users(root, changed_roles))
|
||||||
chosen = [
|
chosen = [
|
||||||
s for s in all_scenarios if s.startswith("roles/") and s.split("/")[1] in roles
|
s
|
||||||
|
for s in all_scenarios
|
||||||
|
if s in extensions or (s.startswith("roles/") and s.split("/")[1] in roles)
|
||||||
]
|
]
|
||||||
covered = {s.split("/")[1] for s in chosen}
|
covered = {s.split("/")[1] for s in chosen if s.startswith("roles/")}
|
||||||
bare = sorted(
|
bare = sorted(
|
||||||
r for r in roles - covered if os.path.isdir(os.path.join(root, "roles", r))
|
r for r in roles - covered if os.path.isdir(os.path.join(root, "roles", r))
|
||||||
)
|
)
|
||||||
@@ -211,16 +229,22 @@ def select(all_scenarios, changed, root="."):
|
|||||||
"role without a molecule scenario (changed, or a user of a changed role): "
|
"role without a molecule scenario (changed, or a user of a changed role): "
|
||||||
+ ", ".join(printable(r) for r in bare)
|
+ ", ".join(printable(r) for r in bare)
|
||||||
)
|
)
|
||||||
|
notes = []
|
||||||
if roles:
|
if roles:
|
||||||
reason = "only roles changed: " + ", ".join(
|
notes.append(
|
||||||
printable(r) for r in sorted(changed_roles)
|
"roles changed: " + ", ".join(printable(r) for r in sorted(changed_roles))
|
||||||
)
|
)
|
||||||
if roles - changed_roles:
|
if roles - changed_roles:
|
||||||
reason += "; their users: " + ", ".join(
|
notes.append(
|
||||||
printable(r) for r in sorted(roles - changed_roles)
|
"their users: "
|
||||||
|
+ ", ".join(printable(r) for r in sorted(roles - changed_roles))
|
||||||
)
|
)
|
||||||
else:
|
if extensions:
|
||||||
reason = "no change that a scenario reads"
|
notes.append(
|
||||||
|
"image-smoke scenarios changed: "
|
||||||
|
+ ", ".join(printable(e.split("/")[2]) for e in sorted(extensions))
|
||||||
|
)
|
||||||
|
reason = "; ".join(notes) or "no change that a scenario reads"
|
||||||
return chosen, reason
|
return chosen, reason
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,304 @@
|
|||||||
|
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
"""Tests for scripts/run_molecule_scenarios.sh with stub molecule and docker on PATH.
|
||||||
|
|
||||||
|
Run with: python3 -m unittest discover -s tests/scripts
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import time
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||||
|
SCRIPT = REPO / "scripts" / "run_molecule_scenarios.sh"
|
||||||
|
WORKFLOW = REPO / ".gitea" / "workflows" / "molecule.yml"
|
||||||
|
|
||||||
|
# Records what each run saw, then behaves as STUB_<scenario label> asks: fail, sleep, hang (and
|
||||||
|
# record its pids), detach (as an ansible worker does, into its own process group, whose orphaned
|
||||||
|
# child no parent link reaches; record both), or read stdin (which must be empty).
|
||||||
|
MOLECULE_STUB = """#!/usr/bin/env bash
|
||||||
|
label="$(basename "$PWD")/$3"
|
||||||
|
[ "$PWD" = "$STUB_ROOT" ] && label="$3"
|
||||||
|
key="STUB_$(printf %s "$label" | tr -c 'A-Za-z0-9' _)"
|
||||||
|
echo "$label start $(date +%s.%N) home=$ANSIBLE_HOME cwd=$PWD args=$*" >> "$STUB_LOG"
|
||||||
|
echo "output of $label"
|
||||||
|
case "${!key:-}" in
|
||||||
|
fail) echo "$label end $(date +%s.%N)" >> "$STUB_LOG"; exit 2 ;;
|
||||||
|
sleep) sleep 1 ;;
|
||||||
|
hang) sleep 60 & echo "$$ $!" >> "$STUB_PIDS"; wait ;;
|
||||||
|
detach)
|
||||||
|
setsid bash -c '(sleep 60 & echo $! >> "$STUB_PIDS"); echo $$ >> "$STUB_PIDS"; exec sleep 60' &
|
||||||
|
wait ;;
|
||||||
|
stdin) echo "stdin of $label: [$(cat)]" ;;
|
||||||
|
esac
|
||||||
|
echo "$label end $(date +%s.%N)" >> "$STUB_LOG"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# `ps` lists a container id per name filter; `rm` records the ids or fails on request.
|
||||||
|
DOCKER_STUB = """#!/usr/bin/env bash
|
||||||
|
echo "docker $*" >> "$STUB_DOCKER_LOG"
|
||||||
|
case "$1" in
|
||||||
|
ps) for a in "$@"; do case "$a" in name=*) n="${a#name=^/}"; echo "id-${n%$}" ;; esac; done ;;
|
||||||
|
rm) [ -z "${STUB_RM_FAIL:-}" ] || exit 1 ;;
|
||||||
|
esac
|
||||||
|
"""
|
||||||
|
|
||||||
|
PLATFORMS = {
|
||||||
|
"roles/alpha/molecule/default": ["alpha-instance"],
|
||||||
|
"roles/beta/molecule/default": ["beta-instance", "beta2-instance"],
|
||||||
|
"roles/beta/molecule/check_mode": ["beta-check-instance"],
|
||||||
|
"extensions/molecule/image-smoke": ["image-smoke"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(shutil.which("bash"), "bash is required")
|
||||||
|
class RunMoleculeScenariosTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix="kamino-runmol-")).resolve()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||||
|
self.root = self.tmp / "kamino"
|
||||||
|
self.hung = []
|
||||||
|
for scenario, names in PLATFORMS.items():
|
||||||
|
d = self.root / scenario
|
||||||
|
d.mkdir(parents=True)
|
||||||
|
platforms = [{"name": n, "image": "${MOLECULE_IMAGE}"} for n in names]
|
||||||
|
(d / "molecule.yml").write_text(yaml.safe_dump({"platforms": platforms}))
|
||||||
|
bin_dir = self.tmp / "bin"
|
||||||
|
bin_dir.mkdir()
|
||||||
|
for name, body in (("molecule", MOLECULE_STUB), ("docker", DOCKER_STUB)):
|
||||||
|
(bin_dir / name).write_text(body)
|
||||||
|
(bin_dir / name).chmod(0o755)
|
||||||
|
self.log = self.tmp / "molecule.log"
|
||||||
|
self.docker_log = self.tmp / "docker.log"
|
||||||
|
self.log.touch()
|
||||||
|
self.docker_log.touch()
|
||||||
|
self.env = {
|
||||||
|
"PATH": f"{bin_dir}:{os.environ['PATH']}",
|
||||||
|
"HOME": str(self.tmp),
|
||||||
|
"STUB_ROOT": str(self.root),
|
||||||
|
"STUB_LOG": str(self.log),
|
||||||
|
"STUB_DOCKER_LOG": str(self.docker_log),
|
||||||
|
}
|
||||||
|
|
||||||
|
def run_script(self, scenarios, **env):
|
||||||
|
return subprocess.run(
|
||||||
|
["bash", str(SCRIPT), str(self.tmp / "work")],
|
||||||
|
cwd=self.root,
|
||||||
|
env={**self.env, **env},
|
||||||
|
input="".join(f"{s}\n" for s in scenarios),
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
def events(self):
|
||||||
|
"""{label: (start, end)} from the molecule stub's log."""
|
||||||
|
times = {}
|
||||||
|
for line in self.log.read_text().splitlines():
|
||||||
|
label, what, stamp = line.split()[:3]
|
||||||
|
times.setdefault(label, {})[what] = float(stamp)
|
||||||
|
return {k: (v["start"], v.get("end")) for k, v in times.items()}
|
||||||
|
|
||||||
|
def test_groups_follow_the_selection_order_with_times(self):
|
||||||
|
order = list(PLATFORMS)
|
||||||
|
proc = self.run_script(order, STUB_alpha_default="sleep")
|
||||||
|
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||||
|
groups = re.findall(
|
||||||
|
r"^::group::molecule test: (\S+) \((\d+) s\)$", proc.stdout, re.MULTILINE
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
[g[0] for g in groups],
|
||||||
|
["alpha/default", "beta/default", "beta/check_mode", "image-smoke"],
|
||||||
|
)
|
||||||
|
self.assertGreaterEqual(int(groups[0][1]), 1)
|
||||||
|
self.assertEqual(proc.stdout.count("::endgroup::"), 4)
|
||||||
|
# each log sits inside its own group
|
||||||
|
body = proc.stdout.split("::group::molecule test: beta/default")[1].split(
|
||||||
|
"::endgroup::"
|
||||||
|
)[0]
|
||||||
|
self.assertIn("output of beta/default", body)
|
||||||
|
self.assertNotIn("output of alpha/default", body)
|
||||||
|
self.assertIn("Scenarios run: 4", proc.stdout)
|
||||||
|
self.assertIn(" image-smoke: ", proc.stdout)
|
||||||
|
|
||||||
|
def test_runs_in_lanes_and_isolates_each_scenario(self):
|
||||||
|
order = list(PLATFORMS)
|
||||||
|
stubs = {
|
||||||
|
f"STUB_{k}": "sleep"
|
||||||
|
for k in ("alpha_default", "beta_default", "image_smoke")
|
||||||
|
}
|
||||||
|
proc = self.run_script(order, MOLECULE_LANES="2", **stubs)
|
||||||
|
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||||
|
spans = self.events()
|
||||||
|
self.assertEqual(len(spans), 4)
|
||||||
|
running_at = [
|
||||||
|
sum(s <= t < e for s, e in spans.values()) for t, _end in spans.values()
|
||||||
|
]
|
||||||
|
self.assertEqual(max(running_at), 2, spans)
|
||||||
|
starts = [
|
||||||
|
line for line in self.log.read_text().splitlines() if " start " in line
|
||||||
|
]
|
||||||
|
homes = {re.search(r"home=(\S+)", s).group(1) for s in starts}
|
||||||
|
self.assertEqual(len(homes), 4)
|
||||||
|
check = next(s for s in starts if s.startswith("beta/check_mode "))
|
||||||
|
self.assertIn(
|
||||||
|
f"cwd={self.root / 'roles' / 'beta'} args=test -s check_mode", check
|
||||||
|
)
|
||||||
|
smoke = next(s for s in starts if s.startswith("image-smoke "))
|
||||||
|
self.assertIn(f"cwd={self.root} args=test -s image-smoke", smoke)
|
||||||
|
|
||||||
|
def test_a_failure_is_reported_and_its_containers_still_go(self):
|
||||||
|
proc = self.run_script(list(PLATFORMS), STUB_beta_default="fail")
|
||||||
|
self.assertEqual(proc.returncode, 1)
|
||||||
|
self.assertIn("::error::Failed: beta/default\n", proc.stdout)
|
||||||
|
self.assertIn("Scenarios run: 4", proc.stdout)
|
||||||
|
docker = self.docker_log.read_text()
|
||||||
|
for name in (n for names in PLATFORMS.values() for n in names):
|
||||||
|
self.assertIn(f"--filter name=^/{name}$", docker)
|
||||||
|
self.assertIn("docker rm -f id-beta-instance id-beta2-instance", docker)
|
||||||
|
|
||||||
|
def test_molecule_gets_no_stdin(self):
|
||||||
|
proc = self.run_script(list(PLATFORMS), STUB_alpha_default="stdin")
|
||||||
|
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||||
|
self.assertIn("stdin of alpha/default: []", proc.stdout)
|
||||||
|
self.assertIn("Scenarios run: 4", proc.stdout)
|
||||||
|
|
||||||
|
def test_a_failed_removal_fails_the_scenario(self):
|
||||||
|
proc = self.run_script(["roles/alpha/molecule/default"], STUB_RM_FAIL="1")
|
||||||
|
self.assertEqual(proc.returncode, 1)
|
||||||
|
self.assertIn(
|
||||||
|
"could not remove the containers of roles/alpha/molecule/default",
|
||||||
|
proc.stdout,
|
||||||
|
)
|
||||||
|
self.assertIn("::error::Failed: alpha/default\n", proc.stdout)
|
||||||
|
|
||||||
|
def test_a_scenario_without_a_result_fails_the_run(self):
|
||||||
|
# a lane that dies leaves no rc file: a file where the second scenario's work directory
|
||||||
|
# goes makes its lane fail before molecule starts
|
||||||
|
(self.tmp / "work").mkdir()
|
||||||
|
(self.tmp / "work" / "1").write_text("not a directory")
|
||||||
|
proc = self.run_script(
|
||||||
|
["roles/alpha/molecule/default", "roles/beta/molecule/default"]
|
||||||
|
)
|
||||||
|
self.assertEqual(proc.returncode, 1)
|
||||||
|
self.assertIn("::error::ran 1 of 2 selected scenarios", proc.stdout)
|
||||||
|
|
||||||
|
def test_lanes_must_be_a_positive_integer(self):
|
||||||
|
for lanes in ("0", "-1", "two", "04"):
|
||||||
|
proc = self.run_script(list(PLATFORMS), MOLECULE_LANES=lanes)
|
||||||
|
self.assertEqual(proc.returncode, 2, lanes)
|
||||||
|
self.assertIn("MOLECULE_LANES must be a positive integer", proc.stderr)
|
||||||
|
self.assertEqual(self.log.read_text(), "")
|
||||||
|
|
||||||
|
def start_hung_run(self, count=4, **stubs):
|
||||||
|
"""A run in its own process group whose molecule stubs hang, and the pids they record."""
|
||||||
|
pids = self.tmp / "pids"
|
||||||
|
pids.touch()
|
||||||
|
env = {**self.env, "STUB_PIDS": str(pids), "MOLECULE_LANES": "2"}
|
||||||
|
env.update(stubs or {"STUB_alpha_default": "hang", "STUB_beta_default": "hang"})
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
["bash", str(SCRIPT), str(self.tmp / "work")],
|
||||||
|
cwd=self.root, env=env, stdin=subprocess.PIPE, text=True,
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, start_new_session=True,
|
||||||
|
) # fmt: skip
|
||||||
|
self.addCleanup(lambda: proc.poll() is None and os.killpg(proc.pid, 9))
|
||||||
|
self.addCleanup(lambda: [os.kill(p, 9) for p in self.hung if alive(p)])
|
||||||
|
proc.stdin.write("".join(f"{s}\n" for s in PLATFORMS))
|
||||||
|
proc.stdin.close()
|
||||||
|
deadline = time.monotonic() + 10
|
||||||
|
while len(pids.read_text().split()) < count and time.monotonic() < deadline:
|
||||||
|
time.sleep(0.05)
|
||||||
|
self.hung = [int(p) for p in pids.read_text().split()]
|
||||||
|
self.assertEqual(len(self.hung), count)
|
||||||
|
return proc
|
||||||
|
|
||||||
|
def assert_all_gone(self, pids):
|
||||||
|
deadline = time.monotonic() + 5
|
||||||
|
while any(map(alive, pids)) and time.monotonic() < deadline:
|
||||||
|
time.sleep(0.05)
|
||||||
|
self.assertEqual([p for p in pids if alive(p)], [])
|
||||||
|
|
||||||
|
@unittest.skipUnless(pathlib.Path("/proc/self").exists(), "needs /proc")
|
||||||
|
def test_a_terminated_run_kills_its_lanes(self):
|
||||||
|
proc = self.start_hung_run()
|
||||||
|
proc.send_signal(signal.SIGTERM)
|
||||||
|
self.assertEqual(proc.wait(timeout=10), 143)
|
||||||
|
self.assert_all_gone(self.hung)
|
||||||
|
self.assertEqual(proc.stderr.read(), "")
|
||||||
|
|
||||||
|
@unittest.skipUnless(pathlib.Path("/proc/self").exists(), "needs /proc")
|
||||||
|
@unittest.skipUnless(shutil.which("setsid"), "needs setsid")
|
||||||
|
def test_a_terminated_run_kills_detached_process_groups(self):
|
||||||
|
proc = self.start_hung_run(count=2, STUB_alpha_default="detach")
|
||||||
|
proc.send_signal(signal.SIGTERM)
|
||||||
|
self.assertEqual(proc.wait(timeout=10), 143)
|
||||||
|
self.assert_all_gone(self.hung)
|
||||||
|
|
||||||
|
@unittest.skipUnless(pathlib.Path("/proc/self").exists(), "needs /proc")
|
||||||
|
def test_a_killed_process_group_takes_its_lanes(self):
|
||||||
|
# a runner may cancel a step by killing its process group, which the script cannot trap
|
||||||
|
proc = self.start_hung_run()
|
||||||
|
os.killpg(proc.pid, signal.SIGKILL)
|
||||||
|
proc.wait(timeout=10)
|
||||||
|
self.assert_all_gone(self.hung)
|
||||||
|
|
||||||
|
def test_an_empty_selection_runs_nothing(self):
|
||||||
|
proc = self.run_script(["", ""])
|
||||||
|
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||||
|
self.assertIn("Scenarios run: 0", proc.stdout)
|
||||||
|
self.assertEqual(self.log.read_text(), "")
|
||||||
|
|
||||||
|
|
||||||
|
def alive(pid):
|
||||||
|
"""Whether pid is a running process, not gone or a zombie."""
|
||||||
|
try:
|
||||||
|
stat = pathlib.Path(f"/proc/{pid}/stat").read_text()
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
return stat.rsplit(")", 1)[1].split()[0] != "Z"
|
||||||
|
|
||||||
|
|
||||||
|
def stale_filters():
|
||||||
|
"""The name filters of the workflow's stale-container cleanup, as docker matches /<name>."""
|
||||||
|
workflow = yaml.safe_load(WORKFLOW.read_text())
|
||||||
|
steps = [s for job in workflow["jobs"].values() for s in job.get("steps", [])]
|
||||||
|
run = next(s["run"] for s in steps if s.get("name") == "Run the scenarios")
|
||||||
|
stale = next(line for line in run.splitlines() if line.strip().startswith("stale="))
|
||||||
|
return re.findall(r"--filter 'name=([^']+)'", stale)
|
||||||
|
|
||||||
|
|
||||||
|
class ScenarioPlatformNamesTest(unittest.TestCase):
|
||||||
|
"""The run script removes containers by literal platform name, and scenarios run side by side."""
|
||||||
|
|
||||||
|
def test_platform_names_are_literal_unique_and_cleared_before_a_run(self):
|
||||||
|
files = sorted(REPO.glob("roles/*/molecule/*/molecule.yml"))
|
||||||
|
files += sorted(REPO.glob("extensions/molecule/*/molecule.yml"))
|
||||||
|
self.assertTrue(files)
|
||||||
|
seen = {}
|
||||||
|
stale = stale_filters()
|
||||||
|
self.assertTrue(stale)
|
||||||
|
for path in files:
|
||||||
|
data = yaml.safe_load(path.read_text())
|
||||||
|
for platform in data["platforms"]:
|
||||||
|
name = platform["name"]
|
||||||
|
where = path.relative_to(REPO)
|
||||||
|
self.assertTrue(
|
||||||
|
any(re.search(f, f"/{name}") for f in stale), f"{where}: {name}"
|
||||||
|
)
|
||||||
|
self.assertNotIn(
|
||||||
|
name, seen, f"{where} and {seen.get(name)} share {name}"
|
||||||
|
)
|
||||||
|
seen[name] = where
|
||||||
|
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -162,6 +162,32 @@ class SelectTest(unittest.TestCase):
|
|||||||
chosen, _reason = sel.select(ALL, ["AGENTS.md"])
|
chosen, _reason = sel.select(ALL, ["AGENTS.md"])
|
||||||
self.assertEqual(chosen, [])
|
self.assertEqual(chosen, [])
|
||||||
|
|
||||||
|
def test_nested_agent_guidance_selects_nothing(self):
|
||||||
|
chosen, _reason = self.select(
|
||||||
|
[
|
||||||
|
".gitea/workflows/AGENTS.md",
|
||||||
|
"scripts/AGENTS.md",
|
||||||
|
"roles/docker/AGENTS.md",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
self.assertEqual(chosen, [])
|
||||||
|
|
||||||
|
def test_role_readme_selects_nothing(self):
|
||||||
|
# A role's README is documentation; its scenarios and its users' do not read it.
|
||||||
|
chosen, _reason = self.select(["roles/docker/README.md"])
|
||||||
|
self.assertEqual(chosen, [])
|
||||||
|
|
||||||
|
def test_selector_and_dev_python_select_nothing(self):
|
||||||
|
# Molecule runs the base copy of the selector and the runner's own venv.
|
||||||
|
chosen, _reason = self.select(
|
||||||
|
[
|
||||||
|
"scripts/select_molecule_scenarios.py",
|
||||||
|
"scripts/lock-requirements.sh",
|
||||||
|
".python-version",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
self.assertEqual(chosen, [])
|
||||||
|
|
||||||
def test_issue_and_pull_request_templates_select_nothing(self):
|
def test_issue_and_pull_request_templates_select_nothing(self):
|
||||||
# Gitea reads them for its web forms; no scenario does, and they are not shipped.
|
# Gitea reads them for its web forms; no scenario does, and they are not shipped.
|
||||||
chosen, _reason = self.select(
|
chosen, _reason = self.select(
|
||||||
@@ -182,9 +208,9 @@ class SelectTest(unittest.TestCase):
|
|||||||
"galaxy.yml",
|
"galaxy.yml",
|
||||||
"meta/runtime.yml",
|
"meta/runtime.yml",
|
||||||
"plugins/modules/x.py",
|
"plugins/modules/x.py",
|
||||||
"extensions/molecule/image-smoke/molecule.yml",
|
"extensions/molecule/requirements.yml",
|
||||||
|
"extensions/molecule/gone/molecule.yml",
|
||||||
".gitea/workflows/molecule.yml",
|
".gitea/workflows/molecule.yml",
|
||||||
"scripts/select_molecule_scenarios.py",
|
|
||||||
"tests/unit/x.py",
|
"tests/unit/x.py",
|
||||||
"new_top_level_file",
|
"new_top_level_file",
|
||||||
"roles/README.md",
|
"roles/README.md",
|
||||||
@@ -192,6 +218,25 @@ class SelectTest(unittest.TestCase):
|
|||||||
chosen, _reason = self.select(["roles/docker/tasks/main.yml", path])
|
chosen, _reason = self.select(["roles/docker/tasks/main.yml", path])
|
||||||
self.assertEqual(chosen, ALL, path)
|
self.assertEqual(chosen, ALL, path)
|
||||||
|
|
||||||
|
def test_image_smoke_change_selects_only_that_scenario(self):
|
||||||
|
chosen, reason = self.select(
|
||||||
|
["extensions/molecule/image-smoke-2604/verify.yml"]
|
||||||
|
)
|
||||||
|
self.assertEqual(chosen, ["extensions/molecule/image-smoke-2604"])
|
||||||
|
self.assertIn("image-smoke-2604", reason)
|
||||||
|
|
||||||
|
def test_image_smoke_and_role_changes_combine(self):
|
||||||
|
chosen, _reason = self.select(
|
||||||
|
[
|
||||||
|
"extensions/molecule/image-smoke/converge.yml",
|
||||||
|
"roles/docker/tasks/main.yml",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
chosen,
|
||||||
|
["extensions/molecule/image-smoke", "roles/docker/molecule/default"],
|
||||||
|
)
|
||||||
|
|
||||||
def test_deleted_role_selects_nothing_of_its_own(self):
|
def test_deleted_role_selects_nothing_of_its_own(self):
|
||||||
chosen, _reason = self.select(["roles/gone/tasks/main.yml"])
|
chosen, _reason = self.select(["roles/gone/tasks/main.yml"])
|
||||||
self.assertEqual(chosen, [])
|
self.assertEqual(chosen, [])
|
||||||
@@ -470,7 +515,7 @@ class MainTest(unittest.TestCase):
|
|||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
def test_every_tracked_file_is_ignored_or_selects_everything_or_is_a_role_file(
|
def test_every_tracked_file_is_ignored_or_selects_everything_or_its_own_scenario(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
tracked = subprocess.run(
|
tracked = subprocess.run(
|
||||||
@@ -487,7 +532,12 @@ class MainTest(unittest.TestCase):
|
|||||||
if sel.is_ignored(path) or path.startswith("roles/"):
|
if sel.is_ignored(path) or path.startswith("roles/"):
|
||||||
continue
|
continue
|
||||||
chosen, _reason = sel.select(scenarios, [path], str(REPO))
|
chosen, _reason = sel.select(scenarios, [path], str(REPO))
|
||||||
self.assertEqual(chosen, scenarios, path)
|
own = "/".join(path.split("/")[:3])
|
||||||
|
if path.startswith("extensions/molecule/") and own in scenarios:
|
||||||
|
# A file of one image-smoke scenario selects that scenario only.
|
||||||
|
self.assertEqual(chosen, [own], path)
|
||||||
|
else:
|
||||||
|
self.assertEqual(chosen, scenarios, path)
|
||||||
|
|
||||||
def test_roles_call_each_other_by_full_name_only(self):
|
def test_roles_call_each_other_by_full_name_only(self):
|
||||||
# The selection finds a role's users by the text mortis.kamino.<role> (users()). A use
|
# The selection finds a role's users by the text mortis.kamino.<role> (users()). A use
|
||||||
|
|||||||
Reference in new issue
Block a user