1 package MigrationTest
::QmMock
;
9 use MigrationTest
::Shared
;
13 use PVE
::Tools
qw(file_set_contents file_get_contents);
16 use base
qw(PVE::CLIHandler);
18 my $RUN_DIR_PATH = $ENV{RUN_DIR_PATH
} or die "no RUN_DIR_PATH set\n";
20 my $target_volids = decode_json
(file_get_contents
("${RUN_DIR_PATH}/target_volids"));
21 my $fail_config = decode_json
(file_get_contents
("${RUN_DIR_PATH}/fail_config"));
22 my $migrate_params = decode_json
(file_get_contents
("${RUN_DIR_PATH}/migrate_params"));
23 my $nodename = $migrate_params->{target
};
27 sub setup_environment
{
28 my $rpcenv = PVE
::RPCEnvironment
::init
('MigrationTest::QmMock', 'cli');
31 # mock RPCEnvironment directly
38 my ($self, $dtype, $id, $user, $function, $background) = @_;
45 my $inotify_module = Test
::MockModule-
>new("PVE::INotify");
46 $inotify_module->mock(
52 $MigrationTest::Shared
::qemu_server_module-
>mock(
56 config_to_command
=> sub {
57 return [ 'mocked_kvm_command' ];
61 my $qemu_server_helpers_module = Test
::MockModule-
>new("PVE::QemuServer::Helpers");
62 $qemu_server_helpers_module->mock(
63 vm_running_locally
=> sub {
68 # to make sure we get valid and predictable names
69 my $disk_counter = 10;
71 $MigrationTest::Shared
::storage_module-
>mock(
73 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
75 die "vdisk_alloc (mocked) - name is not expected to be set - implement me\n"
78 my $name_without_extension = "vm-${vmid}-disk-${disk_counter}";
82 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
84 $volid = "${storeid}:${vmid}/${name_without_extension}.${fmt}";
86 $volid = "${storeid}:${name_without_extension}";
89 PVE
::Storage
::parse_volume_id
($volid);
91 die "vdisk_alloc '$volid' error\n" if $fail_config->{vdisk_alloc
}
92 && $fail_config->{vdisk_alloc
} eq $volid;
94 MigrationTest
::Shared
::add_target_volid
($volid);
100 $MigrationTest::Shared
::qemu_server_module-
>mock(
102 my ($vmid, $command, %params) = @_;
104 if ($command eq 'nbd-server-start') {
106 } elsif ($command eq 'block-export-add') {
108 } elsif ($command eq 'query-block') {
110 } elsif ($command eq 'qom-set') {
113 die "mon_cmd (mocked) - implement me: $command";
116 my ($cmd_full, %param) = @_;
118 my $cmd_msg = to_json
($cmd_full);
120 my $cmd = shift @{$cmd_full};
122 if ($cmd eq '/bin/systemctl') {
124 } elsif ($cmd eq 'mocked_kvm_command') {
128 die "run_command (mocked) - implement me: ${cmd_msg}";
130 set_migration_caps
=> sub {
133 vm_migrate_alloc_nbd_disks
=> sub{
134 my $nbd = $MigrationTest::Shared
::qemu_server_module-
>original('vm_migrate_alloc_nbd_disks')->(@_);
135 file_set_contents
("${RUN_DIR_PATH}/nbd_info", to_json
($nbd));
141 start
=> [ "PVE::API2::Qemu", 'vm_start', ['vmid'], { node
=> $nodename } ],
144 MigrationTest
::QmMock-
>run_cli_handler();