Skip to main content

libvirt Molecule Plugin :: run molecule tests on libvirt

Project description

PyPI Package CI Status Ruff Code Style Repository License

Molecule libvirt-ng is a Molecule driver for provisioning test VMs via libvirt/QEMU/KVM.

This is a modernized fork of the archived molecule-libvirt plugin, updated for current versions of Molecule and Ansible.

Requirements

  • Python >= 3.10

  • Molecule >= 24.2.0

  • Ansible >= 2.16

  • A working libvirt/QEMU/KVM setup on the host

  • libvirt-python (system package or built from source with pkg-config and libvirt headers)

  • virt-resize from guestfs-tools (for disk resizing)

Required Ansible collections (installed automatically via test_requirements.yml):

  • community.libvirt

  • community.crypto

  • community.general

  • ansible.posix

  • ansible.utils

Quickstart

Installation

pip install molecule-libvirt-ng

You also need libvirt-python which requires system libvirt headers:

# Debian/Ubuntu
sudo apt install libvirt-dev pkg-config python3-dev

# RHEL/Fedora
sudo dnf install libvirt-devel pkg-config python3-devel

pip install libvirt-python

Install the required Ansible collections:

ansible-galaxy collection install -r test_requirements.yml

Example

Create a molecule/default/molecule.yml in your Ansible role:

---
driver:
  name: libvirt

platforms:
  - name: debian12-test
    image_url: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
    memory_size: 2
    vcpu: 2
    disk_size: "10G"
    qemu_user: "qemu"

provisioner:
  name: ansible

verifier:
  name: ansible

Then run:

molecule test

Platform Parameters

Required

image_url

URL to a cloud image (qcow2 format). Defaults to Debian 12 genericcloud.

Optional

memory_size

RAM in GB. Default: 1.

vcpu

Number of virtual CPUs. Default: 1.

disk_size

Disk size (qemu-img format). Default: 15G.

ssh_port

SSH port on the guest. Default: 22.

cpu_model

CPU model requested by the guest. Default: qemu64.

arch

CPU architecture. Default: x86_64.

timezone

VM timezone. Default: America/Toronto.

qemu_user

QEMU process user for filesystem ACLs. Varies by distro:

  • RHEL/Fedora: qemu (default)

  • Debian/Ubuntu: libvirt-qemu

  • NixOS: root

image_volume

Partition to expand with virt-resize. Default: /dev/sda1.

network_name

Use an existing libvirt network instead of creating a molecule-managed one.

bridge_name

Use an existing bridge on a remote host. Makes the VM reachable via ARP.

libvirt_host and libvirt_user

Provision VMs on a remote libvirt host via qemu+ssh://.

Network Parameters

These apply when molecule manages its own network (no network_name or bridge_name):

molecule_bridge

Bridge interface name. Default: molecule-br0.

molecule_network_cidr

IP range for the molecule network. Default: 10.10.10.0/24.

Documentation

Read the Molecule documentation at https://molecule.readthedocs.io/.

Authors

Original authors:

  • James Regis

  • Gaetan Trellu

  • Gariele Cerami

  • Sorin Sbarnea

License

The MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molecule_libvirt_ng-1.0.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molecule_libvirt_ng-1.0.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file molecule_libvirt_ng-1.0.1.tar.gz.

File metadata

  • Download URL: molecule_libvirt_ng-1.0.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for molecule_libvirt_ng-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8d821cf23c2314bebf6bb2724ae07cc2f8f21e529dfd5122456ffce8eca2fdcc
MD5 a913a5f730ca42c966584401c2cdeedc
BLAKE2b-256 363f8cd168e7d864fa15674a059d92f4f1647a2b060ba56f2d7e80e46b271734

See more details on using hashes here.

File details

Details for the file molecule_libvirt_ng-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for molecule_libvirt_ng-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5cfbb11a14f7b1bc0aec8c2530ac5ef3c30450e7dee46f013b051c73c0101b7f
MD5 6e1cfd7fed17893a1f8615d6ee2c8be2
BLAKE2b-256 d934ad0f8aeb8855b0170772967009daa0e891f5b95553b29c4e9bb527e92902

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page