return $map;
};
-my $restore_update_config_line = sub {
+sub restore_update_config_line {
my ($cookie, $vmid, $map, $line, $unique) = @_;
return '' if $line =~ m/^\#qmdump\#/;
}
return $res;
-};
+}
my $restore_deactivate_volumes = sub {
my ($storecfg, $devinfo) = @_;
my $cookie = { netcount => 0 };
while (defined(my $line = <$fh>)) {
- $new_conf_raw .= $restore_update_config_line->(
+ $new_conf_raw .= restore_update_config_line(
$cookie,
$vmid,
$map,
my $cookie = { netcount => 0 };
while (defined(my $line = <$fh>)) {
- $new_conf_raw .= $restore_update_config_line->(
+ $new_conf_raw .= restore_update_config_line(
$cookie,
$vmid,
$map,
my $cookie = { netcount => 0 };
while (defined (my $line = <$srcfd>)) {
- $new_conf_raw .= $restore_update_config_line->(
+ $new_conf_raw .= restore_update_config_line(
$cookie,
$vmid,
$map,
all: test
-test: test_snapshot test_ovf test_cfg_to_cmd test_pci_addr_conflicts test_qemu_img_convert test_migration
+test: test_snapshot test_ovf test_cfg_to_cmd test_pci_addr_conflicts test_qemu_img_convert test_migration test_restore_config
test_snapshot: run_snapshot_tests.pl
./run_snapshot_tests.pl
$(MIGRATION_TEST_TARGETS):
./run_qemu_migrate_tests.pl $(@:test_migration_%=%)
+test_restore_config: run_qemu_restore_config_tests.pl
+ ./run_qemu_restore_config_tests.pl
+
.PHONY: clean
clean:
rm -rf MigrationTest/run
--- /dev/null
+# regular VM with an EFI disk
+bios: ovmf
+boot: order=scsi0;ide2;net0
+cores: 1
+efidisk0: target:139/vm-139-disk-0.qcow2,size=128K
+ide2: local:iso/debian-10.6.0-amd64-netinst.iso,media=cdrom
+memory: 2048
+name: eficloneclone
+net0: virtio=7A:6C:A5:8B:11:93,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: target:139/vm-139-disk-1.raw,size=4G
+scsihw: virtio-scsi-pci
+smbios1: uuid=21a7e7bc-3cd2-4232-a009-a41f4ee992ae
+sockets: 1
+vmgenid: 0
--- /dev/null
+# plain VM
+bootdisk: scsi0
+cores: 1
+ide2: none,media=cdrom
+memory: 512
+name: apache
+net0: virtio=92:38:11:FD:ED:87,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: target:142/vm-142-disk-0.qcow2,size=4G
+scsihw: virtio-scsi-pci
+smbios1: uuid=ddf91b3f-a597-42be-9a7e-fb6421dcd5cd
+sockets: 1
+vmgenid: 0
+tags: foo bar
--- /dev/null
+# some properties should be filtered
+bootdisk: scsi0
+cores: 1
+ide2: none,media=cdrom
+memory: 512
+name: apache
+net0: virtio=92:38:11:FD:ED:87,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: target:1422/vm-1422-disk-0.qcow2,size=4G
+scsihw: virtio-scsi-pci
+smbios1: uuid=ddf91b3f-a597-42be-9a7e-fb6421dcd5cd
+sockets: 1
+vmgenid: 0
--- /dev/null
+# many disks
+boot: order=scsi0;ide2;net0
+cores: 1
+ide2: none,media=cdrom
+memory: 2048
+net0: virtio=26:15:5B:73:3F:7C,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: target:179/vm-179-disk-0.qcow2,cache=none,discard=on,size=32G,ssd=1
+scsi1: target:179/vm-179-disk-1.qcow2,cache=writethrough,size=32G
+scsi2: target:179/vm-179-disk-2.qcow2,mbps_rd=7,mbps_wr=7,replicate=0,size=32G
+scsi3: target:179/vm-179-disk-3.vmdk,size=32G
+#scsi4: myfs:179/vm-179-disk-1.qcow2,backup=0,size=32G
+scsihw: virtio-scsi-pci
+smbios1: uuid=1819ead7-a55d-4544-8d38-29ca94869a9c
+sockets: 1
+vmgenid: 0
--- /dev/null
+# regular VM with an EFI disk
+bios: ovmf
+boot: order=scsi0;ide2;net0
+cores: 1
+efidisk0: mydir:139/vm-139-disk-0.qcow2,size=128K
+ide2: local:iso/debian-10.6.0-amd64-netinst.iso,media=cdrom
+memory: 2048
+name: eficloneclone
+net0: virtio=7A:6C:A5:8B:11:93,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: rbdkvm:vm-139-disk-1,size=4G
+scsihw: virtio-scsi-pci
+smbios1: uuid=21a7e7bc-3cd2-4232-a009-a41f4ee992ae
+sockets: 1
+vmgenid: 0
+#qmdump#map:efidisk0:drive-efidisk0:mydir:qcow2:
+#qmdump#map:scsi0:drive-scsi0:rbdkvm::
--- /dev/null
+# plain VM
+bootdisk: scsi0
+cores: 1
+ide2: none,media=cdrom
+memory: 512
+name: apache
+net0: virtio=92:38:11:FD:ED:87,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: mydir:142/vm-142-disk-0.qcow2,size=4G
+scsihw: virtio-scsi-pci
+smbios1: uuid=ddf91b3f-a597-42be-9a7e-fb6421dcd5cd
+sockets: 1
+vmgenid: 0
+tags: foo bar
+#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
--- /dev/null
+# some properties should be filtered
+bootdisk: scsi0
+cores: 1
+ide2: none,media=cdrom
+memory: 512
+name: apache
+net0: virtio=92:38:11:FD:ED:87,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: mydir:1422/vm-1422-disk-0.qcow2,size=4G
+unused7: mydir:1422/vm-1422-disk-8.qcow2
+parent: snap
+lock: backup
+scsihw: virtio-scsi-pci
+smbios1: uuid=ddf91b3f-a597-42be-9a7e-fb6421dcd5cd
+sockets: 1
+vmgenid: 0
+#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
--- /dev/null
+# many disks
+boot: order=scsi0;ide2;net0
+cores: 1
+ide2: none,media=cdrom
+memory: 2048
+net0: virtio=26:15:5B:73:3F:7C,bridge=vmbr0,firewall=1
+numa: 0
+ostype: l26
+scsi0: myfs:179/vm-179-disk-4.qcow2,cache=none,discard=on,size=32G,ssd=1
+scsi1: myfs:179/vm-179-disk-0.qcow2,cache=writethrough,size=32G
+scsi2: myfs:179/vm-179-disk-2.qcow2,mbps_rd=7,mbps_wr=7,replicate=0,size=32G
+scsi3: myfs:179/vm-179-disk-3.vmdk,size=32G
+scsi4: myfs:179/vm-179-disk-1.qcow2,backup=0,size=32G
+scsihw: virtio-scsi-pci
+smbios1: uuid=1819ead7-a55d-4544-8d38-29ca94869a9c
+sockets: 1
+vmgenid: 0
+#qmdump#map:scsi0:drive-scsi0:myfs:qcow2:
+#qmdump#map:scsi1:drive-scsi1:myfs:qcow2:
+#qmdump#map:scsi2:drive-scsi2:myfs:qcow2:
+#qmdump#map:scsi3:drive-scsi3:myfs:vmdk:
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+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;
+
+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,
+ $vmid,
+ $map,
+ $line,
+ 0,
+ );
+ }
+
+ my $expected = file_get_contents("${EXPECTED_DIR}/${file}");
+
+ is_deeply($got, $expected, $file);
+});
+
+done_testing();