From b2fcf5405f49f9c5d4218fd10cd83056f41234ff Mon Sep 17 00:00:00 2001 From: upstream Date: Sat, 3 Oct 2026 01:40:02 +0200 Subject: [PATCH] Upstream proxmox-git/qemu-server state of the touched files before 7e62afd562 --- src/PVE/QemuServer.pm | 2 - src/test/run_qemu_restore_config_tests.pl | 81 +++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/test/run_qemu_restore_config_tests.pl diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 3b9a86a..f199371 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -2167,8 +2167,6 @@ sub write_vm_config { foreach my $key (sort keys %$conf) { next if $key =~ /^(digest|description|pending|snapshots|special-sections)$/; - # an empty tag list is only needed as pending change for removing all tags - next if $key eq 'tags' && !$pending && $conf->{$key} =~ m/^\s*$/; $raw .= "$key: $conf->{$key}\n"; } return $raw; diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl new file mode 100644 index 0000000..4d5ebb5 --- /dev/null +++ b/src/test/run_qemu_restore_config_tests.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use lib qw(..); + +use Test::MockModule; +use Test::More; + +use File::Basename; + +use PVE::QemuServer; +use PVE::Tools qw(dir_glob_foreach file_get_contents); + +my $INPUT_DIR = './restore-config-input'; +my $EXPECTED_DIR = './restore-config-expected'; + +# NOTE update when you add/remove tests +plan tests => 4; + +my $pve_cluster_module = Test::MockModule->new("PVE::Cluster"); +$pve_cluster_module->mock( + cfs_read_file => sub { + my ($file) = @_; + + if ($file eq 'datacenter.cfg') { + return {}; + } else { + die "'cfs_read_file' called - missing mock?\n"; + } + }, +); + +dir_glob_foreach( + './restore-config-input', + '[0-9]+.conf', + sub { + my ($file) = @_; + + my $vmid = basename($file, ('.conf')); + + my $fh = IO::File->new("${INPUT_DIR}/${file}", "r") + or die "unable to read '$file' - $!\n"; + + my $map = {}; + my $disknum = 0; + + # NOTE For now, the map is hardcoded to a file-based 'target' storage. + # In the future, the test could be extended to include parse_backup_hints + # and restore_allocate_devices. Even better if the config-related logic from + # the restore_XYZ_archive functions could become a separate function. + while (defined(my $line = <$fh>)) { + if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) { + my ($drive, undef, $storeid, $fmt) = ($1, $2, $3, $4); + + $fmt ||= 'raw'; + + $map->{$drive} = "target:${vmid}/vm-${vmid}-disk-${disknum}.${fmt}"; + $disknum++; + } + } + + $fh->seek(0, 0) or die "seek failed - $!\n"; + + my $got = ''; + my $cookie = { netcount => 0 }; + + while (defined(my $line = <$fh>)) { + $got .= PVE::QemuServer::restore_update_config_line( + $cookie, $map, $line, 0, + ); + } + + my $expected = file_get_contents("${EXPECTED_DIR}/${file}"); + + is_deeply($got, $expected, $file); + }, +); + +done_testing();