Skip to content

About

Test Kitchen driver for UTM on macOS

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

kitchen-utm

Run Test Kitchen instances in UTM on macOS. Use native-architecture Linux boxes with Kitchen's SSH transport or a prepared Windows ARM64 QEMU box with an explicit endpoint. It uses UTM's AppleScript import and the utmctl lifecycle commands.

Requirements

  • UTM 5.0.9 in a logged-in macOS session with Automation access.
  • Ruby 3.1 or newer and Test Kitchen 4.2.1.
  • A trusted Vagrant box for provider utm with native architecture metadata, a single UTM bundle and a working guest transport account. For automatic address discovery, use a QEMU guest with its guest agent running and a host-reachable network.

Install a locally built gem into the Ruby environment that runs kitchen. From this checkout, use bundle install, bundle exec rake and gem build kitchen-utm.gemspec.

Local smoke test

Put this in a cookbook's kitchen.yml, adjust the box path, and configure the supplied guest's credentials through Kitchen's SSH transport.

driver:
  name: utm
  box: /path/to/linux-utm-arm64.box
transport:
  name: ssh
  username: vagrant
provisioner:
  name: shell
platforms:
  - name: linux
suites:
  - name: default

Run kitchen create, kitchen login and kitchen destroy. Use kitchen converge with a provisioner configured for your project. Set driver.ssh_host and optionally driver.ssh_port for a known reachable endpoint. For a separate UTM installation, set driver.utmctl to its executable or a symlink to it. An executable wrapper outside an app bundle uses the default UTM app for AppleScript.

For a retained manifest, set driver.box_manifest and replace the local path with a map containing the exact box name and version. Kitchen selects and verifies the native UTM archive using its shared box cache.

With a Test Kitchen version that supports live driver status, run kitchen list --live to see the UTM state for instances in the current project. The driver queries UTM by the recorded VM UUID, so a renamed VM still appears. An unavailable or invalid UTM inventory reports an unknown status.

For guest-agent discovery, driver.ip_timeout sets the deadline for finding a reported IPv4 address whose SSH port accepts a TCP connection from the Mac. Set driver.ssh_port or the SSH transport's port for a non-default SSH port. Kitchen's SSH transport handles authentication and connection retries.

Remote box archives

With a Test Kitchen version that supports direct remote box URLs, set box_url for a platform or inherit a shared box_url_template. Replace the example server with your archive host and match the template to its URL layout. The template uses the exact version from each platform's driver settings.

driver:
  name: utm
  box_server: https://boxes.example.com
  box_namespace: bento
  box_url_template: "%{server}/%{namespace}/boxes/%{platform}/versions/%{version}/providers/%{provider}/%{arch}/vagrant.box"
platforms:
  - name: ubuntu-24.04
    driver:
      box_version: "202510.26.0"

A platform's explicit box_url overrides the template. Set box_sha256 when you have the archive's expected SHA-256, or box_bytes to check the file size. Test Kitchen handles the download and cache, and UTM imports the archive.

Package a prepared VM for local reuse

Shut down a VM you prepared as a template. Keep its boot disks inside the UTM bundle. UTM export copies guest data and settings, including credentials, machine IDs and SSH host keys. Review those before sharing the box or running multiple copies.

For a stopped, Kitchen-managed QEMU VM, run kitchen snapshot export INSTANCE on Test Kitchen builds that expose the snapshot command. On builds that expose shared box publication as package, run kitchen package INSTANCE.

The driver reads the guest architecture from UTM and writes INSTANCE.box in the Kitchen project with private permissions. An existing output is preserved. The staged copy drops fixed network port forwards, so each import can choose its own SSH endpoint. Packaging rejects host paths, mounted external media, bridged adapters, TCP serial ports, custom QEMU arguments and dependent QCOW disks.

For Test Kitchen builds without shared box publication, or for a VM managed directly in UTM, use the manual recipe below. Review the resulting bundle for machine-specific settings, including port forwards and paths.

Set VM_UUID to the stopped VM's ID from /Applications/UTM.app/Contents/MacOS/utmctl list. This example uses an arm64 box. Set BOX_ARCH=amd64 for an Intel box.

(
  set -eu
  umask 077
  test ! -e prepared.box && test ! -L prepared.box || exit 1
  staging=$(mktemp -d "$PWD/utm-package.XXXXXXXX")
  trap 'rm -rf -- "$staging"' EXIT

  osascript - "$VM_UUID" "$staging/box.utm" <<'APPLESCRIPT'
on run argv
  set vmID to item 1 of argv
  set destination to POSIX file (item 2 of argv)
  tell application id "com.utmapp.UTM"
    set targetVM to virtual machine id vmID
    if status of targetVM is not stopped then error "Stop the VM before exporting"
    with timeout of 300 seconds
      export targetVM to destination
    end timeout
  end tell
end run
APPLESCRIPT

  printf '{"provider":"utm","architecture":"%s"}\n' "${BOX_ARCH:-arm64}" > "$staging/metadata.json"
  COPYFILE_DISABLE=1 tar -czf "$staging/prepared.box" -C "$staging" metadata.json box.utm
  /bin/link "$staging/prepared.box" prepared.box
)

Set driver.box to the resulting archive in another Kitchen project and run kitchen create. The driver assigns the imported VM a fresh UTM UUID.

VM sizing

Set driver.cpus and driver.memory to override the box's CPU count and RAM in MiB. Both settings accept positive integers and can be set per platform or suite. Omitted values retain the box defaults when creating a VM.

platforms:
  - name: almalinux-10
    driver:
      cpus: 2
      memory: 1536

Synced folders

A QEMU Linux guest can mount one host directory through VirtFS. The guest needs the QEMU guest agent, 9p kernel support and the usual Linux mount utilities. Use a dedicated, empty guest mount directory. driver.ip_timeout sets how long Kitchen waits for the guest agent and mount.

driver:
  synced_folders:
    - ["./fixtures", "/mnt/fixtures", { readonly: true }]

Host paths are relative to the Kitchen project. Use %{instance_name} in the path to give each guest its own directory. Use create: true to create a missing host directory or disabled: true to skip an entry. Shares are writable by default. Use a dedicated directory and set readonly: true if the guest only needs to read it.

Destroy and recreate the VM to change the share configuration. Destroy preserves the host directory and its contents.

Additional test disk

Set driver.disk_size_mib to attach one unformatted VirtIO disk to a QEMU VM before its first boot. Use a positive integer in MiB. A stopped VM gets a disk created by UTM inside its own bundle. The box's existing drives stay attached. Kitchen destroys the test disk with the VM.

Destroy and recreate to change the configured initial size or add a test disk to an existing VM. If Kitchen reports an interrupted attachment, destroy the instance before retrying.

To grow an attached test disk, stop the VM and call instance.driver.resize_disk(state, size_mib) with the new total size and the instance's Kitchen state. Keep driver.disk_size_mib at its original create-time value. UTM grows the owned QCOW2 image and rejects shrinking. Partition and filesystem growth are guest provisioning tasks.

Kitchen checks the UTM drive ID and the file identity recorded at attachment. A VM with an older attachment record or a replaced image must be recreated before disk growth.

Removable ISO at boot

Set driver.boot_iso: ./seed.iso to attach one local ISO as read-only removable media on a QEMU VM before it boots. Relative paths start at the Kitchen project root. Keep the file available for the life of the VM. Kitchen keeps the box's existing drives and reuses a matching ISO attachment on retry.

Destroy and recreate the instance to change the configured ISO. Destroy preserves the host file. The guest decides how it uses the media. For a NoCloud seed, use a guest image with cloud-init enabled and configured to read an ISO labelled CIDATA. UTM 5.0.9 presents the ISO through VirtIO SCSI on QEMU arm64 virt machines so cloud-init can find it during boot.

Headless QEMU guests

Set driver.headless: true to run a QEMU guest without a display window. Kitchen removes display devices and built-in serial terminals from the prepared VM. Other serial devices, such as pseudo-TTYs, remain available. UTM must stay open while the guest runs.

The default preserves the box's display and serial configuration. Destroy and recreate an existing instance to change this setting.

Host-only networking

Set driver.network_mode: host-only to give a QEMU guest one UTM host-only adapter. Kitchen replaces the box's inherited adapters and forwarding rules. On UTM 5.0.9, guests received DHCP addresses, could reach each other and accept connections from the Mac, and timed out at an external IPv4 TCP endpoint the Mac could reach.

Use guest-agent SSH discovery or set driver.ssh_host to the guest's reachable address. The host-only adapter cannot use driver.ssh_forward_port. The box must have a network adapter so Kitchen can reuse its hardware type. Extra QEMU arguments can bring up networking independently, so Kitchen rejects them in this mode.

The default inherit mode keeps the box's network topology. In host-only mode, Kitchen checks the VM's adapters and extra QEMU arguments before boot. Destroy and recreate an existing instance to change modes.

Bridged networking

Set driver.network_mode: bridged and driver.bridge_interface to the name of a macOS interface eligible for vmnet bridging, such as en0 when available. Kitchen replaces the box’s adapters and forwarding rules with one bridged adapter. The guest joins the network of the selected interface.

driver:
  network_mode: bridged
  bridge_interface: en0

Use guest-agent SSH discovery or set driver.ssh_host to a known reachable guest address. The bridge cannot use driver.ssh_forward_port. Kitchen checks that macOS can bridge the interface and that the registered VM uses it before starting. Destroy and recreate to change the interface. Extra QEMU arguments are incompatible with this mode.

SSH over a forwarded port

For a QEMU box with an Emulated VLAN network adapter, set driver.ssh_forward_port to forward a local TCP port on 127.0.0.1 to guest port 22. Kitchen uses that endpoint without guest-agent IP discovery. Use a distinct, available port for each concurrently running instance.

suites:
  - name: default
    driver:
      ssh_forward_port: 23221
  - name: second
    driver:
      ssh_forward_port: 23222

Configure authentication in the SSH transport. Leave driver.ssh_host and driver.ssh_port unset for forwarded instances. Destroy and recreate an existing instance to change its port.

Kitchen can prepare multiple instances with kitchen create all --concurrency=2. The driver sends one start request at a time to the shared UTM process for the current macOS user. Box preparation and guest readiness checks can overlap, and both guests can run together after startup.

Windows ARM64 with WinRM

Use a prepared Windows ARM64 QEMU box with a working network adapter and an enabled WinRM listener. UTM's Windows Guest Tools include the NetKVM driver for the VirtIO network adapter. See the UTM guest tools instructions.

For an Emulated VLAN, configure the box to forward a dedicated loopback TCP port to guest port 5985. The example uses host port 25985. Set driver.ssh_host and driver.ssh_port to that endpoint. Despite their names, these two settings provide the host and port to Kitchen's selected transport. The driver.ssh_forward_port shorthand always forwards to guest port 22.

driver:
  name: utm
  box: /path/to/windows-utm-arm64.box
  headless: true
  ssh_host: 127.0.0.1
  ssh_port: 25985
transport:
  name: winrm
  username: <%= ENV.fetch("KITCHEN_WINRM_USER").to_json %>
  password: <%= ENV.fetch("KITCHEN_WINRM_PASSWORD").to_json %>
provisioner:
  name: dummy
platforms:
  - name: windows-arm64
    os_type: windows
suites:
  - name: default

Use kitchen create, then run kitchen exec default-windows-arm64 -c 'Write-Output "ready"' to check PowerShell through WinRM. Run kitchen destroy when finished.

For Windows OpenSSH, use the SSH transport with an endpoint that reaches guest port 22. For RDP, give the box a separate loopback forward to guest port 3389. Set the WinRM transport's rdp_port to that host port. On macOS, kitchen login hands an RDP file to the app associated with that file type.

Concurrent lifecycle commands

When Test Kitchen supplies the with_instance_lifecycle hook, UTM locks each project instance across processes before Kitchen reads its saved state. Each create, converge, verify or destroy transition holds the lock through its state updates and hooks. Different instances keep separate locks. kitchen test can release the lock between transitions. A lifecycle hook must avoid calling Kitchen for the same instance from inside the transition.

Driver power operations

The driver exposes suspend(state) and resume(state) for a Kitchen instance with a recorded UTM UUID. Suspend pauses a running guest in memory. Resume continues that guest from its paused state. Repeat requests for the same state succeed without a second UTM call. The driver keeps the instance's saved lifecycle and SSH settings so Kitchen can reconnect after resuming.

halt(state) asks a running guest to shut down and waits for UTM to report that it stopped. Set driver.graceful_halt_timeout to change the default deadline of 60 seconds. Kitchen reports an error when the guest does not stop by the deadline. Resume a paused guest before halting it.

reload(state) halts the existing VM, applies the configured CPU and memory overrides, restarts the same VM and refreshes its SSH endpoint. Omitted settings retain the stopped VM's current values. A caller persisting Kitchen state should save the updated endpoint after a successful reload.

reboot(state) resolves the SSH endpoint for a running systemd Linux guest before requesting reboot, then reconnects and checks for a new boot ID. It requires the SSH account to be able to run systemd-run with passwordless sudo. Use driver.reboot_timeout to change the 180-second deadline for scheduling the reboot and reconnecting. The caller can persist the refreshed SSH endpoint after success.

Automatic address discovery also requires a working QEMU guest agent. The driver compares the SSH endpoint's boot ID with the boot ID read from the managed UTM VM before submitting the reboot and after reconnecting.

Driver snapshot interface

For an existing Kitchen instance, call instance.driver.save_snapshot(name), list_snapshots, restore_snapshot(id) or delete_snapshot(id). Save and list return snapshot records with an ID, display name, running state flag and missing data flag. Restore and delete take the snapshot ID from those records.

Snapshot operations use UTM's AppleScript interface. See the UTM snapshot requirements for supported backends and guest disk types. Shut down the VM before restoring and wait for any other Kitchen action on the same instance to finish. Restore clears Kitchen's recorded action and SSH endpoint. Run kitchen create on the same instance to start it again and resolve its endpoint.

Release status

The first public release requires a published Test Kitchen with shared remote-box support and a gemspec that requires that version or newer. A locally built gem is a development artifact.

About

Test Kitchen driver for UTM on macOS

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages