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;
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
85 # To begin testing for different options, use a fake test like the first one
88 description
=> 'BEGIN RETENTION TESTS',
89 tested_options
=> ['prune-backups', 'remove'],
92 description
=> 'no params',
100 # TODO make parse error critical?
102 description
=> 'maxfiles vzdump 1',
114 description
=> 'maxfiles vzdump 2',
126 description
=> 'maxfiles storage 1',
138 description
=> 'maxfiles storage 2',
150 description
=> 'maxfiles CLI 1',
162 description
=> 'maxfiles CLI 2',
174 description
=> 'prune-backups vzdump 1',
176 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
177 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
192 description
=> 'prune-backups vzdump 2',
194 'prune-backups' => 'keep-all=1',
204 description
=> 'prune-backups vzdump 3',
206 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
216 description
=> 'both vzdump 1',
218 'prune-backups' => 'keep-all=1',
229 description
=> 'prune-backups storage 1',
231 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
232 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
247 description
=> 'prune-backups storage 2',
249 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
250 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
260 description
=> 'prune-backups storage 3',
262 'prune-backups' => 'keep-hourly=0,keep-monthly=0,keep-yearly=0',
272 description
=> 'both storage 1',
274 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
287 description
=> 'prune-backups CLI 1',
289 'prune-backups' => 'keep-last=1,keep-hourly=2,keep-daily=3,' .
290 'keep-weekly=4,keep-monthly=5,keep-yearly=6',
305 description
=> 'prune-backups CLI 2',
307 'prune-backups' => 'keep-last=0,keep-hourly=0,keep-daily=0,' .
308 'keep-weekly=0,keep-monthly=0,keep-yearly=0',
318 description
=> 'prune-backups CLI 3',
320 'prune-backups' => 'foo=bar',
322 expected
=> "format error\n" .
323 "foo: property is not defined in schema and the schema does not allow additional properties\n",
326 description
=> 'both CLI 1',
328 'prune-backups' => 'keep-hourly=1,keep-monthly=2,keep-yearly=3',
331 expected
=> "400 Parameter verification failed.\n" .
332 "prune-backups: option conflicts with option 'maxfiles'\n",
335 description
=> 'mixed 1',
340 'prune-backups' => 'keep-hourly=24',
349 # TODO make parse error critical?
351 description
=> 'mixed 2',
356 'prune-backups' => 'keephourly=24',
366 description
=> 'mixed 3',
371 'prune-backups' => 'keep-all=1',
381 description
=> 'mixed 4',
386 'prune-backups' => 'keep-all=0,keep-last=10',
389 'prune-backups' => 'keep-all=1',
399 description
=> 'mixed 5',
404 'prune-backups' => 'keep-all=0,keep-last=10',
414 description
=> 'mixed 6',
416 'prune-backups' => 'keep-last=10',
419 'prune-backups' => 'keep-all=1',
429 description
=> 'mixed 7',
431 'prune-backups' => 'keep-all=1',
434 'prune-backups' => 'keep-last=10',
444 description
=> 'mixed 8',
446 'prune-backups' => 'keep-last=10',
449 'prune-backups' => 'keep-all=1',
459 description
=> 'mixed 9',
461 'prune-backups' => 'keep-last=10',
464 'prune-backups' => 'keep-all=1',
474 description
=> 'BEGIN MAILTO TESTS',
475 tested_options
=> ['mailto'],
478 description
=> 'mailto vzdump 1',
480 'mailto' => 'developer@proxmox.com',
484 'developer@proxmox.com',
489 description
=> 'mailto vzdump 2',
491 'mailto' => 'developer@proxmox.com admin@proxmox.com',
495 'developer@proxmox.com',
501 description
=> 'mailto vzdump 3',
503 'mailto' => 'developer@proxmox.com,admin@proxmox.com',
507 'developer@proxmox.com',
513 description
=> 'mailto vzdump 4',
515 'mailto' => 'developer@proxmox.com, admin@proxmox.com',
519 'developer@proxmox.com',
525 description
=> 'mailto vzdump 5',
527 'mailto' => ' ,,; developer@proxmox.com, ; admin@proxmox.com ',
531 'developer@proxmox.com',
537 description
=> 'mailto vzdump 6',
546 description
=> 'mailto CLI 1',
548 'mailto' => 'developer@proxmox.com',
552 'developer@proxmox.com',
557 description
=> 'mailto CLI 2',
559 'mailto' => 'developer@proxmox.com admin@proxmox.com',
563 'developer@proxmox.com',
569 description
=> 'mailto CLI 3',
571 'mailto' => 'developer@proxmox.com,admin@proxmox.com',
575 'developer@proxmox.com',
581 description
=> 'mailto CLI 4',
583 'mailto' => 'developer@proxmox.com, admin@proxmox.com',
587 'developer@proxmox.com',
593 description
=> 'mailto CLI 5',
595 'mailto' => ' ,,; developer@proxmox.com, ; admin@proxmox.com ',
599 'developer@proxmox.com',
605 description
=> 'mailto both 1',
607 'mailto' => 'developer@proxmox.com',
610 'mailto' => 'admin@proxmox.com',
619 description
=> 'mailto both 2',
621 'mailto' => 'developer@proxmox.com',
632 plan tests
=> scalar @tests;
634 foreach my $test (@tests) {
635 if (defined($test->{tested_options
})) {
636 $tested_options = $test->{tested_options
};
637 ok
(1, $test->{description
});
641 prepare_storage_config
($test->{storage_param
});
642 prepare_vzdump_config
($test->{vzdump_param
});
644 $test->{cli_param
}->{vmid
} = 100;
645 $test->{cli_param
}->{storage
} = 'local';
648 PVE
::VZDump
::verify_vzdump_parameters
($test->{cli_param
}, 1);
649 PVE
::VZDump
::parse_mailto_exclude_path
($test->{cli_param
});
651 my $vzdump = PVE
::VZDump-
>new('fake cmdline', $test->{cli_param
}, undef);
653 my $opts = $vzdump->{opts
} or die "did not get options\n";
654 die "maxfiles is defined" if defined($opts->{maxfiles
});
657 foreach my $opt (@{$tested_options}) {
658 next if !defined($opts->{$opt});
659 $res->{$opt} = $opts->{$opt};
665 is_deeply
($got, $test->{expected
}, $test->{description
}) || diag
(explain
($got));