From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 925CB1FF0C0 for ; Wed, 18 Nov 2026 05:40:07 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6D1D621732; Wed, 18 Nov 2026 05:39:26 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v3 20/38] tests: remote migration: check a failed command and an early tunnel end Date: Wed, 18 Nov 2026 05:37:32 +0100 Message-ID: <20261118043817.1659212-21-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118043817.1659212-1-t.lamprecht@proxmox.com> References: <20261118043817.1659212-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794976702828 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.189 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: K2J5MSWOOKSOYX4JX6OSEZMYKVR5TXZ5 X-Message-ID-Hash: K2J5MSWOOKSOYX4JX6OSEZMYKVR5TXZ5 X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: With the uid taken over at the start of a remote migration, a config left behind on the target would keep the uid of the VM in the target cluster. Check that the target removes its reservation if the tunnel closes before the config arrived, keeps a config that arrived, and logs the error of a failed tunnel command. Signed-off-by: Thomas Lamprecht --- changes v2 -> v3: * follow the fixed wait for a volume transfer in the cleanup of the target, which is bounded by time: check a transfer that exits late and one that cannot be collected changes v1 -> v2: * new in v2 src/test/run_guest_identity_tests.pl | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl index 1379220a..9d97cd9b 100755 --- a/src/test/run_guest_identity_tests.pl +++ b/src/test/run_guest_identity_tests.pl @@ -530,6 +530,102 @@ subtest 'remote migration, target side' => sub { ); ok($replies->[1]->{success}, 'adopting fails: cleanup on quit succeeds'); ok(!defined(configs()->{103}), 'adopting fails: reservation removed by the cleanup'); + + my $warnings = ''; + local $SIG{__WARN__} = sub { $warnings .= $_[0]; }; + + ($replies, $output, $err) = run_mtunnel(104, [$identity_cmd, $cleanup_cmd]); + like( + $warnings, + qr/^failed to handle 'identity' command - unable to adopt the uid of the source guest/m, + 'failed command: target task logs the error', + ); + + QemuServerTest::FakeCFS::reset(); + $warnings = ''; + ($replies, $output, $err) = run_mtunnel(104, [$identity_cmd]); + like($err, qr/mtunnel exited unexpectedly/, 'end before the config: tunnel fails'); + ok($replies->[0]->{success}, 'end before the config: uid was taken over'); + like( + $warnings, + qr/^tunnel closed before the config arrived, cleaning up$/m, + 'end before the config: cleanup is logged', + ); + ok(!defined(configs()->{104}), + 'end before the config: reservation with the uid is removed'); + + QemuServerTest::FakeCFS::reset(); + $warnings = ''; + ($replies, $output, $err) = run_mtunnel(104, [$identity_cmd, $config_cmd]); + like($err, qr/mtunnel exited unexpectedly/, 'end after the config: tunnel fails'); + unlike($warnings, qr/cleaning up/, 'end after the config: no cleanup'); + like(configs()->{104}, qr/^lock: migrate$/m, 'end after the config: config is kept'); + + # the volume of a transfer is only known once the transfer is done + my $import_cmd = { + cmd => 'disk-import', + volname => 'vm-104-disk-0', + format => 'raw', + export_formats => 'raw+size', + storage => 'local', + }; + my ($queries, $ends_after, $query_error, $freed) = (0, 2, undef, []); + my $storage_tunnel_module = Test::MockModule->new('PVE::StorageTunnel'); + $storage_tunnel_module->mock( + handle_disk_import => sub { + my ($state) = @_; + $state->{disk_import} = { pid => 1 }; + return {}; + }, + handle_query_disk_import => sub { + my ($state) = @_; + die $query_error if $query_error; + return { status => 'pending' } if ++$queries < $ends_after; + delete $state->{disk_import}; + $state->{cleanup}->{volumes}->{'local:104/vm-104-disk-0.raw'} = 1; + return { status => 'complete' }; + }, + ); + $storage_module->mock( + storage_check_enabled => sub { return 1; }, + storage_config => sub { return { content => { images => 1 } }; }, + vdisk_free => sub { push $freed->@*, $_[1]; }, + ); + my $rpcenv_module = Test::MockModule->new('PVE::RPCEnvironment'); + $rpcenv_module->mock(check => sub { return 1; }); + + QemuServerTest::FakeCFS::reset(); + $warnings = ''; + ($replies, $output, $err) = run_mtunnel(104, [$import_cmd]); + ok($replies->[0]->{success}, 'transfer that ends: it starts') or diag(explain($replies)); + is_deeply( + $freed, + ['local:104/vm-104-disk-0.raw'], + 'transfer that ends: its volume is freed', + ); + ok(!defined(configs()->{104}), 'transfer that ends: reservation is removed'); + + # a transfer that closed its output can be queried many times before it has exited + QemuServerTest::FakeCFS::reset(); + ($queries, $ends_after, $freed, $warnings) = (0, 20, [], ''); + ($replies, $output, $err) = run_mtunnel(104, [$import_cmd]); + is_deeply( + $freed, + ['local:104/vm-104-disk-0.raw'], + 'transfer that exits late: volume is freed', + ); + ok(!defined(configs()->{104}), 'transfer that exits late: reservation is removed'); + + QemuServerTest::FakeCFS::reset(); + ($queries, $query_error, $freed, $warnings) = (0, "unable to query the transfer\n", [], ''); + ($replies, $output, $err) = run_mtunnel(104, [$import_cmd]); + like( + $warnings, + qr/^cleanup failed - a volume transfer is still running$/m, + 'transfer that cannot be collected: it is reported', + ); + is_deeply($freed, [], 'transfer that cannot be collected: nothing is freed'); + ok(defined(configs()->{104}), 'transfer that cannot be collected: reservation is kept'); }; subtest 'remote migration, source side' => sub { -- 2.47.3