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;
64 # never update during the tests
70 my $pve_tools_module = Test
::MockModule-
>new('PVE::Tools');
71 $pve_tools_module->mock(
72 file_get_contents
=> sub {
75 die "unexpected filename '$filename'\n" if $filename ne '/etc/vzdump.conf';
76 return $vzdump_config;
82 # each test consists of the following:
83 # name - unique name for the test
84 # cli_param - CLI parameters to be passed to new(); vmid and storage are hardcoded
85 # storage_param - parameters for the mocked storage configuration
86 # vzdump_param - parameters for the mocked /etc/vzdump.conf
87 # expected - expected options
89 # To begin testing for different options, use a fake test like the first one
92 description
=> 'BEGIN RETENTION TESTS',
93 tested_options
=> ['prune-backups', 'remove'],
96 description
=> 'no params',
104 # TODO make parse error critical?
106 description
=> 'maxfiles vzdump 1',
118 description
=> 'maxfiles vzdump 2',
130 description
=> 'maxfiles storage 1',
142 description
=> 'maxfiles storage 2',
154 description
=> 'maxfiles CLI 1',
166 description
=> 'maxfiles CLI 2',
178 description
=> 'prune-backups vzdump 1',
180 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
181 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
196 description
=> 'prune-backups vzdump 2',
198 'prune-backups' => 'keep-all=1',
208 description
=> 'prune-backups vzdump 3',
210 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
220 description
=> 'both vzdump 1',
222 'prune-backups' => 'keep-all=1',
233 description
=> 'prune-backups storage 1',
235 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
236 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
251 description
=> 'prune-backups storage 2',
253 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
254 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
264 description
=> 'prune-backups storage 3',
266 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
276 description
=> 'both storage 1',
278 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
291 description
=> 'prune-backups CLI 1',
293 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
294 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
309 description
=> 'prune-backups CLI 2',
311 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
312 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
322 description
=> 'prune-backups CLI 3',
324 'prune-backups' => 'foo=bar',
326 expected
=> "format error\n" .
327 "foo: property is not defined in schema and the schema does not allow additional properties\n",
330 description
=> 'both CLI 1',
332 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
335 expected
=> "400 Parameter verification failed.\n" .
336 "prune-backups: option conflicts with option 'maxfiles'\n",
339 description
=> 'mixed 1',
344 'prune-backups' => 'keep-hourly=24',
353 # TODO make parse error critical?
355 description
=> 'mixed 2',
360 'prune-backups' => 'keephourly=24',
370 description
=> 'mixed 3',
375 'prune-backups' => 'keep-all=1',
385 description
=> 'mixed 4',
390 'prune-backups' => 'keep-all=0,keep-last=10',
393 'prune-backups' => 'keep-all=1',
403 description
=> 'mixed 5',
408 'prune-backups' => 'keep-all=0,keep-last=10',
418 description
=> 'mixed 6',
420 'prune-backups' => 'keep-last=10',
423 'prune-backups' => 'keep-all=1',
433 description
=> 'mixed 7',
435 'prune-backups' => 'keep-all=1',
438 'prune-backups' => 'keep-last=10',
448 description
=> 'mixed 8',
450 'prune-backups' => 'keep-last=10',
453 'prune-backups' => 'keep-all=1',
463 description
=> 'mixed 9',
465 'prune-backups' => 'keep-last=10',
468 'prune-backups' => 'keep-all=1',
478 description
=> 'BEGIN MAILTO TESTS',
479 tested_options
=> ['mailto'],
482 description
=> 'mailto vzdump 1',
484 'mailto' => 'developer@proxmox.com',
488 'developer@proxmox.com',
493 description
=> 'mailto vzdump 2',
495 'mailto' => 'developer@proxmox.com admin@proxmox.com',
499 'developer@proxmox.com',
505 description
=> 'mailto vzdump 3',
507 'mailto' => 'developer@proxmox.com,admin@proxmox.com',
511 'developer@proxmox.com',
517 description
=> 'mailto vzdump 4',
519 'mailto' => 'developer@proxmox.com, admin@proxmox.com',
523 'developer@proxmox.com',
529 description
=> 'mailto vzdump 5',
531 'mailto' => ' ,,; developer@proxmox.com, ; admin@proxmox.com ',
535 'developer@proxmox.com',
541 description
=> 'mailto vzdump 6',
550 description
=> 'mailto CLI 1',
552 'mailto' => 'developer@proxmox.com',
556 'developer@proxmox.com',
561 description
=> 'mailto CLI 2',
563 'mailto' => 'developer@proxmox.com admin@proxmox.com',
567 'developer@proxmox.com',
573 description
=> 'mailto CLI 3',
575 'mailto' => 'developer@proxmox.com,admin@proxmox.com',
579 'developer@proxmox.com',
585 description
=> 'mailto CLI 4',
587 'mailto' => 'developer@proxmox.com, admin@proxmox.com',
591 'developer@proxmox.com',
597 description
=> 'mailto CLI 5',
599 'mailto' => ' ,,; developer@proxmox.com, ; admin@proxmox.com ',
603 'developer@proxmox.com',
609 description
=> 'mailto both 1',
611 'mailto' => 'developer@proxmox.com',
614 'mailto' => 'admin@proxmox.com',
623 description
=> 'mailto both 2',
625 'mailto' => 'developer@proxmox.com',
636 plan tests
=> scalar @tests;
638 foreach my $test (@tests) {
639 if (defined($test->{tested_options
})) {
640 $tested_options = $test->{tested_options
};
641 ok
(1, $test->{description
});
645 prepare_storage_config
($test->{storage_param
});
646 prepare_vzdump_config
($test->{vzdump_param
});
648 $test->{cli_param
}->{vmid
} = 100;
649 $test->{cli_param
}->{storage
} = 'local';
652 PVE
::VZDump
::verify_vzdump_parameters
($test->{cli_param
}, 1);
653 PVE
::VZDump
::parse_mailto_exclude_path
($test->{cli_param
});
655 my $vzdump = PVE
::VZDump-
>new('fake cmdline', $test->{cli_param
}, undef);
657 my $opts = $vzdump->{opts
} or die "did not get options\n";
658 die "maxfiles is defined" if defined($opts->{maxfiles
});
661 foreach my $opt (@{$tested_options}) {
662 next if !defined($opts->{$opt});
663 $res->{$opt} = $opts->{$opt};
669 is_deeply
($got, $test->{expected
}, $test->{description
}) || diag
(explain
($got));