From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 0A0BC1FF0AA for ; Tue, 17 Nov 2026 21:45:26 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 86FA32186B; Tue, 17 Nov 2026 21:43:54 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 35/51] test: parse volname: modernize code Date: Tue, 17 Nov 2026 21:39:07 +0100 Message-ID: <20261117203953.913035-36-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: 1794948066994 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.248 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: LBPZGAQD2KP5IRDYLZOGXDHDQVZDL54X X-Message-ID-Hash: LBPZGAQD2KP5IRDYLZOGXDHDQVZDL54X 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: Modernize the existing code in `parse_volname_test.pm` while leaving the tests unchanged otherwise. In particular, - move the test execution code into its own subroutine - add and call a `main()` subroutine - declare `use v5.36;` instead of `use strict;` and `use warnings;` - fix a handful of typos - adapt the code style to fit our more modern style guide Signed-off-by: Max R. Carrara --- src/test/parse_volname_test.pm | 93 ++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/src/test/parse_volname_test.pm b/src/test/parse_volname_test.pm index a3b4d568..6beb2be3 100644 --- a/src/test/parse_volname_test.pm +++ b/src/test/parse_volname_test.pm @@ -1,9 +1,8 @@ package PVE::Storage::TestParseVolname; -use strict; -use warnings; +use v5.36; use lib qw(..); use PVE::Storage; use PVE::Storage::Common qw( @@ -182,28 +181,28 @@ my $tests = [ description => "Import, ovf", volname => 'import/import.ovf', expected => ['import', 'import.ovf', undef, undef, undef, undef, 'ovf'], }, { - description => "Import, innner file of ova", + description => "Import, inner file of ova", volname => 'import/import.ova/disk.qcow2', expected => ['import', 'import.ova/disk.qcow2', undef, undef, undef, undef, 'ova+qcow2'], }, { - description => "Import, innner file of ova", + description => "Import, inner file of ova", volname => 'import/import.ova/disk.vmdk', expected => ['import', 'import.ova/disk.vmdk', undef, undef, undef, undef, 'ova+vmdk'], }, { - description => "Import, innner file of ova with whitespace in name", + description => "Import, inner file of ova with whitespace in name", volname => 'import/import.ova/OS disk.vmdk', expected => ['import', 'import.ova/OS disk.vmdk', undef, undef, undef, undef, 'ova+vmdk'], }, { - description => "Import, innner file of ova", + description => "Import, inner file of ova", volname => 'import/import.ova/disk.raw', expected => ['import', 'import.ova/disk.raw', undef, undef, undef, undef, 'ova+raw'], }, # # failed matches @@ -249,11 +248,11 @@ my $tests = [ }, ]; # create more test cases for VM disk images matches my $disk_suffix = ['raw', 'qcow2', 'vmdk']; -foreach my $s (@$disk_suffix) { +for my $s ($disk_suffix->@*) { my @arr = ( { description => "VM disk image, $s", volname => "$vmid/vm-$vmid-disk-1.$s", expected => [ @@ -280,23 +279,23 @@ foreach my $s (@$disk_suffix) { 'vm-vol', "base-$vmid-disk-0.$s", "$vmid", undef, undef, 'base-', "$s", ], }, ); - push @$tests, @arr; + push($tests->@*, @arr); } # create more test cases for backup files matches my $bkp_suffix = { qemu => ['vma', 'vma.gz', 'vma.lzo', 'vma.zst'], lxc => ['tar', 'tgz', 'tar.gz', 'tar.lzo', 'tar.zst', 'tar.bz2'], openvz => ['tar', 'tgz', 'tar.gz', 'tar.lzo', 'tar.zst'], }; -foreach my $virt (keys %$bkp_suffix) { +for my $virt (keys $bkp_suffix->%*) { my $suffix = $bkp_suffix->{$virt}; - foreach my $s (@$suffix) { + for my $s ($suffix->@*) { my @arr = ( { description => "Backup archive, $virt, $s", volname => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s", expected => [ @@ -309,32 +308,32 @@ foreach my $virt (keys %$bkp_suffix) { 'raw', ], }, ); - push @$tests, @arr; + push($tests->@*, @arr); } } # create more test cases for failed backup files matches my $non_bkp_suffix = { qemu => ['vms.gz', 'vma.xz'], lxc => ['zip.gz', 'tgz.lzo'], }; -foreach my $virt (keys %$non_bkp_suffix) { +for my $virt (keys $non_bkp_suffix->%*) { my $suffix = $non_bkp_suffix->{$virt}; - foreach my $s (@$suffix) { + for my $s ($suffix->@*) { my @arr = ( { description => "Failed match: Backup archive, $virt, $s", volname => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s", expected => "unable to parse directory volume name 'backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s'\n", }, ); - push @$tests, @arr; + push($tests->@*, @arr); } } my sub map_is_base { my ($plugin_name, $is_base) = @_; @@ -590,45 +589,53 @@ push $tests->@*, plugin => 'PVE::Storage::PBSPlugin', expected => "unable to parse PBS volume name 'images/host/999/2025-08-06T14:27:07Z'\n", }, ); -# -# run through test case array -# -plan tests => scalar @$tests + 1; +my sub run_tests($tests) { + my $seen_vtype = {}; + my $vtype_subdirs = { map { $_ => 1 } keys plugin_get_default_vtype_subdirs()->%* }; -my $seen_vtype; -my $vtype_subdirs = - { map { $_ => 1 } keys %{ plugin_get_default_vtype_subdirs() } }; + for my $t ($tests->@*) { + my $description = $t->{description}; + my $volname = $t->{volname}; + my $expected = $t->{expected}; -foreach my $t (@$tests) { - my $description = $t->{description}; - my $volname = $t->{volname}; - my $expected = $t->{expected}; + my $got; + if (my $plugin = $t->{plugin}) { + eval { $got = [$plugin->parse_volname($volname)] }; + } else { + eval { $got = [PVE::Storage::Plugin->parse_volname($volname)] }; + } + $got = $@ if $@; - my $got; - if (my $plugin = $t->{plugin}) { - eval { $got = [$plugin->parse_volname($volname)] }; - } else { - eval { $got = [PVE::Storage::Plugin->parse_volname($volname)] }; + is_deeply($got, $expected, $description); + + $seen_vtype->{ $expected->[0] } = 1 if ref $expected eq 'ARRAY'; } - $got = $@ if $@; - is_deeply($got, $expected, $description); + # every directory type needs a test: the volumes of VMs and containers all use the directory of the + # 'images' type, and the in-tree plugins return 'rootdir' for no volume + my $seen_subdir_vtype = {}; + for my $vtype (keys $seen_vtype->%*) { + $vtype = 'images' if PVE::Storage::Common::is_guest_vtype($vtype); + $seen_subdir_vtype->{$vtype} = 1; + } + delete $vtype_subdirs->{rootdir}; + is_deeply($seen_subdir_vtype, $vtype_subdirs, "vtype_subdir check"); - $seen_vtype->{ @$expected[0] } = 1 if ref $expected eq 'ARRAY'; + return; } -# every directory type needs a test: the volumes of VMs and containers all use the directory of the -# 'images' type, and the in-tree plugins return 'rootdir' for no volume -my $seen_subdir_vtype = {}; -for my $vtype (keys $seen_vtype->%*) { - $vtype = 'images' if PVE::Storage::Common::is_guest_vtype($vtype); - $seen_subdir_vtype->{$vtype} = 1; -} -delete $vtype_subdirs->{rootdir}; -is_deeply($seen_subdir_vtype, $vtype_subdirs, "vtype_subdir check"); +my sub main() { + plan tests => scalar($tests->@*) + 1; -done_testing(); + run_tests($tests); + + done_testing(); + + return; +} + +main(); 1; -- 2.47.3