mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-04-28 17:37:36 +00:00
test: add tests for restoring config
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
41ab78c626
commit
c62d7cf547
@ -5971,7 +5971,7 @@ my $restore_allocate_devices = sub {
|
|||||||
return $map;
|
return $map;
|
||||||
};
|
};
|
||||||
|
|
||||||
my $restore_update_config_line = sub {
|
sub restore_update_config_line {
|
||||||
my ($cookie, $vmid, $map, $line, $unique) = @_;
|
my ($cookie, $vmid, $map, $line, $unique) = @_;
|
||||||
|
|
||||||
return '' if $line =~ m/^\#qmdump\#/;
|
return '' if $line =~ m/^\#qmdump\#/;
|
||||||
@ -6038,7 +6038,7 @@ my $restore_update_config_line = sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
};
|
}
|
||||||
|
|
||||||
my $restore_deactivate_volumes = sub {
|
my $restore_deactivate_volumes = sub {
|
||||||
my ($storecfg, $devinfo) = @_;
|
my ($storecfg, $devinfo) = @_;
|
||||||
@ -6351,7 +6351,7 @@ sub restore_proxmox_backup_archive {
|
|||||||
|
|
||||||
my $cookie = { netcount => 0 };
|
my $cookie = { netcount => 0 };
|
||||||
while (defined(my $line = <$fh>)) {
|
while (defined(my $line = <$fh>)) {
|
||||||
$new_conf_raw .= $restore_update_config_line->(
|
$new_conf_raw .= restore_update_config_line(
|
||||||
$cookie,
|
$cookie,
|
||||||
$vmid,
|
$vmid,
|
||||||
$map,
|
$map,
|
||||||
@ -6618,7 +6618,7 @@ sub restore_vma_archive {
|
|||||||
|
|
||||||
my $cookie = { netcount => 0 };
|
my $cookie = { netcount => 0 };
|
||||||
while (defined(my $line = <$fh>)) {
|
while (defined(my $line = <$fh>)) {
|
||||||
$new_conf_raw .= $restore_update_config_line->(
|
$new_conf_raw .= restore_update_config_line(
|
||||||
$cookie,
|
$cookie,
|
||||||
$vmid,
|
$vmid,
|
||||||
$map,
|
$map,
|
||||||
@ -6775,7 +6775,7 @@ sub restore_tar_archive {
|
|||||||
|
|
||||||
my $cookie = { netcount => 0 };
|
my $cookie = { netcount => 0 };
|
||||||
while (defined (my $line = <$srcfd>)) {
|
while (defined (my $line = <$srcfd>)) {
|
||||||
$new_conf_raw .= $restore_update_config_line->(
|
$new_conf_raw .= restore_update_config_line(
|
||||||
$cookie,
|
$cookie,
|
||||||
$vmid,
|
$vmid,
|
||||||
$map,
|
$map,
|
||||||
|
@ -3,7 +3,7 @@ MIGRATION_TEST_TARGETS := $(addprefix test_migration_,$(MIGRATION_TEST_NAMES))
|
|||||||
|
|
||||||
all: test
|
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
|
test_snapshot: run_snapshot_tests.pl
|
||||||
./run_snapshot_tests.pl
|
./run_snapshot_tests.pl
|
||||||
@ -26,6 +26,9 @@ test_migration: run_qemu_migrate_tests.pl MigrationTest/*.pm $(MIGRATION_TEST_TA
|
|||||||
$(MIGRATION_TEST_TARGETS):
|
$(MIGRATION_TEST_TARGETS):
|
||||||
./run_qemu_migrate_tests.pl $(@:test_migration_%=%)
|
./run_qemu_migrate_tests.pl $(@:test_migration_%=%)
|
||||||
|
|
||||||
|
test_restore_config: run_qemu_restore_config_tests.pl
|
||||||
|
./run_qemu_restore_config_tests.pl
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf MigrationTest/run
|
rm -rf MigrationTest/run
|
||||||
|
16
test/restore-config-expected/139.conf
Normal file
16
test/restore-config-expected/139.conf
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 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
|
15
test/restore-config-expected/142.conf
Normal file
15
test/restore-config-expected/142.conf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# 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
|
14
test/restore-config-expected/1422.conf
Normal file
14
test/restore-config-expected/1422.conf
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# 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
|
17
test/restore-config-expected/179.conf
Normal file
17
test/restore-config-expected/179.conf
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# 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
|
18
test/restore-config-input/139.conf
Normal file
18
test/restore-config-input/139.conf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# 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::
|
16
test/restore-config-input/142.conf
Normal file
16
test/restore-config-input/142.conf
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 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:
|
18
test/restore-config-input/1422.conf
Normal file
18
test/restore-config-input/1422.conf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# 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:
|
21
test/restore-config-input/179.conf
Normal file
21
test/restore-config-input/179.conf
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# 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:
|
67
test/run_qemu_restore_config_tests.pl
Executable file
67
test/run_qemu_restore_config_tests.pl
Executable file
@ -0,0 +1,67 @@
|
|||||||
|
#!/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();
|
Loading…
Reference in New Issue
Block a user