Resetting Infrastructure Tests with Multipass Snapshots
How I use local Ubuntu VMs and a saved baseline to repeat deployment tests without carrying failed state into the next run.

On this page
Audio edition
0:00 / 7:32
Ready
A failed infrastructure test can change the next test before it even starts.
The first run may leave containers, files, database directories, firewall rules, or reverse-proxy configuration behind. If the second run begins on that machine, its result now depends on both the code under test and the residue from the first attempt. A failure may disappear because a required package is already installed, or appear because an old process still owns a port.
I wanted a shorter, more trustworthy loop for testing deployment tooling: establish a known machine state, run the test, then return to that state without writing cleanup logic for every possible partial failure.
Local virtual-machine snapshots provided that reset point. I wrapped Multipass in a small manager for the lifecycle I needed: create, snapshot, test, restore, and destroy.

Why cleanup scripts were the wrong boundary
Tools such as Kamal and Coolify manage a host, not just one process. A test can cross SSH, package installation, Docker, networking, storage, and service configuration. A cleanup script has to know every change the tool might have made, including the partial changes from paths that failed.
That makes cleanup a poor definition of a clean test fixture. It only reverses state I remembered to list.
There are other useful boundaries, but they answer different questions:
- A disposable cloud VM is closer to the final environment, but every reset includes provider provisioning and may carry a cost.
- A container is quick to replace, but it does not reproduce the VM boundary for a tool that installs or manages the host’s container runtime.
- A hand-maintained test server is convenient until previous work becomes an undocumented input to the next run.
A local VM is not production. Provider networking, metadata services, storage, firewalls, CPU architecture, and performance can all differ. I use this loop for fast functional testing, then keep a smaller final check on the real target environment when those differences matter.
Put the snapshot at the boundary you are testing
Multipass creates cloud-style Ubuntu VMs on Linux, macOS, and Windows . Its snapshots record the mutable instance state, including disk contents and VM configuration. Restoring one is therefore broader than removing a container or rerunning a cleanup script.
The useful baseline depends on the test:
- To test application deployment, commission the VM first, then snapshot the state with Docker, firewall defaults, and any deployment agent already present.
- To test commissioning itself, snapshot an earlier state or create a fresh VM. A post-commissioning snapshot would skip the behavior under test.
For my deployment loop, the post-commissioning state was the useful starting line.

The resulting sequence is:

- Create the Ubuntu VMs.
- Commission them to the chosen baseline.
- Stop them and take a named snapshot.
- Run the deployment test.
- Stop, restore, and restart the VMs.
- Repeat the test, or destroy the environment when finished.
The important decision is step 2. A snapshot is useful only when I can say what it contains and why that is the correct starting state.
What the manager automates

The manager creates three Ubuntu VMs by default because I wanted a multi-node environment. That number is configuration, not a general recommendation; one VM is enough for a single-host deployment.
It also handles the repeated host-side work:
- generates a dedicated Ed25519 SSH keypair under
.multipass-state/; - injects the public key for the VM’s
ubuntuuser; - records the VM names for later cleanup;
- prints addresses and can add project-specific entries to
~/.ssh/config; - takes a
cleansnapshot for each VM; and - removes the tracked VMs and local state on destruction.
Creating the environment is one command:
./multipass-manager.sh create
The script launches deploy1, deploy2, and deploy3, creates the keypair when needed, injects the public key, and prints connection details. The defaults are easy to change near the top of the script:
VM_PREFIX="deploy"
NUM_VMS=3
MEMORY="1G"
CPUS=1
DISK="20G"
UBUNTU_VERSION="24.04"
SNAPSHOT_NAME="clean"
After commissioning, the wrapper stops the VMs, replaces any previous clean snapshots, takes new snapshots, and starts the VMs again:
./multipass-manager.sh snapshot
Multipass requires an instance to be stopped when taking or restoring a snapshot. Its current restore command also asks whether to preserve the state being discarded. For an intentional, non-interactive reset, the underlying sequence should be explicit:
multipass stop deploy1
multipass restore --destructive deploy1.clean
multipass start deploy1
The --destructive restore option
means exactly what it says: the state since the snapshot is discarded without creating another snapshot first. It belongs only in a loop where clean is a confirmed disposable baseline.
The linked manager script
captures the lifecycle and supporting SSH work, but its current restore helper does not implement this stricter command sequence: it calls multipass restore without first stopping the VM or passing --destructive. I would update that function before using it unattended, and make it fail the run if any restore fails. The command output should not be the only evidence that the environment is clean.
Verify the baseline after a restore
A snapshot removes the need to enumerate every cleanup action, but it does not remove the need for a postcondition.
The check should be small and specific to the baseline. For example, confirm that the expected VMs are running, the intended ports respond, and test containers or application directories are absent. If the baseline includes Docker or an agent, confirm those services are ready before starting the next deployment.
The manager includes an ssh-update command because VM addresses may change after a host or VM restart:
./multipass-manager.sh ssh-update
Its generated SSH entries disable host-key checking for these local, disposable VMs. That is convenient for a reset loop, but it removes SSH’s server-identity check. I would not reuse those entries, keys, or settings for production hosts. The script also prints the private key for transfer into a deployment tool, so the state directory should remain local and disposable.
When the test environment is no longer useful, the destructive cleanup is deliberate:
./multipass-manager.sh destroy
The command deletes the managed VMs, purges their snapshots, removes the generated SSH block, and deletes .multipass-state/ after confirmation.
What snapshots solve—and what they do not
The main improvement is not that Multipass makes infrastructure tests identical to production. It does not. The improvement is that consecutive local tests can begin from the same declared machine state.
Snapshots are also not backups. Multipass stores them with the instance data
, and long snapshot chains can reduce performance. In this workflow, clean is a disposable test baseline that can be recreated, not a durable copy of anything important.
That narrower promise is enough to change the loop. When a deployment fails halfway through, I can preserve the failed VM while it is useful for diagnosis, then discard that state and repeat from a baseline I chose in advance. The next result no longer depends on how complete my cleanup script happened to be.



