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 128A21FF0AA for ; Tue, 17 Nov 2026 21:44:41 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5B27C217A4; Tue, 17 Nov 2026 21:43:05 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 29/51] test: list volumes: reorganize and modernize test running code Date: Tue, 17 Nov 2026 21:39:01 +0100 Message-ID: <20261117203953.913035-30-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794948054389 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.202 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) PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far 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: GJJH4NYMSZILUKK5OV4OYDA3XEBFFXCZ X-Message-ID-Hash: GJJH4NYMSZILUKK5OV4OYDA3XEBFFXCZ X-MailFrom: m.carrara@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 CC: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Use the `use v5.36` pragma to enable subroutine signatures, warnings and strictness by default. Factor out the list of file suffixes for file formats that support backing files into its own constant. Introduce a `main()` subroutine. Move the code that runs the existing tests for `::Plugin->list_volumes()` into its own subroutine. Move the remaining single test that checks whether the vmlist returned by `PVE::Cluster::get_vmlist()` was modified into `main()`. Move the call to `Test::More`'s `plan()` into `main()` as well. Done as preparation for other changes. Signed-off-by: Max R. Carrara --- src/test/list_volumes_test.pm | 66 ++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm index a1f3eb18..176b5a46 100644 --- a/src/test/list_volumes_test.pm +++ b/src/test/list_volumes_test.pm @@ -1,21 +1,20 @@ package PVE::Storage::TestListVolumes; -use strict; -use warnings; +use v5.36; use lib qw(..); use PVE::Storage; use PVE::Cluster; use PVE::Tools qw(run_command); use Test::More; use Test::MockModule; use Cwd; -use File::Basename; +use File::Basename qw(fileparse); use File::Path qw(make_path remove_tree); use File::stat qw(); use File::Temp; use Storable qw(dclone); @@ -74,10 +73,12 @@ my $scfg = { 'backup' => 1, 'import' => 1, }, }; +my @BACKING_FILE_SUFFIXES = ('qcow2', 'raw', 'vmdk', 'vhdx'); + # The test cases are comprised of an arry of hashes with the following keys: # description => displayed on error by Test::More # vmid => used for image matches by list_volume # files => array of files for qemu-img to create # expected => returned result hash @@ -747,48 +748,26 @@ $mock_fsi->redefine( my sub cmp_volinfo_by_volid { return $a->{volid} cmp $b->{volid}; } -my $plan = scalar @tests; -plan tests => $plan + 1; - -{ - # don't accidentally modify vmlist, see bug report - # https://pve.proxmox.com/pipermail/pve-devel/2020-January/041096.html - my $scfg_with_type = { path => $storage_dir, type => 'dir' }; - my $original_vmlist = { ids => {} }; - my $tested_vmlist = dclone($original_vmlist); - - PVE::Storage::Plugin->list_volumes('sid', $scfg_with_type, undef, ['images']); - - is_deeply($tested_vmlist, $original_vmlist, 'PVE::Cluster::vmlist remains unmodified') - || diag( - "Expected vmlist to remain\n", - explain($original_vmlist), - "but it turned to\n", - explain($tested_vmlist), - ); -} - -{ +my sub run_legacy_tests() { my $sid = 'local'; my $types = [grep { $scfg->{content}->{$_} } keys $scfg->{content}->%*]; - my @suffixes = ('qcow2', 'raw', 'vmdk', 'vhdx'); # run through test cases foreach my $tt (@tests) { my $vmid = $tt->{vmid}; my $files = $tt->{files}; my $expected = [sort cmp_volinfo_by_volid $tt->{expected}->@*]; my $description = $tt->{description}; my $parent = $tt->{parent}; # prepare environment my $num = 0; #parent disks for my $file (@$files) { - my ($name, $dir, $suffix) = fileparse($file, @suffixes); + my ($name, $dir, $suffix) = fileparse($file, @BACKING_FILE_SUFFIXES); make_path($dir, { verbose => 1, mode => 0755 }); if ($name) { # using qemu-img to also be able to represent the backing device @@ -812,10 +791,41 @@ plan tests => $plan + 1; # clean up after each test case, otherwise # we get wrong results from leftover files remove_tree($storage_dir, { verbose => 1 }); } + + return; } -done_testing(); +sub main() { + my $plan = scalar @tests; + plan tests => $plan + 1; + + { + # don't accidentally modify vmlist, see bug report + # https://pve.proxmox.com/pipermail/pve-devel/2020-January/041096.html + my $scfg_with_type = { path => $storage_dir, type => 'dir' }; + my $original_vmlist = { ids => {} }; + my $tested_vmlist = dclone($original_vmlist); + + PVE::Storage::Plugin->list_volumes('sid', $scfg_with_type, undef, ['images']); + + is_deeply($tested_vmlist, $original_vmlist, 'PVE::Cluster::vmlist remains unmodified') + || diag( + "Expected vmlist to remain\n", + explain($original_vmlist), + "but it turned to\n", + explain($tested_vmlist), + ); + } + + run_legacy_tests(); + + done_testing(); + + return; +} + +main(); 1; -- 2.47.3