]> git.proxmox.com Git - qemu-server.git/blobdiff - test/snapshot-test.pm
d/control: remove unused dependency
[qemu-server.git] / test / snapshot-test.pm
index 43b1515e79f4bad7f48c6799d6cba97990a93983..c95e7f37b3e0fc0eddd0f8d819a3c84ffbb54727 100644 (file)
@@ -10,6 +10,7 @@ use PVE::Storage::Plugin;
 use PVE::QemuServer;
 use PVE::QemuConfig;
 use PVE::Tools;
+use PVE::ReplicationConfig;
 
 use Test::MockModule;
 use Test::More;
@@ -104,6 +105,24 @@ sub mocked_volume_rollback_is_possible {
     die "volume_rollback_is_possible failed\n";
 }
 
+sub mocked_activate_volumes {
+    my ($storecfg, $volumes) = @_;
+    die "Storage config not mocked! aborting\n"
+       if defined($storecfg);
+    die "wrong volume - fake vmstate expected!\n"
+       if ((scalar @$volumes != 1) || @$volumes[0] ne "somestorage:state-volume");
+    return;
+}
+
+sub mocked_deactivate_volumes {
+    my ($storecfg, $volumes) = @_;
+    die "Storage config not mocked! aborting\n"
+       if defined($storecfg);
+    die "wrong volume - fake vmstate expected!\n"
+       if ((scalar @$volumes != 1) || @$volumes[0] ne "somestorage:state-volume");
+    return;
+}
+
 sub mocked_vdisk_free {
     my ($storecfg, $vmstate) = @_;
     die "Storage config not mocked! aborting\n"
@@ -276,7 +295,7 @@ sub __snapshot_save_vmstate {
 
     my $snap = $conf->{snapshots}->{$snapname};
     $snap->{vmstate} = "somestorage:state-volume";
-    $snap->{machine} = "somemachine";
+    $snap->{runningmachine} = "somemachine"
 }
 # END mocked PVE::QemuConfig methods
 
@@ -358,6 +377,10 @@ $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);
 
+# ignore existing replication config
+my $repl_config_module = new Test::MockModule('PVE::ReplicationConfig');
+$repl_config_module->mock('check_for_existing_jobs' => sub { return undef });
+
 $running = 1;
 $freeze_possible = 1;
 $save_vmstate_works = 1;
@@ -454,6 +477,8 @@ 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);
@@ -503,6 +528,8 @@ printf("Expected error for snapshot_create when Qemu mon command 'savevm-start'
 testcase_create("203", "test", 0, "test comment", "savevm-start disabled\n\n");
 $vm_mon->{savevm_start} = 1;
 
+printf("Successful snapshot_create with no existing snapshots but set machine type\n");
+testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
 
 $nodename = "delete";
 printf("\n");
@@ -586,4 +613,10 @@ testcase_rollback("206", "test", "volume_rollback_is_possible failed\n");
 printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
 testcase_rollback("207", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
 
+printf("Successful snapshot_rollback with saved vmstate and machine config only in snapshot\n");
+testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n");
+testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
+
 done_testing();