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 2752D1FF0B7 for ; Mon, 30 Nov 2026 19:11:13 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0758B216CF; Mon, 30 Nov 2026 19:10:52 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v3 04/18] test: api: factor out validating the migration preconditions Date: Mon, 30 Nov 2026 19:09:36 +0100 Message-ID: <20261130181007.596064-5-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130181007.596064-1-j.theisen@proxmox.com> References: <20261130181007.596064-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796062224538 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.064 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: BERFTKYDKMUIEKBZ5GTZ7NXTDIXGYQ4L X-Message-ID-Hash: BERFTKYDKMUIEKBZ5GTZ7NXTDIXGYQ4L X-MailFrom: j.theisen@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: Move validating a result of the migration precondition API against its schema into a helper, so that further tests of the API can check that the reasons of each node they produce are documented as well. No functional change intended. Signed-off-by: Jonas Theisen --- src/test/run_api_tests.pl | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl index d8f26e32..f2916346 100755 --- a/src/test/run_api_tests.pl +++ b/src/test/run_api_tests.pl @@ -256,6 +256,20 @@ is( 'clone_vm: no check without target node', ); +# Returns the error of validating a result of migrate_vm_precondition against its schema, which +# also requires every reason why a node is not allowed to be documented. +sub validate_migration_preconditions { + my ($res) = @_; + + my $returns = PVE::API2::Qemu->map_method_by_name('migrate_vm_precondition')->{returns}; + my $strict = dclone($returns); + my $node_schema = $strict->{properties}->{not_allowed_nodes}->{additionalProperties}; + $node_schema->{additionalProperties} = 0; + eval { PVE::JSONSchema::validate($res, $strict) }; + + return $@; +} + subtest 'migration preconditions' => sub { my $nodes = ['localhost', 'pve2', 'pve3', 'pve4']; $cluster_module->mock(get_nodelist => sub { return $nodes; }); @@ -303,16 +317,17 @@ subtest 'migration preconditions' => sub { 'node with an older version is not allowed', ); - my $returns = PVE::API2::Qemu->map_method_by_name('migrate_vm_precondition')->{returns}; - # every reason of a node must be documented - my $strict = dclone($returns); - my $node_schema = $strict->{properties}->{not_allowed_nodes}->{additionalProperties}; - $node_schema->{additionalProperties} = 0; - eval { PVE::JSONSchema::validate($res, $strict) }; - is($@, '', 'result matches the schema, including the reasons of each node'); + is( + validate_migration_preconditions($res), + '', + 'result matches the schema, including the reasons of each node', + ); my $undocumented = { $res->%*, not_allowed_nodes => { pve3 => { 'other-reason' => 1 } } }; - eval { PVE::JSONSchema::validate($undocumented, $strict) }; - like($@, qr/other-reason/, 'an undocumented reason does not'); + like( + validate_migration_preconditions($undocumented), + qr/other-reason/, + 'an undocumented reason does not', + ); $cluster_module->unmock('get_nodelist', 'get_config'); mock_unreachable_config(); -- 2.47.3