15 use PVE
::Tools
qw(dir_glob_foreach file_get_contents);
17 my $INPUT_DIR = './restore-config-input';
18 my $EXPECTED_DIR = './restore-config-expected';
20 my $pve_cluster_module = Test
::MockModule-
>new('PVE::Cluster');
21 $pve_cluster_module->mock(
22 cfs_read_file
=> sub {
27 # NOTE update when you add/remove tests
30 my $cfs_mock = Test
::MockModule-
>new("PVE::Cluster");
32 cfs_read_file
=> sub {
35 if ($file eq 'datacenter.cfg') {
38 die "'cfs_read_file' called - missing mock?\n";
43 dir_glob_foreach
('./restore-config-input', '[0-9]+.conf', sub {
46 my $vmid = basename
($file, ('.conf'));
48 my $fh = IO
::File-
>new("${INPUT_DIR}/${file}", "r") or
49 die "unable to read '$file' - $!\n";
54 # NOTE For now, the map is hardcoded to a file-based 'target' storage.
55 # In the future, the test could be extended to include parse_backup_hints
56 # and restore_allocate_devices. Even better if the config-related logic from
57 # the restore_XYZ_archive functions could become a separate function.
58 while (defined(my $line = <$fh>)) {
59 if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) {
60 my ($drive, undef, $storeid, $fmt) = ($1, $2, $3, $4);
64 $map->{$drive} = "target:${vmid}/vm-${vmid}-disk-${disknum}.${fmt}";
69 $fh->seek(0, 0) or die "seek failed - $!\n";
72 my $cookie = { netcount
=> 0 };
74 while (defined(my $line = <$fh>)) {
75 $got .= PVE
::QemuServer
::restore_update_config_line
(
83 my $expected = file_get_contents
("${EXPECTED_DIR}/${file}");
85 is_deeply
($got, $expected, $file);