]>
git.proxmox.com Git - pve-storage.git/blob - test/parse_volname_test.pm
1 package PVE
::Storage
::TestParseVolname
;
13 # an array of test cases, each test is comprised of the following keys:
14 # description => to identify a single test
15 # volname => the input for parse_volname
16 # expected => the array that parse_volname returns
22 description
=> 'VM disk image, linked, qcow2, vm- as base-',
23 volname
=> "$vmid/vm-$vmid-disk-0.qcow2/$vmid/vm-$vmid-disk-0.qcow2",
24 expected
=> [ 'images', "vm-$vmid-disk-0.qcow2", "$vmid", "vm-$vmid-disk-0.qcow2", "$vmid", undef, 'qcow2', ],
30 description
=> 'ISO image, iso',
31 volname
=> 'iso/some-installation-disk.iso',
32 expected
=> ['iso', 'some-installation-disk.iso'],
35 description
=> 'ISO image, img',
36 volname
=> 'iso/some-other-installation-disk.img',
37 expected
=> ['iso', 'some-other-installation-disk.img'],
43 description
=> 'Container template tar.gz',
44 volname
=> 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz',
45 expected
=> ['vztmpl', 'debian-10.0-standard_10.0-1_amd64.tar.gz'],
48 description
=> 'Container template tar.xz',
49 volname
=> 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.xz',
50 expected
=> ['vztmpl', 'debian-10.0-standard_10.0-1_amd64.tar.xz'],
56 description
=> 'Container rootdir, sub directory',
57 volname
=> "rootdir/$vmid",
58 expected
=> ['rootdir', "$vmid", "$vmid"],
61 description
=> 'Container rootdir, subvol',
62 volname
=> "$vmid/subvol-$vmid-disk-0.subvol",
63 expected
=> [ 'images', "subvol-$vmid-disk-0.subvol", "$vmid", undef, undef, undef, 'subvol' ],
66 description
=> 'Backup archive, no virtualization type',
67 volname
=> "backup/vzdump-none-$vmid-2020_03_30-21_39_30.tar",
68 expected
=> ['backup', "vzdump-none-$vmid-2020_03_30-21_39_30.tar"],
74 description
=> 'Snippets, yaml',
75 volname
=> 'snippets/userconfig.yaml',
76 expected
=> ['snippets', 'userconfig.yaml'],
79 description
=> 'Snippets, perl',
80 volname
=> 'snippets/hookscript.pl',
81 expected
=> ['snippets', 'hookscript.pl'],
87 description
=> "Failed match: VM disk image, base, raw",
88 volname
=> "ssss/base-$vmid-disk-0.raw",
89 expected
=> "unable to parse directory volume name 'ssss/base-$vmid-disk-0.raw'\n",
92 description
=> 'Failed match: ISO image, dvd',
93 volname
=> 'iso/yet-again-a-installation-disk.dvd',
94 expected
=> "unable to parse directory volume name 'iso/yet-again-a-installation-disk.dvd'\n",
97 description
=> 'Failed match: Container template, zip.gz',
98 volname
=> 'vztmpl/debian-10.0-standard_10.0-1_amd64.zip.gz',
99 expected
=> "unable to parse directory volume name 'vztmpl/debian-10.0-standard_10.0-1_amd64.zip.gz'\n",
102 description
=> 'Failed match: Container template, tar.bz2',
103 volname
=> 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.bz2',
104 expected
=> "unable to parse directory volume name 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.bz2'\n",
107 description
=> 'Failed match: Container rootdir, subvol',
108 volname
=> "rootdir/subvol-$vmid-disk-0",
109 expected
=> "unable to parse directory volume name 'rootdir/subvol-$vmid-disk-0'\n",
112 description
=> 'Failed match: VM disk image, linked, vhdx',
113 volname
=> "$vmid/base-$vmid-disk-0.vhdx/$vmid/vm-$vmid-disk-0.vhdx",
114 expected
=> "unable to parse volume filename 'base-$vmid-disk-0.vhdx'\n",
117 description
=> 'Failed match: VM disk image, linked, qcow2, first vmid',
118 volname
=> "ssss/base-$vmid-disk-0.qcow2/$vmid/vm-$vmid-disk-0.qcow2",
119 expected
=> "unable to parse directory volume name 'ssss/base-$vmid-disk-0.qcow2/$vmid/vm-$vmid-disk-0.qcow2'\n",
122 description
=> 'Failed match: VM disk image, linked, qcow2, second vmid',
123 volname
=> "$vmid/base-$vmid-disk-0.qcow2/ssss/vm-$vmid-disk-0.qcow2",
124 expected
=> "unable to parse volume filename 'base-$vmid-disk-0.qcow2/ssss/vm-$vmid-disk-0.qcow2'\n",
128 # create more test cases for VM disk images matches
129 my $disk_suffix = [ 'raw', 'qcow2', 'vmdk' ];
130 foreach my $s (@$disk_suffix) {
133 description
=> "VM disk image, $s",
134 volname
=> "$vmid/vm-$vmid-disk-1.$s",
137 "vm-$vmid-disk-1.$s",
146 description
=> "VM disk image, linked, $s",
147 volname
=> "$vmid/base-$vmid-disk-0.$s/$vmid/vm-$vmid-disk-0.$s",
150 "vm-$vmid-disk-0.$s",
152 "base-$vmid-disk-0.$s",
159 description
=> "VM disk image, base, $s",
160 volname
=> "$vmid/base-$vmid-disk-0.$s",
163 "base-$vmid-disk-0.$s",
177 # create more test cases for backup files matches
179 qemu
=> [ 'vma', 'vma.gz', 'vma.lzo', 'vma.zst' ],
180 lxc
=> [ 'tar', 'tgz', 'tar.gz', 'tar.lzo', 'tar.zst' ],
181 openvz
=> [ 'tar', 'tgz', 'tar.gz', 'tar.lzo', 'tar.zst' ],
184 foreach my $virt (keys %$bkp_suffix) {
185 my $suffix = $bkp_suffix->{$virt};
186 foreach my $s (@$suffix) {
189 description
=> "Backup archive, $virt, $s",
190 volname
=> "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
193 "vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
204 # create more test cases for failed backup files matches
205 my $non_bkp_suffix = {
206 qemu
=> [ 'vms.gz', 'vma.xz' ],
207 lxc
=> [ 'tar.bz2', 'zip.gz', 'tgz.lzo' ],
209 foreach my $virt (keys %$non_bkp_suffix) {
210 my $suffix = $non_bkp_suffix->{$virt};
211 foreach my $s (@$suffix) {
214 description
=> "Failed match: Backup archive, $virt, $s",
215 volname
=> "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
216 expected
=> "unable to parse directory volume name 'backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s'\n",
226 # run through test case array
228 plan tests
=> scalar @$tests + 1;
231 my $vtype_subdirs = { map { $_ => 1 } keys %{ PVE
::Storage
::Plugin
::get_vtype_subdirs
() } };
233 foreach my $t (@$tests) {
234 my $description = $t->{description
};
235 my $volname = $t->{volname
};
236 my $expected = $t->{expected
};
239 eval { $got = [ PVE
::Storage
::Plugin-
>parse_volname($volname) ] };
242 is_deeply
($got, $expected, $description);
244 $seen_vtype->{@$expected[0]} = 1 if ref $expected eq 'ARRAY';
247 # to check if all $vtype_subdirs are defined in path_to_volume_id
249 is_deeply
($seen_vtype, $vtype_subdirs, "vtype_subdir check");