]>
git.proxmox.com Git - pve-manager.git/blob - test/vzdump_new_retention_test.pl
16 sub prepare_storage_config
{
19 $storage_config = "dir: local\n";
20 $storage_config .= "\tcontent backup\n";
21 $storage_config .= "\tpath /var/lib/vz\n";
23 foreach my $key (keys %{$param}) {
24 my $value = $param->{$key};
25 $storage_config .= "\t${key} ${value}\n";
29 sub prepare_vzdump_config
{
33 foreach my $key (keys %{$param}) {
34 my $value = $param->{$key};
35 $vzdump_config .= "${key}: ${value}\n";
39 my $pve_vzdump_module = Test
::MockModule-
>new('PVE::VZDump');
40 $pve_vzdump_module->mock(
49 my $pve_storage_module = Test
::MockModule-
>new('PVE::Storage');
50 $pve_storage_module->mock(
51 activate_storage
=> sub {
56 my $pve_cluster_module = Test
::MockModule-
>new('PVE::Cluster');
57 $pve_cluster_module->mock(
61 die "unexpected filename '$filename'\n" if $filename ne 'storage.cfg';
62 return $storage_config;
66 my $pve_tools_module = Test
::MockModule-
>new('PVE::Tools');
67 $pve_tools_module->mock(
68 file_get_contents
=> sub {
71 die "unexpected filename '$filename'\n" if $filename ne '/etc/vzdump.conf';
72 return $vzdump_config;
76 my @tested_options = qw(prune-backups remove);
78 # each test consists of the following:
79 # name - unique name for the test
80 # cli_param - CLI parameters to be passed to new(); vmid and storage are hardcoded
81 # storage_param - parameters for the mocked storage configuration
82 # vzdump_param - parameters for the mocked /etc/vzdump.conf
83 # expected - expected options
86 description
=> 'no params',
94 # TODO make parse error critical?
96 description
=> 'maxfiles vzdump 1',
108 description
=> 'maxfiles vzdump 2',
120 description
=> 'maxfiles storage 1',
132 description
=> 'maxfiles storage 2',
144 description
=> 'maxfiles CLI 1',
156 description
=> 'maxfiles CLI 2',
168 description
=> 'prune-backups storage 1',
170 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
171 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
186 description
=> 'prune-backups storage 2',
188 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
189 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
199 description
=> 'prune-backups storage 3',
201 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
211 description
=> 'both storage 1',
213 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
226 description
=> 'prune-backups CLI 1',
228 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
229 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
244 description
=> 'prune-backups CLI 2',
246 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
247 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
257 description
=> 'prune-backups CLI 3',
259 'prune-backups' => 'foo=bar',
261 expected
=> "format error\n" .
262 "foo: property is not defined in schema and the schema does not allow additional properties\n",
265 description
=> 'both CLI 1',
267 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
270 expected
=> "400 Parameter verification failed.\n" .
271 "prune-backups: option conflicts with option 'maxfiles'\n",
274 description
=> 'mixed 1',
279 'prune-backups' => 'keep-hourly=24',
288 # TODO make parse error critical?
290 description
=> 'mixed 2',
295 'prune-backups' => 'keephourly=24',
305 description
=> 'mixed 3',
310 'prune-backups' => 'keep-all=1',
320 description
=> 'mixed 4',
325 'prune-backups' => 'keep-all=0,keep-last=10',
328 'prune-backups' => 'keep-all=1',
338 description
=> 'mixed 5',
343 'prune-backups' => 'keep-all=0,keep-last=10',
353 description
=> 'mixed 6',
355 'prune-backups' => 'keep-last=10',
358 'prune-backups' => 'keep-all=1',
368 description
=> 'mixed 7',
370 'prune-backups' => 'keep-all=1',
373 'prune-backups' => 'keep-last=10',
384 plan tests
=> scalar @tests;
386 foreach my $test (@tests) {
387 prepare_storage_config
($test->{storage_param
});
388 prepare_vzdump_config
($test->{vzdump_param
});
390 $test->{cli_param
}->{vmid
} = 100;
391 $test->{cli_param
}->{storage
} = 'local';
394 PVE
::VZDump
::verify_vzdump_parameters
($test->{cli_param
}, 1);
396 my $vzdump = PVE
::VZDump-
>new('fake cmdline', $test->{cli_param
}, undef);
398 my $opts = $vzdump->{opts
} or die "did not get options\n";
399 die "maxfiles is defined" if defined($opts->{maxfiles
});
402 foreach my $opt (@tested_options) {
403 next if !defined($opts->{$opt});
404 $res->{$opt} = $opts->{$opt};
410 is_deeply
($got, $test->{expected
}, $test->{description
}) || diag
(explain
($got));