]> git.proxmox.com Git - qemu-server.git/blobdiff - test/snapshot-test.pm
snapshot-test: mock query-savevm better
[qemu-server.git] / test / snapshot-test.pm
index ed5acb9683e9f2a635799938a93984770ea30764..f65a902c819e74f574815fa59592f9ca33a07eeb 100644 (file)
@@ -1,4 +1,4 @@
-package PVE::QemuServer;
+package PVE::QemuServer; ## no critic
 
 use strict;
 use warnings;
@@ -315,7 +315,7 @@ sub vm_running_locally {
 # BEGIN mocked PVE::QemuServer::Monitor methods
 
 sub qmp_cmd {
-    my ($vmid, $cmd, $nocheck) = @_;
+    my ($vmid, $cmd) = @_;
 
     my $exec = $cmd->{execute};
     if ($exec eq "delete-drive-snapshot") {
@@ -342,7 +342,11 @@ sub qmp_cmd {
        return;
     }
     if ($exec eq "query-savevm") {
-       return { "status" => "completed" };
+       return {
+           "status" => "completed",
+           "bytes" => 1024*1024*1024,
+           "total-time" => 5000,
+        };
     }
     die "unexpected vm_qmp_command!\n";
 }
@@ -356,13 +360,13 @@ sub do_snapshots_with_qemu {
 }
 
 sub vm_start {
-    my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine) = @_;
+    my ($storecfg, $vmid, $params, $migrate_opts) = @_;
 
     die "Storage config not mocked! aborting\n"
        if defined($storecfg);
 
     die "statefile and forcemachine must be both defined or undefined! aborting\n"
-       if defined($statefile) xor defined($forcemachine);
+       if defined($params->{statefile}) xor defined($params->{forcemachine});
 
     return;
 }
@@ -381,13 +385,13 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
-my $qemu_helpers_module = new Test::MockModule('PVE::QemuServer::Helpers');
+my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
 $qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
 
-my $qemu_monitor_module = new Test::MockModule('PVE::QemuServer::Monitor');
+my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
 $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 
-my $qemu_config_module = new Test::MockModule('PVE::QemuConfig');
+my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
 $qemu_config_module->mock('load_config', \&load_config);
@@ -397,12 +401,12 @@ $qemu_config_module->mock('__snapshot_save_vmstate', \&__snapshot_save_vmstate);
 $qemu_config_module->mock('assert_config_exists_on_node', \&assert_config_exists_on_node);
 
 # ignore existing replication config
-my $repl_config_module = new Test::MockModule('PVE::ReplicationConfig');
+my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
 $repl_config_module->mock('new' => sub { return bless {}, "PVE::ReplicationConfig" });
-$repl_config_module->mock('check_for_existing_jobs' => sub { return undef });
+$repl_config_module->mock('check_for_existing_jobs' => sub { return });
 
-my $storage_module = new Test::MockModule('PVE::Storage');
-$storage_module->mock('config', sub { return undef; });
+my $storage_module = Test::MockModule->new('PVE::Storage');
+$storage_module->mock('config', sub { return; });
 $storage_module->mock('path', sub { return "/some/store/statefile/path"; });
 $storage_module->mock('activate_volumes', \&mocked_activate_volumes);
 $storage_module->mock('deactivate_volumes', \&mocked_deactivate_volumes);
@@ -506,7 +510,7 @@ $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
 
 #printf("\n");
 #printf("Setting up Mocking for PVE::Tools\n");
-#my $tools_module = new Test::MockModule('PVE::Tools');
+#my $tools_module = Test::MockModule->new('PVE::Tools');
 #$tools_module->mock('run_command' => \&mocked_run_command);
 #printf("\trun_command() mocked\n");
 #
@@ -638,3 +642,5 @@ printf("Successful snapshot_rollback with saved vmstate and machine config and r
 testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
 
 done_testing();
+
+1;