]>
git.proxmox.com Git - pve-storage.git/blob - test/path_to_volume_id_test.pm
1 package PVE
::Storage
::TestPathToVolumeId
;
14 use File
::Path
qw(make_path remove_tree);
17 my $storage_dir = File
::Temp-
>newdir();
19 'digest' => 'd29306346b8b25b90a4a96165f1e8f52d1af1eda',
23 'path' => "$storage_dir",
41 # the tests array consists of hashes with the following keys:
42 # description => to identify the test case
43 # volname => to create the test file
44 # expected => the result that path_to_volume_id should return
47 description
=> 'Image, qcow2',
48 volname
=> "$storage_dir/images/16110/vm-16110-disk-0.qcow2",
51 'local:16110/vm-16110-disk-0.qcow2',
55 description
=> 'Image, raw',
56 volname
=> "$storage_dir/images/16112/vm-16112-disk-0.raw",
59 'local:16112/vm-16112-disk-0.raw',
63 description
=> 'Image template, qcow2',
64 volname
=> "$storage_dir/images/9004/base-9004-disk-0.qcow2",
67 'local:9004/base-9004-disk-0.qcow2',
72 description
=> 'Backup, vma.gz',
73 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz",
76 'local:backup/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz',
80 description
=> 'Backup, vma.lzo',
81 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_12_45.vma.lzo",
84 'local:backup/vzdump-qemu-16110-2020_03_30-21_12_45.vma.lzo',
88 description
=> 'Backup, vma',
89 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_13_55.vma",
92 'local:backup/vzdump-qemu-16110-2020_03_30-21_13_55.vma',
96 description
=> 'Backup, tar.lzo',
97 volname
=> "$storage_dir/dump/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo",
100 'local:backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo',
104 description
=> 'Backup, vma.zst',
105 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_13_55.vma.zst",
108 'local:backup/vzdump-qemu-16110-2020_03_30-21_13_55.vma.zst'
112 description
=> 'Backup, tar.zst',
113 volname
=> "$storage_dir/dump/vzdump-lxc-16112-2020_03_30-21_39_30.tar.zst",
116 'local:backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.zst'
121 description
=> 'ISO file',
122 volname
=> "$storage_dir/template/iso/yet-again-a-installation-disk.iso",
125 'local:iso/yet-again-a-installation-disk.iso',
129 description
=> 'CT template, tar.gz',
130 volname
=> "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.tar.gz",
133 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz',
138 description
=> 'Rootdir',
139 volname
=> "$storage_dir/private/1234/", # fileparse needs / at the end
142 'local:rootdir/1234',
146 description
=> 'Rootdir, folder subvol',
147 volname
=> "$storage_dir/images/1234/subvol-1234-disk-0.subvol/", # fileparse needs / at the end
150 'local:1234/subvol-1234-disk-0.subvol'
154 description
=> 'Snippets, yaml',
155 volname
=> "$storage_dir/snippets/userconfig.yaml",
158 'local:snippets/userconfig.yaml',
162 description
=> 'Snippets, hookscript',
163 volname
=> "$storage_dir/snippets/hookscript.pl",
166 'local:snippets/hookscript.pl',
170 description
=> 'CT template, tar.xz',
171 volname
=> "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.tar.xz",
174 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.xz',
178 # no matches, path or files with failures
180 description
=> 'Base template, string as vmid in folder name',
181 volname
=> "$storage_dir/images/ssss/base-4321-disk-0.raw",
185 description
=> 'ISO file, wrong ending',
186 volname
=> "$storage_dir/template/iso/yet-again-a-installation-disk.dvd",
190 description
=> 'CT template, wrong ending, zip.gz',
191 volname
=> "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.zip.gz",
195 description
=> 'CT template, wrong ending, tar bz2',
196 volname
=> "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.tar.bz2",
200 description
=> 'Rootdir as subvol, wrong path',
201 volname
=> "$storage_dir/private/subvol-19254-disk-0/",
205 description
=> 'Backup, wrong ending, openvz, tar.bz2',
206 volname
=> "$storage_dir/dump/vzdump-openvz-16112-2020_03_30-21_39_30.tar.bz2",
210 description
=> 'Backup, wrong format, openvz, zip.gz',
211 volname
=> "$storage_dir/dump/vzdump-openvz-16112-2020_03_30-21_39_30.zip.gz",
215 description
=> 'Backup, wrong format, openvz, tgz.lzo',
216 volname
=> "$storage_dir/dump/vzdump-openvz-16112-2020_03_30-21_39_30.tgz.lzo",
220 description
=> 'Backup, wrong ending, qemu, vma.xz',
221 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_12_40.vma.xz",
225 description
=> 'Backup, wrong format, qemu, vms.gz',
226 volname
=> "$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_12_40.vms.gz",
230 description
=> 'Image, string as vmid in folder name',
231 volname
=> "$storage_dir/images/ssss/vm-1234-disk-0.qcow2",
236 plan tests
=> scalar @tests + 1;
239 my $vtype_subdirs = { map { $_ => 1 } keys %{ PVE
::Storage
::Plugin
::get_vtype_subdirs
() } };
241 foreach my $tt (@tests) {
242 my $file = $tt->{volname
};
243 my $expected = $tt->{expected
};
244 my $description = $tt->{description
};
246 # prepare environment
247 my ($name, $dir, $suffix) = fileparse
($file);
248 make_path
($dir, { verbose
=> 1, mode
=> 0755 });
251 open(my $fh, ">>", "$file") || die "Error open file: $!";
257 eval { $got = [ PVE
::Storage
::path_to_volume_id
($scfg, $file) ] };
260 is_deeply
($got, $expected, $description) || diag
(explain
($got));
262 $seen_vtype->{@$expected[0]} = 1
263 if ( @$expected[0] ne '' && scalar @$expected > 1);
266 # to check if all $vtype_subdirs are defined in path_to_volume_id
268 is_deeply
($seen_vtype, $vtype_subdirs, "vtype_subdir check");
271 # File::Temp unlinks tempdir on exit