]> git.proxmox.com Git - pve-storage.git/blame - test/archive_info_test.pm
pbs: allow setting up a master key
[pve-storage.git] / test / archive_info_test.pm
CommitLineData
cd554b79
AA
1package PVE::Storage::TestArchiveInfo;
2
3use strict;
4use warnings;
5
6use lib qw(..);
7
8use PVE::Storage;
9use Test::More;
10
11my $vmid = 16110;
12
13# an array of test cases, each test is comprised of the following keys:
14# description => to identify a single test
15# archive => the input filename for archive_info
16# expected => the hash that archive_info returns
17#
18# most of them are created further below
19my $tests = [
20 # backup archives
b1ddc54a
FE
21 {
22 description => 'Backup archive, lxc, tgz, future millenium',
23 archive => "backup/vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
24 expected => {
25 'filename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
26 'logfilename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.log",
27 'type' => 'lxc',
28 'format' => 'tar',
29 'decompressor' => ['tar', '-z'],
30 'compression' => 'gz',
31 'vmid' => $vmid,
32 'ctime' => 60*60*24 * (365*1100 + 267),
33 'is_std_name' => 1,
34 },
35 },
36 {
37 description => 'Backup archive, lxc, tgz, very old',
38 archive => "backup/vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
39 expected => {
40 'filename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
41 'logfilename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.log",
42 'type' => 'lxc',
43 'format' => 'tar',
44 'decompressor' => ['tar', '-z'],
45 'compression' => 'gz',
46 'vmid' => $vmid,
47 'ctime' => 60*60*2 + 30,
48 'is_std_name' => 1,
49 },
50 },
cd554b79
AA
51 {
52 description => 'Backup archive, lxc, tgz',
53 archive => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
54 expected => {
e34afeb1
FE
55 'filename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
56 'logfilename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.log",
cd554b79
AA
57 'type' => 'lxc',
58 'format' => 'tar',
59 'decompressor' => ['tar', '-z'],
60 'compression' => 'gz',
fb821c18
FE
61 'vmid' => $vmid,
62 'ctime' => 1585604370,
63 'is_std_name' => 1,
cd554b79
AA
64 },
65 },
66 {
67 description => 'Backup archive, openvz, tgz',
68 archive => "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
69 expected => {
e34afeb1
FE
70 'filename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
71 'logfilename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.log",
cd554b79
AA
72 'type' => 'openvz',
73 'format' => 'tar',
74 'decompressor' => ['tar', '-z'],
75 'compression' => 'gz',
fb821c18
FE
76 'vmid' => $vmid,
77 'ctime' => 1585604370,
78 'is_std_name' => 1,
cd554b79
AA
79 },
80 },
e34afeb1
FE
81 {
82 description => 'Backup archive, custom dump directory, qemu, tgz',
83 archive => "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
84 expected => {
85 'filename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
86 'logfilename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.log",
87 'type' => 'qemu',
88 'format' => 'tar',
89 'decompressor' => ['tar', '-z'],
90 'compression' => 'gz',
91 'vmid' => $vmid,
92 'ctime' => 1585604370,
93 'is_std_name' => 1,
94 },
95 },
4b26f814
AA
96 {
97 description => 'Backup archive, none, tgz',
5029f978 98 archive => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
4b26f814 99 expected => {
e34afeb1 100 'filename' => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
5029f978 101 'type' => 'qemu',
4b26f814
AA
102 'format' => 'tar',
103 'decompressor' => ['tar', '-z'],
104 'compression' => 'gz',
fb821c18 105 'is_std_name' => 0,
4b26f814
AA
106 },
107 },
cd554b79
AA
108];
109
110# add new compression fromats to test
111my $decompressor = {
112 tar => {
113 gz => ['tar', '-z'],
114 lzo => ['tar', '--lzop'],
014d36db 115 zst => ['tar', '--zstd'],
cd554b79
AA
116 },
117 vma => {
118 gz => ['zcat'],
119 lzo => ['lzop', '-d', '-c'],
014d36db 120 zst => ['zstd', '-q', '-d', '-c'],
cd554b79
AA
121 },
122};
123
124my $bkp_suffix = {
125 qemu => [ 'vma', $decompressor->{vma}, ],
126 lxc => [ 'tar', $decompressor->{tar}, ],
127 openvz => [ 'tar', $decompressor->{tar}, ],
128};
129
130# create more test cases for backup files matches
5df46bf2
TL
131for my $virt (sort keys %$bkp_suffix) {
132 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
cd554b79 133
5df46bf2 134 for my $suffix (sort keys %$decomp) {
c265d421
TL
135 push @$tests, {
136 description => "Backup archive, $virt, $format.$suffix",
137 archive => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
138 expected => {
e34afeb1
FE
139 'filename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
140 'logfilename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log",
c265d421
TL
141 'type' => "$virt",
142 'format' => "$format",
143 'decompressor' => $decomp->{$suffix},
144 'compression' => "$suffix",
fb821c18
FE
145 'vmid' => $vmid,
146 'ctime' => 1585602760,
147 'is_std_name' => 1,
cd554b79 148 },
c265d421 149 };
cd554b79
AA
150 }
151}
152
153
154# add compression formats to test failed matches
155my $non_bkp_suffix = {
156 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
157 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
014d36db 158 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
a6c4705a 159 'none' => [ 'tar.gz', ],
cd554b79
AA
160};
161
162# create tests for failed matches
5df46bf2 163for my $virt (sort keys %$non_bkp_suffix) {
cd554b79 164 my $suffix = $non_bkp_suffix->{$virt};
c265d421 165 for my $s (@$suffix) {
bf5af0fb 166 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
c265d421
TL
167 push @$tests, {
168 description => "Failed match: Backup archive, $virt, $s",
bf5af0fb
TL
169 archive => $archive,
170 expected => "ERROR: couldn't determine archive info from '$archive'\n",
c265d421 171 };
cd554b79
AA
172 }
173}
174
175
176plan tests => scalar @$tests;
177
3dde6a9c
TL
178for my $tt (@$tests) {
179
180 my $got = eval { PVE::Storage::archive_info($tt->{archive}) };
cd554b79
AA
181 $got = $@ if $@;
182
3dde6a9c 183 is_deeply($got, $tt->{expected}, $tt->{description}) || diag(explain($got));
cd554b79
AA
184}
185
186done_testing();
187
1881;