- Python 95.4%
- Jinja 4.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
qemu_vm and qemu_lab take the port sshd listens on inside the guest (default 22), for guests whose first-boot configuration moves it - the site repository's anchor and identity scenarios run sshd on another port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVUe4g65L7UnUVqHmQp7kG |
||
| .forgejo/workflows | ||
| changelogs | ||
| extensions/molecule | ||
| meta | ||
| plugins | ||
| roles/qemu_lab | ||
| tests/unit/plugins | ||
| .ansible-lint | ||
| .copier-answers.yml | ||
| .gitignore | ||
| .gitleaks.toml | ||
| .pre-commit-config.yaml | ||
| .yamllint | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| galaxy.yml | ||
| LICENSE | ||
| README.md | ||
| ruff.toml | ||
| SECURITY.md | ||
belowtoxic.testing
Unprivileged QEMU lab for Molecule: boots Debian, Ubuntu and Flatcar VMs as an ordinary user, wires them into multi-VM topologies with point-to-point links, and hands them to Molecule. No libvirt, no bridges, no root.
Part of belowtoxic-ansible.
Content
| Name | Type | Purpose |
|---|---|---|
belowtoxic.testing.qemu_lab |
role | tasks_from: create / destroy for Molecule's managed driver |
belowtoxic.testing.qemu_vm |
module | Start/stop one QEMU VM (slirp management NIC with SSH forward, UDP links, cloud-init seed, fw_cfg) |
belowtoxic.testing.free_ports |
module | Free TCP+UDP ports on 127.0.0.1 |
belowtoxic.testing.lab_links |
filter | Wire link names of Molecule platforms to UDP port pairs |
belowtoxic.testing.lab_mac |
filter | Deterministic MAC of a lab VM's NIC |
How a lab looks
controller (127.0.0.1)
ssh :p1 │ │ ssh :p2 management: QEMU user networking
┌──────┴───┐ ┌────┴─────┐ (DHCP, NAT, SSH port forward)
│ upstream │───│ hv │ links: UDP socket pairs on 127.0.0.1,
└──────────┘ ↑ └──────────┘ one virtio NIC per link, no DHCP
link "uplink"
- Images are downloaded once per machine into
~/.cache/belowtoxic-testing/imagesand verified against the distribution's checksum list (DebianSHA512SUMS, UbuntuSHA256SUMS, Flatcar.DIGESTS). - Debian/Ubuntu get a cloud-init NoCloud seed (user
ansible, passwordless sudo; the management NIC is renamedmgmt0where the distribution allows it at first boot - Ubuntu 26.04 keeps its predictable name). Flatcar gets an Ignition config viafw_cfg(usercore). - Every NIC has a deterministic MAC (
lab_mac), so tests find interfaces by MAC; the inventory getsqemu_lab_macs: {mgmt: ..., <link>: ...}per host. - KVM is used when
/dev/kvmis usable, otherwise QEMU falls back to TCG emulation (slow, but works).
Using it in a scenario
requirements.yml of the collection under test (or extensions/molecule/requirements.yml):
collections:
- name: https://git.belowtoxic.cloud/belowtoxic-ansible/collection-testing.git
type: git
version: v0.1.0
molecule.yml:
driver:
name: default
options:
managed: true
platforms:
- name: upstream
image: debian-13 # debian-13, ubuntu-24.04, ubuntu-26.04, flatcar-stable
links: [uplink]
- name: hv
image: debian-13
memory: 2048
cpus: 2
links: [uplink]
groups: [hypervisors]
cloud_init: # merged into the generated cloud-config
packages: [nftables]
provisioner:
name: ansible
playbooks:
create: ../shared/create.yml
destroy: ../shared/destroy.yml
shared/create.yml (and destroy.yml with tasks_from: destroy):
- name: Create lab
hosts: localhost
gather_facts: false
tasks:
- name: Create QEMU lab VMs
ansible.builtin.include_role:
name: belowtoxic.testing.qemu_lab
tasks_from: create
vars:
qemu_lab_platforms: "{{ molecule_yml.platforms }}"
Flatcar platforms accept ignition: - an Ignition config (dict) merged into
the generated one. Flatcar has no Python: use ansible.builtin.raw in
verify.yml.
See roles/qemu_lab/README.md for all variables,
and extensions/molecule/ for working examples (two linked VMs; Flatcar).
Host requirements
qemu-system-x86_64, qemu-img, xorriso, ssh, and ideally read/write
access to /dev/kvm (user in group kvm). In CI, bt-ci molecule runs the
scenarios inside the toolchain container (with /dev/kvm passed through)
when the host lacks these but has docker.
Development
eval "$(../toolchain/bin/bt-ci-setup)"
bt-ci lint && bt-ci sanity && bt-ci units
bt-ci molecule default # two linked VMs, ~3 min with KVM
bt-ci molecule flatcar # Flatcar via Ignition
License
GPL-3.0-or-later, see LICENSE.