]>
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 vzdump 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 vzdump 2',
188 'prune-backups' => 'keep-all=1',
198 description
=> 'prune-backups vzdump 3',
200 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
210 description
=> 'both vzdump 1',
212 'prune-backups' => 'keep-all=1',
223 description
=> 'prune-backups storage 1',
225 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
226 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
241 description
=> 'prune-backups storage 2',
243 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
244 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
254 description
=> 'prune-backups storage 3',
256 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
266 description
=> 'both storage 1',
268 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
281 description
=> 'prune-backups CLI 1',
283 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
284 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
299 description
=> 'prune-backups CLI 2',
301 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
302 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
312 description
=> 'prune-backups CLI 3',
314 'prune-backups' => 'foo=bar',
316 expected
=> "format error\n" .
317 "foo: property is not defined in schema and the schema does not allow additional properties\n",
320 description
=> 'both CLI 1',
322 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
325 expected
=> "400 Parameter verification failed.\n" .
326 "prune-backups: option conflicts with option 'maxfiles'\n",
329 description
=> 'mixed 1',
334 'prune-backups' => 'keep-hourly=24',
343 # TODO make parse error critical?
345 description
=> 'mixed 2',
350 'prune-backups' => 'keephourly=24',
360 description
=> 'mixed 3',
365 'prune-backups' => 'keep-all=1',
375 description
=> 'mixed 4',
380 'prune-backups' => 'keep-all=0,keep-last=10',
383 'prune-backups' => 'keep-all=1',
393 description
=> 'mixed 5',
398 'prune-backups' => 'keep-all=0,keep-last=10',
408 description
=> 'mixed 6',
410 'prune-backups' => 'keep-last=10',
413 'prune-backups' => 'keep-all=1',
423 description
=> 'mixed 7',
425 'prune-backups' => 'keep-all=1',
428 'prune-backups' => 'keep-last=10',
438 description
=> 'mixed 8',
440 'prune-backups' => 'keep-last=10',
443 'prune-backups' => 'keep-all=1',
453 description
=> 'mixed 9',
455 'prune-backups' => 'keep-last=10',
458 'prune-backups' => 'keep-all=1',
469 plan tests
=> scalar @tests;
471 foreach my $test (@tests) {
472 prepare_storage_config
($test->{storage_param
});
473 prepare_vzdump_config
($test->{vzdump_param
});
475 $test->{cli_param
}->{vmid
} = 100;
476 $test->{cli_param
}->{storage
} = 'local';
479 PVE
::VZDump
::verify_vzdump_parameters
($test->{cli_param
}, 1);
481 my $vzdump = PVE
::VZDump-
>new('fake cmdline', $test->{cli_param
}, undef);
483 my $opts = $vzdump->{opts
} or die "did not get options\n";
484 die "maxfiles is defined" if defined($opts->{maxfiles
});
487 foreach my $opt (@tested_options) {
488 next if !defined($opts->{$opt});
489 $res->{$opt} = $opts->{$opt};
495 is_deeply
($got, $test->{expected
}, $test->{description
}) || diag
(explain
($got));