]> git.proxmox.com Git - qemu-server.git/blame - test/run_qemu_restore_config_tests.pl
remove left-over mentions of to-be-dropped, outdated QMP commands
[qemu-server.git] / test / run_qemu_restore_config_tests.pl
CommitLineData
c62d7cf5
FE
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib qw(..);
7
cc1cdadb 8use Test::MockModule;
c62d7cf5 9use Test::More;
75c430ce 10use Test::MockModule;
c62d7cf5
FE
11
12use File::Basename;
13
14use PVE::QemuServer;
15use PVE::Tools qw(dir_glob_foreach file_get_contents);
16
17my $INPUT_DIR = './restore-config-input';
18my $EXPECTED_DIR = './restore-config-expected';
19
cc1cdadb
FE
20my $pve_cluster_module = Test::MockModule->new('PVE::Cluster');
21$pve_cluster_module->mock(
22 cfs_read_file => sub {
23 return {};
24 },
25);
26
c62d7cf5
FE
27# NOTE update when you add/remove tests
28plan tests => 4;
29
75c430ce
FG
30my $cfs_mock = Test::MockModule->new("PVE::Cluster");
31$cfs_mock->mock(
32 cfs_read_file => sub {
33 my ($file) = @_;
34
35 if ($file eq 'datacenter.cfg') {
36 return {};
37 } else {
38 die "'cfs_read_file' called - missing mock?\n";
39 }
40 },
41);
42
c62d7cf5
FE
43dir_glob_foreach('./restore-config-input', '[0-9]+.conf', sub {
44 my ($file) = @_;
45
46 my $vmid = basename($file, ('.conf'));
47
48 my $fh = IO::File->new("${INPUT_DIR}/${file}", "r") or
49 die "unable to read '$file' - $!\n";
50
51 my $map = {};
52 my $disknum = 0;
53
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);
61
62 $fmt ||= 'raw';
63
64 $map->{$drive} = "target:${vmid}/vm-${vmid}-disk-${disknum}.${fmt}";
65 $disknum++;
66 }
67 }
68
69 $fh->seek(0, 0) or die "seek failed - $!\n";
70
71 my $got = '';
72 my $cookie = { netcount => 0 };
73
74 while (defined(my $line = <$fh>)) {
75 $got .= PVE::QemuServer::restore_update_config_line(
76 $cookie,
c62d7cf5
FE
77 $map,
78 $line,
79 0,
80 );
81 }
82
83 my $expected = file_get_contents("${EXPECTED_DIR}/${file}");
84
85 is_deeply($got, $expected, $file);
86});
87
88done_testing();