From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH e2e-tests 36/38] tests: migration: verify VM migration with local disks
Date: Wed, 4 Nov 2026 20:03:43 +0100 [thread overview]
Message-ID: <20261104190345.2573464-37-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20261104190345.2573464-1-m.koeppl@proxmox.com>
Live migrate a VM with a disk on node-local ZFS storage to another node
onto local-lvm and back onto ZFS, then migrate the stopped VM to the
other node again. Check that the disk is moved to the target storage
each time, that no volume is left behind and that its content stays the
same. A live migration without allowing local disks must fail and leave
the VM running on its node.
The offline migration keeps the disk on ZFS if the disk cannot be
converted in a format both storages support. The disk content is
compared by checksum on the node.
Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
tests/pve_vm_migration_local_disks.pl | 213 ++++++++++++++++++++++++++
tests/testcases.ron | 11 ++
2 files changed, 224 insertions(+)
create mode 100755 tests/pve_vm_migration_local_disks.pl
diff --git a/tests/pve_vm_migration_local_disks.pl b/tests/pve_vm_migration_local_disks.pl
new file mode 100755
index 0000000..55d2e14
--- /dev/null
+++ b/tests/pve_vm_migration_local_disks.pl
@@ -0,0 +1,213 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+C<pve_vm_migration_local_disks> - Test migrating a VM with local disks between cluster nodes.
+
+=head1 DESCRIPTION
+
+This testcase creates a VM with a disk on the node-local ZFS storage of the first
+cluster node, writes random data to the disk and records its checksum. The
+migration preconditions must report the disk as local.
+
+It starts the VM, and a live migration without allowing the migration of local
+disks must fail, leaving the VM running on the first node. A live migration with
+local disks to the second node, onto its local-lvm storage, must move the VM and
+its disk, and so must a live migration back onto the ZFS storage. After stopping
+the VM, an offline migration to the second node must move it to the storage with
+the same storage ID. The disk must have the original content after each
+migration, and no volume may be left behind on the source node.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib '.';
+use Proxmox::Test::Helper qw(get_pve_instance);
+use Proxmox::Test::Testcase;
+use Proxmox::Test::Util qw(poll_until);
+
+my $pve_a = get_pve_instance('pve1-cluster');
+my $pve_b = get_pve_instance('pve2-cluster');
+my $node_a = $pve_a->get_nodename();
+my $node_b = $pve_b->get_nodename();
+my $client = $pve_a->client();
+
+my $zfs_storage = 'zfstest';
+
+my $vmid;
+my $checksum;
+
+# The node the VM lives on according to the cluster resources. undef if the node could not be
+# determined.
+my $resource_node = sub {
+ my $resources = $client->get('/cluster/resources', { type => 'vm' });
+ my ($entry) = grep { ($_->{vmid} // 0) == $vmid } $resources->@*;
+ return $entry ? $entry->{node} : undef;
+};
+
+my $disk_volid = sub {
+ my ($node) = @_;
+ my $conf = $client->get("/nodes/$node/qemu/$vmid/config", {});
+ my ($volid) = ($conf->{scsi0} // '') =~ m/^([^,]+)/;
+ return $volid;
+};
+
+my $volumes_on = sub {
+ my ($node, $storage) = @_;
+ my $content = $client->get("/nodes/$node/storage/$storage/content", { vmid => $vmid });
+ return { map { $_->{volid} => 1 } $content->@* };
+};
+
+my $disk_checksum = sub {
+ my ($instance) = @_;
+ my $volid = $disk_volid->($instance->get_nodename());
+ my ($path) = $instance->run_command("pvesm path $volid");
+ chomp($path);
+ my ($out) = $instance->run_command("sha256sum $path");
+ my ($sum) = split(/\s+/, $out // '');
+ return $sum;
+};
+
+my $migrate = sub {
+ my ($instance, $params) = @_;
+ my $node = $instance->get_nodename();
+ return $instance->client()->post("/nodes/$node/qemu/$vmid/migrate", $params);
+};
+
+my $verify_location = sub {
+ my ($instance, $storage, $source, $source_storage) = @_;
+ my $node = $instance->get_nodename();
+
+ poll_until(
+ sub { ($resource_node->() // '') eq $node },
+ timeout => 60,
+ description => "VM $vmid to show up on node $node",
+ );
+ pass("VM $vmid is on node $node");
+
+ my $volid = $disk_volid->($node);
+ like($volid // '', qr/^\Q$storage\E:/, "disk is on $storage");
+ ok($volid && $volumes_on->($node, $storage)->{$volid}, "disk volume exists on node $node");
+ is_deeply(
+ $volumes_on->($source->get_nodename(), $source_storage),
+ {},
+ 'no volume is left on the source node',
+ );
+ is($disk_checksum->($instance), $checksum, 'disk has the original content');
+};
+
+Proxmox::Test::Testcase->new('pve_vm_migration_local_disks')->with([{}])->step(
+ 'create VM with a local disk',
+ sub {
+ $vmid = $client->get('/cluster/nextid');
+ my $upid = $client->post(
+ "/nodes/$node_a/qemu",
+ {
+ vmid => $vmid,
+ name => 'vm-migration-local-disks',
+ memory => 256,
+ scsihw => 'virtio-scsi-pci',
+ scsi0 => "$zfs_storage:1",
+ },
+ );
+ $pve_a->task_ok($upid, "created VM $vmid on node $node_a")
+ or die "creating VM $vmid failed\n";
+ },
+ sub {
+ my $node = $resource_node->();
+ $pve_a->destroy_guest_on($node, 'qemu', $vmid) if defined($node);
+ },
+)->step(
+ 'write data to the disk',
+ sub {
+ my ($path) = $pve_a->run_command('pvesm path ' . $disk_volid->($node_a));
+ chomp($path);
+ $pve_a->run_command("dd if=/dev/urandom of=$path bs=1M count=8 seek=16 conv=notrunc");
+
+ $checksum = $disk_checksum->($pve_a);
+ ok($checksum, 'recorded the checksum of the disk');
+ },
+)->step(
+ 'check migration preconditions',
+ sub {
+ my $precondition = $client->get("/nodes/$node_a/qemu/$vmid/migrate", {});
+ my $volid = $disk_volid->($node_a);
+ ok(
+ (grep { $_->{volid} eq $volid } ($precondition->{local_disks} // [])->@*),
+ 'disk reported as local',
+ );
+ },
+)->step(
+ 'live migration needs to allow local disks',
+ sub {
+ $pve_a->start_guest('qemu', $vmid);
+
+ my $upid = $migrate->($pve_a, { target => $node_b, online => 1 });
+ ok(
+ !$pve_a->task_successful($pve_a->wait_for_task($upid, 1)),
+ 'live migration without local disks allowed fails',
+ );
+ is($resource_node->(), $node_a, "VM $vmid stays on node $node_a");
+ is(
+ $client->get("/nodes/$node_a/qemu/$vmid/status/current", {})->{status},
+ 'running',
+ "VM $vmid keeps running",
+ );
+ },
+)->step(
+ 'live migrate VM with local disk to another storage',
+ sub {
+ my $upid = $migrate->(
+ $pve_a,
+ {
+ target => $node_b,
+ online => 1,
+ 'with-local-disks' => 1,
+ targetstorage => 'local-lvm',
+ },
+ );
+ $pve_a->task_ok($upid, "live migrated VM $vmid to node $node_b")
+ or die "live migrating VM $vmid failed\n";
+
+ is(
+ $client->get("/nodes/$node_b/qemu/$vmid/status/current", {})->{status},
+ 'running',
+ "VM $vmid keeps running during the live migration",
+ );
+ $verify_location->($pve_b, 'local-lvm', $pve_a, $zfs_storage);
+ },
+)->step(
+ 'live migrate VM with local disk back to the ZFS storage',
+ sub {
+ my $upid = $migrate->(
+ $pve_b,
+ {
+ target => $node_a,
+ online => 1,
+ 'with-local-disks' => 1,
+ targetstorage => $zfs_storage,
+ },
+ );
+ $pve_b->task_ok($upid, "live migrated VM $vmid back to node $node_a")
+ or die "live migrating VM $vmid back failed\n";
+
+ $verify_location->($pve_a, $zfs_storage, $pve_b, 'local-lvm');
+ },
+)->step(
+ 'migrate stopped VM with local disk',
+ sub {
+ $pve_a->stop_guest('qemu', $vmid);
+
+ my $upid = $migrate->($pve_a, { target => $node_b });
+ $pve_a->task_ok($upid, "migrated VM $vmid to node $node_b")
+ or die "migrating VM $vmid failed\n";
+
+ $verify_location->($pve_b, $zfs_storage, $pve_a, $zfs_storage);
+ },
+)->run();
+
+done_testing();
diff --git a/tests/testcases.ron b/tests/testcases.ron
index 9903d79..e0d622c 100644
--- a/tests/testcases.ron
+++ b/tests/testcases.ron
@@ -151,6 +151,17 @@ TestcaseConfig(
],
tag: "extended",
),
+ Testcase(
+ name: "pve_vm_migration_local_disks",
+ run: "./tests/pve_vm_migration_local_disks.pl",
+ timeout: 600,
+ instances: [
+ "pve1-cluster",
+ "pve2-cluster",
+ "pve3-cluster",
+ ],
+ tag: "extended",
+ ),
Testcase(
name: "pve_replication",
run: "./tests/pve_replication.pl",
--
2.47.3
next prev parent reply other threads:[~2026-11-04 19:09 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 19:03 [PATCH e2e-tests/test-tools 00/38] tests: add tests for guests, Ceph, PBS and cluster workflows Michael Köppl
2026-11-04 19:03 ` [PATCH test-tools 01/38] ansible: rename snd_test bridge to tt_test as multi-purpose bridge Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 02/38] plans: rename sdn_test bridge to tt_test Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 03/38] debian: add missing jq dependency Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 04/38] test framework: move the default container template to the helper Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 05/38] lib: instance: add helper to check if an address answers ping Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 06/38] lib: pveinstance: look up disks by their SCSI serial Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 07/38] lib: pveinstance: add helper to find a task started by another task Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 08/38] lib: pveinstance: add helpers to start and stop guests Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 09/38] lib: pveinstance: add helper to run commands in containers Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 10/38] lib: pveinstance: add helper to wait for qmeventd's cleanup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 11/38] lib: pveinstance: add helper to check if guest exists Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 12/38] lib: add helpers to use a PBS datastore as PVE storage Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 13/38] scripts: retry container template download, fail if it fails Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 14/38] tests: container: verify lifecycle and guest setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 15/38] tests: container: verify volume and bind mountpoints Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 16/38] tests: container: verify snapshots, clones, templates Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 17/38] tests: container: verify device passthrough Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 18/38] plans,scripts: build a minimal OCI image onto pve1 Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 19/38] tests: container: verify application containers from OCI images Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 20/38] tests: vm: verify snapshots, clones, templates Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 21/38] tests: vm: verify adding, resizing, and removing disks Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 22/38] plans,scripts: download a Debian cloud image onto pve1 Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 23/38] tests: vm: verify lifecycle operations and cloud-init guest setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 24/38] plans,scripts: install Ceph Tentacle on the cluster nodes Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 25/38] test framework: add Ceph test helpers Michael Köppl
2026-11-06 12:24 ` Kefu Chai
2026-11-06 13:04 ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 26/38] tests: ceph: verify setting up a hyper-converged cluster Michael Köppl
2026-11-06 12:50 ` Kefu Chai
2026-11-06 13:05 ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 27/38] tests: ceph: verify guests on RBD storage Michael Köppl
2026-11-06 13:01 ` Kefu Chai
2026-11-06 13:07 ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 28/38] tests: ceph: verify setting up, using and destroying a CephFS Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 29/38] tests: ceph: verify replacing an OSD Michael Köppl
2026-11-06 13:14 ` Kefu Chai
2026-11-04 19:03 ` [PATCH e2e-tests 30/38] tests: ceph: drop the outdated Ceph setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 31/38] tests: pbs: verify container backup and restore Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 32/38] tests: backup: verify VM backup and restore, locally and on PBS Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 33/38] tests: pbs: verify single file restore from a container backup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 34/38] tests: storage: verify moving guest volumes between storages Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 35/38] tests: migration: verify container migration between nodes Michael Köppl
2026-11-04 19:03 ` Michael Köppl [this message]
2026-11-04 19:03 ` [PATCH e2e-tests 37/38] tests: ha: verify moving guests off a node for maintenance Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 38/38] tests: migration: verify migrating guests in bulk Michael Köppl
2026-11-06 13:25 ` [PATCH e2e-tests/test-tools 00/38] tests: add tests for guests, Ceph, PBS and cluster workflows Kefu Chai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261104190345.2573464-37-m.koeppl@proxmox.com \
--to=m.koeppl@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox