]> git.proxmox.com Git - qemu-server.git/commitdiff
test: migration: mock get_current_qemu_machine
authorFiona Ebner <f.ebner@proxmox.com>
Fri, 10 Nov 2023 13:24:50 +0000 (14:24 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 12 Nov 2023 17:48:01 +0000 (18:48 +0100)
by remembering the 'forcemachine' parameter that's passed along when
starting the target instance.

In preparation to introduce a call to get_current_qemu_machine after
starting a VM to check for machine version deprecation.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
test/MigrationTest/QmMock.pm

index e34686e30f65f36bac92a4646e1157c474e66261..fb94c58b088b2c26eec5cb79b21d5e11c1d90143 100644 (file)
@@ -23,6 +23,7 @@ my $migrate_params = decode_json(file_get_contents("${RUN_DIR_PATH}/migrate_para
 my $nodename = $migrate_params->{target};
 
 my $kvm_exectued = 0;
+my $forcemachine;
 
 sub setup_environment {
     my $rpcenv = PVE::RPCEnvironment::init('MigrationTest::QmMock', 'cli');
@@ -56,6 +57,12 @@ $MigrationTest::Shared::qemu_server_module->mock(
     config_to_command => sub {
        return [ 'mocked_kvm_command' ];
     },
+    vm_start_nolock => sub {
+       my ($storecfg, $vmid, $conf, $params, $migrate_opts) = @_;
+       $forcemachine = $params->{forcemachine}
+           or die "mocked vm_start_nolock - expected 'forcemachine' parameter\n";
+       $MigrationTest::Shared::qemu_server_module->original('vm_start_nolock')->(@_);
+    },
 );
 
 my $qemu_server_helpers_module = Test::MockModule->new("PVE::QemuServer::Helpers");
@@ -65,6 +72,13 @@ $qemu_server_helpers_module->mock(
     },
 );
 
+our $qemu_server_machine_module = Test::MockModule->new("PVE::QemuServer::Machine");
+$qemu_server_machine_module->mock(
+    get_current_qemu_machine => sub {
+       return wantarray ? ($forcemachine, 0) : $forcemachine;
+    },
+);
+
 # to make sure we get valid and predictable names
 my $disk_counter = 10;