test: migration: mock get_current_qemu_machine

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>
This commit is contained in:
Fiona Ebner 2023-11-10 14:24:50 +01:00 committed by Thomas Lamprecht
parent da84155405
commit e13a66c8f7

View 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;