test(cloudflared): add the default molecule scenario
Runs without Cloudflare and without a real cloudflared: a stub of the Cloudflare API on the controller's loopback answers the tunnel, zone and DNS record calls through cloudflared_api_base_url, a stub binary stands in for the daemon, and the releases come from file:// URLs. Covers the converge with an update through _binary_update and its idempotence, the rendered files and the running unit, the input asserts, the deleted-tunnel and DNS guards, a stale hash and a failed checksum, the mint entry point (as child processes outside CI) and the remove path. The cloudflare_dns calls cannot reach the stub and are not run. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
e308683431
commit
9a626962a5
8 files changed
+831
No files matched your search
@@ -0,0 +1,87 @@
|
||||
---
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image
|
||||
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No Cloudflare and no real
|
||||
# cloudflared: prepare.yml starts a stub of the Cloudflare API on the controller's loopback
|
||||
# (files/cloudflare_api_stub.py, reached through cloudflared_api_base_url; cleanup.yml stops it)
|
||||
# and seeds a stub cloudflared binary that reports an older version, so the update downloads its
|
||||
# new stub from local file:// URLs. The scenario downloads nothing. cloudflared_manage_dns is
|
||||
# false here because community.general.cloudflare_dns cannot be pointed at the stub; the DNS
|
||||
# guards in front of it are run with it true in verify.yml.
|
||||
# The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: cloudflared-instance
|
||||
image: ${MOLECULE_IMAGE}
|
||||
pre_build_image: true
|
||||
pull: true
|
||||
command: /sbin/init
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play, so a verify play that runs the role again renders the same
|
||||
# configuration.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
# The stub binary; @VERSION@ is replaced per release file. Its hash is the configured
|
||||
# sha256, so the release files need no checksum file.
|
||||
cloudflared_test_stub: |
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
--version) echo "cloudflared version @VERSION@ (built 2026-01-01-0000 UTC)" ;;
|
||||
tunnel)
|
||||
[ "$2" = --config ] || { echo "stub cloudflared: expected --config" >&2; exit 2; }
|
||||
case "$4" in
|
||||
ingress) grep -q 'service: http_status:404' "$3" && { echo "Validating rules from $3"; exit 0; } ;;
|
||||
run) [ -r "$3" ] && exec sleep infinity ;;
|
||||
esac
|
||||
echo "stub cloudflared: cannot handle: $*" >&2; exit 1 ;;
|
||||
*) echo "stub cloudflared: unexpected arguments: $*" >&2; exit 2 ;;
|
||||
esac
|
||||
cloudflared_test_stub_dir: "{{ lookup('ansible.builtin.env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/cloudflare-stub"
|
||||
cloudflared_test_tunnel_id: 6f1a6e2c-0000-4000-8000-000000000001
|
||||
cloudflared_test_credentials_json: >-
|
||||
{"AccountTag": "molecule-account", "TunnelID": "6f1a6e2c-0000-4000-8000-000000000001", "TunnelSecret": "bW9sZWN1bGU="}
|
||||
cloudflared_version: "2026.2.0"
|
||||
cloudflared_sha256_amd64: "{{ cloudflared_test_stub | replace('@VERSION@', cloudflared_version) | hash('sha256') }}"
|
||||
cloudflared_download_url: "file:///opt/molecule-download/cloudflared-{{ cloudflared_version }}"
|
||||
cloudflared_api_base_url: >-
|
||||
http://127.0.0.1:{{ lookup('ansible.builtin.file', cloudflared_test_stub_dir ~ '/port') }}/client/v4
|
||||
cloudflared_account_id: molecule-account
|
||||
cloudflared_tunnel_api_token: molecule-not-a-token
|
||||
cloudflared_tunnel_id: "{{ cloudflared_test_tunnel_id }}"
|
||||
cloudflared_credentials_json: "{{ cloudflared_test_credentials_json }}"
|
||||
cloudflared_manage_dns: false
|
||||
cloudflared_ingress: "{{ cloudflared_test_ingress }}"
|
||||
cloudflared_test_ingress:
|
||||
- hostname: app.example.test
|
||||
service: https://127.0.0.1:443
|
||||
originRequest:
|
||||
originServerName: app.example.test
|
||||
- hostname: other.example.test
|
||||
service: http://127.0.0.1:8080
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container before the
|
||||
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
|
||||
# After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
Reference in new issue
Block a user