]> git.proxmox.com Git - qemu-server.git/blobdiff - test/snapshot-test.pm
tests: allow running migration tests in parallel
[qemu-server.git] / test / snapshot-test.pm
index 2090d2602fa11b4e9ac8c26eb94b7f1226788fae..8f9f60a8d542b1d037a652e98a7fca6461ee1bc7 100644 (file)
@@ -1,4 +1,4 @@
-package PVE::QemuServer;
+package PVE::QemuServer; ## no critic
 
 use strict;
 use warnings;
@@ -297,21 +297,25 @@ sub __snapshot_save_vmstate {
     $snap->{vmstate} = "somestorage:state-volume";
     $snap->{runningmachine} = "somemachine"
 }
+
+sub assert_config_exists_on_node {
+    my ($vmid, $node) = @_;
+    return -f cfs_config_path("PVE::QemuConfig", $vmid, $node);
+}
 # END mocked PVE::QemuConfig methods
 
-# BEGIN redefine PVE::QemuServer methods
+# BEGIN mocked PVE::QemuServer::Helpers methods
 
-sub check_running {
+sub vm_running_locally {
     return $running;
 }
 
+# END mocked PVE::QemuServer::Helpers methods
 
-sub do_snapshots_with_qemu {
-    return 0;
-}
+# BEGIN mocked PVE::QemuServer::Monitor methods
 
-sub vm_qmp_command {
-    my ($vmid, $cmd, $nocheck) = @_;
+sub qmp_cmd {
+    my ($vmid, $cmd) = @_;
 
     my $exec = $cmd->{execute};
     if ($exec eq "delete-drive-snapshot") {
@@ -343,14 +347,22 @@ sub vm_qmp_command {
     die "unexpected vm_qmp_command!\n";
 }
 
+# END mocked PVE::QemuServer::Monitor methods
+
+# BEGIN redefine PVE::QemuServer methods
+
+sub do_snapshots_with_qemu {
+    return 0;
+}
+
 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;
 }
@@ -369,18 +381,36 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
-my $qemu_config_module = new Test::MockModule('PVE::QemuConfig');
+my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
+
+my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
+$qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
+
+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);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
 $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 = 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);
+$storage_module->mock('vdisk_free', \&mocked_vdisk_free);
+$storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
+$storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
+$storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
+$storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
 
 $running = 1;
 $freeze_possible = 1;
@@ -473,23 +503,10 @@ $vm_mon->{savevm_end} = 1;
 # possible, but fails
 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
 
-printf("\n");
-printf("Setting up Mocking for PVE::Storage\n");
-my $storage_module = new Test::MockModule('PVE::Storage');
-$storage_module->mock('config', sub { return undef; });
-$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);
-$storage_module->mock('vdisk_free', \&mocked_vdisk_free);
-$storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
-$storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
-$storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
-$storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
-printf("\tconfig(), volume_snapshot(), volume_snapshot_delete(), volume_snapshot_rollback() and volume_rollback_is_possible() mocked\n");
 
 #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");
 #
@@ -621,3 +638,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;