]> git.proxmox.com Git - qemu-server.git/blob - test/run_qemu_restore_config_tests.pl
cfg2cmd: make io_uring default
[qemu-server.git] / test / run_qemu_restore_config_tests.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib qw(..);
7
8 use Test::MockModule;
9 use Test::More;
10
11 use File::Basename;
12
13 use PVE::QemuServer;
14 use PVE::Tools qw(dir_glob_foreach file_get_contents);
15
16 my $INPUT_DIR = './restore-config-input';
17 my $EXPECTED_DIR = './restore-config-expected';
18
19 my $pve_cluster_module = Test::MockModule->new('PVE::Cluster');
20 $pve_cluster_module->mock(
21 cfs_read_file => sub {
22 return {};
23 },
24 );
25
26 # NOTE update when you add/remove tests
27 plan tests => 4;
28
29 dir_glob_foreach('./restore-config-input', '[0-9]+.conf', sub {
30 my ($file) = @_;
31
32 my $vmid = basename($file, ('.conf'));
33
34 my $fh = IO::File->new("${INPUT_DIR}/${file}", "r") or
35 die "unable to read '$file' - $!\n";
36
37 my $map = {};
38 my $disknum = 0;
39
40 # NOTE For now, the map is hardcoded to a file-based 'target' storage.
41 # In the future, the test could be extended to include parse_backup_hints
42 # and restore_allocate_devices. Even better if the config-related logic from
43 # the restore_XYZ_archive functions could become a separate function.
44 while (defined(my $line = <$fh>)) {
45 if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) {
46 my ($drive, undef, $storeid, $fmt) = ($1, $2, $3, $4);
47
48 $fmt ||= 'raw';
49
50 $map->{$drive} = "target:${vmid}/vm-${vmid}-disk-${disknum}.${fmt}";
51 $disknum++;
52 }
53 }
54
55 $fh->seek(0, 0) or die "seek failed - $!\n";
56
57 my $got = '';
58 my $cookie = { netcount => 0 };
59
60 while (defined(my $line = <$fh>)) {
61 $got .= PVE::QemuServer::restore_update_config_line(
62 $cookie,
63 $map,
64 $line,
65 0,
66 );
67 }
68
69 my $expected = file_get_contents("${EXPECTED_DIR}/${file}");
70
71 is_deeply($got, $expected, $file);
72 });
73
74 done_testing();