]> git.proxmox.com Git - qemu-server.git/blob - test/snapshot-test.pm
d26b4223f3fe47fee2e5332f144c7275ca0c6018
[qemu-server.git] / test / snapshot-test.pm
1 package PVE::QemuServer; ## no critic
2
3 use strict;
4 use warnings;
5
6 use lib qw(..);
7
8 use PVE::Storage;
9 use PVE::Storage::Plugin;
10 use PVE::QemuServer;
11 use PVE::QemuConfig;
12 use PVE::Tools;
13 use PVE::ReplicationConfig;
14
15 use Test::MockModule;
16 use Test::More;
17
18 my $activate_storage_possible = 1;
19 my $nodename;
20 my $snapshot_possible;
21 my $vol_snapshot_possible = {};
22 my $vol_snapshot_delete_possible = {};
23 my $vol_snapshot_rollback_possible = {};
24 my $vol_snapshot_rollback_enabled = {};
25 my $vol_snapshot = {};
26 my $vol_snapshot_delete = {};
27 my $vol_snapshot_rollback = {};
28 my $running;
29 my $freeze_possible;
30 my $stop_possible;
31 my $save_vmstate_works;
32 my $vm_mon = {};
33
34 # Mocked methods
35
36 sub mocked_volume_snapshot {
37 my ($storecfg, $volid, $snapname) = @_;
38 die "Storage config not mocked! aborting\n"
39 if defined($storecfg);
40 die "volid undefined\n"
41 if !defined($volid);
42 die "snapname undefined\n"
43 if !defined($snapname);
44 if ($vol_snapshot_possible->{$volid}) {
45 if (defined($vol_snapshot->{$volid})) {
46 $vol_snapshot->{$volid} .= ",$snapname";
47 } else {
48 $vol_snapshot->{$volid} = $snapname;
49 }
50 return 1;
51 } else {
52 die "volume snapshot disabled\n";
53 }
54 }
55
56 sub mocked_volume_snapshot_delete {
57 my ($storecfg, $volid, $snapname) = @_;
58 die "Storage config not mocked! aborting\n"
59 if defined($storecfg);
60 die "volid undefined\n"
61 if !defined($volid);
62 die "snapname undefined\n"
63 if !defined($snapname);
64 if ($vol_snapshot_delete_possible->{$volid}) {
65 if (defined($vol_snapshot_delete->{$volid})) {
66 $vol_snapshot_delete->{$volid} .= ",$snapname";
67 } else {
68 $vol_snapshot_delete->{$volid} = $snapname;
69 }
70 return 1;
71 } else {
72 die "volume snapshot delete disabled\n";
73 }
74 }
75
76 sub mocked_volume_snapshot_rollback {
77 my ($storecfg, $volid, $snapname) = @_;
78 die "Storage config not mocked! aborting\n"
79 if defined($storecfg);
80 die "volid undefined\n"
81 if !defined($volid);
82 die "snapname undefined\n"
83 if !defined($snapname);
84 if ($vol_snapshot_rollback_enabled->{$volid}) {
85 if (defined($vol_snapshot_rollback->{$volid})) {
86 $vol_snapshot_rollback->{$volid} .= ",$snapname";
87 } else {
88 $vol_snapshot_rollback->{$volid} = $snapname;
89 }
90 return 1;
91 } else {
92 die "volume snapshot rollback disabled\n";
93 }
94 }
95
96 sub mocked_volume_rollback_is_possible {
97 my ($storecfg, $volid, $snapname) = @_;
98 die "Storage config not mocked! aborting\n"
99 if defined($storecfg);
100 die "volid undefined\n"
101 if !defined($volid);
102 die "snapname undefined\n"
103 if !defined($snapname);
104 return $vol_snapshot_rollback_possible->{$volid}
105 if ($vol_snapshot_rollback_possible->{$volid});
106 die "volume_rollback_is_possible failed\n";
107 }
108
109 sub mocked_activate_storage {
110 my ($storecfg, $storeid) = @_;
111 die "Storage config not mocked! aborting\n"
112 if defined($storecfg);
113 die "storage activation failed\n"
114 if !$activate_storage_possible;
115 return;
116 }
117
118 sub mocked_activate_volumes {
119 my ($storecfg, $volumes) = @_;
120 die "Storage config not mocked! aborting\n"
121 if defined($storecfg);
122 die "wrong volume - fake vmstate expected!\n"
123 if ((scalar @$volumes != 1) || @$volumes[0] ne "somestorage:state-volume");
124 return;
125 }
126
127 sub mocked_deactivate_volumes {
128 my ($storecfg, $volumes) = @_;
129 die "Storage config not mocked! aborting\n"
130 if defined($storecfg);
131 die "wrong volume - fake vmstate expected!\n"
132 if ((scalar @$volumes != 1) || @$volumes[0] ne "somestorage:state-volume");
133 return;
134 }
135
136 sub mocked_vdisk_free {
137 my ($storecfg, $vmstate) = @_;
138 die "Storage config not mocked! aborting\n"
139 if defined($storecfg);
140 die "wrong vdisk - fake vmstate expected!\n"
141 if ($vmstate ne "somestorage:state-volume");
142 return;
143 }
144
145 sub mocked_run_command {
146 my ($cmd, %param) = @_;
147 my $cmdstring;
148 if (my $ref = ref($cmd)) {
149 $cmdstring = PVE::Tools::cmd2string($cmd);
150 if ($cmdstring =~ m/.*\/qemu-(un)?freeze.*/) {
151 return 1 if $freeze_possible;
152 die "qemu-[un]freeze disabled\n";
153 }
154 if ($cmdstring =~ m/.*\/qemu-stop.*--kill.*/) {
155 if ($stop_possible) {
156 $running = 0;
157 return 1;
158 } else {
159 return 0;
160 }
161 }
162 }
163 die "unexpected run_command call: '$cmdstring', aborting\n";
164 }
165
166 # Testing methods
167
168 sub test_file {
169 my ($exp_fn, $real_fn) = @_;
170 my $ret;
171 eval {
172 $ret = system("diff -u '$exp_fn' '$real_fn'");
173 };
174 die if $@;
175 return !$ret;
176 }
177
178 sub testcase_prepare {
179 my ($vmid, $snapname, $save_vmstate, $comment, $exp_err) = @_;
180 subtest "Preparing snapshot '$snapname' for vm '$vmid'" => sub {
181 plan tests => 2;
182 $@ = undef;
183 eval {
184 PVE::QemuConfig->__snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
185 };
186 is($@, $exp_err, "\$@ correct");
187 ok(test_file("snapshot-expected/prepare/qemu-server/$vmid.conf", "snapshot-working/prepare/qemu-server/$vmid.conf"), "config file correct");
188 };
189 }
190
191 sub testcase_commit {
192 my ($vmid, $snapname, $exp_err) = @_;
193 subtest "Committing snapshot '$snapname' for vm '$vmid'" => sub {
194 plan tests => 2;
195 $@ = undef;
196 eval {
197 PVE::QemuConfig->__snapshot_commit($vmid, $snapname);
198 };
199 is($@, $exp_err, "\$@ correct");
200 ok(test_file("snapshot-expected/commit/qemu-server/$vmid.conf", "snapshot-working/commit/qemu-server/$vmid.conf"), "config file correct");
201 }
202 }
203
204 sub testcase_create {
205 my ($vmid, $snapname, $save_vmstate, $comment, $exp_err, $exp_vol_snap, $exp_vol_snap_delete) = @_;
206 subtest "Creating snapshot '$snapname' for vm '$vmid'" => sub {
207 plan tests => 4;
208 $vol_snapshot = {};
209 $vol_snapshot_delete = {};
210 $exp_vol_snap = {} if !defined($exp_vol_snap);
211 $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
212 $@ = undef;
213 eval {
214 PVE::QemuConfig->snapshot_create($vmid, $snapname, $save_vmstate, $comment);
215 };
216 is($@, $exp_err, "\$@ correct");
217 is_deeply($vol_snapshot, $exp_vol_snap, "created correct volume snapshots");
218 is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
219 ok(test_file("snapshot-expected/create/qemu-server/$vmid.conf", "snapshot-working/create/qemu-server/$vmid.conf"), "config file correct");
220 };
221 }
222
223 sub testcase_delete {
224 my ($vmid, $snapname, $force, $exp_err, $exp_vol_snap_delete) = @_;
225 subtest "Deleting snapshot '$snapname' of vm '$vmid'" => sub {
226 plan tests => 3;
227 $vol_snapshot_delete = {};
228 $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
229 $@ = undef;
230 eval {
231 PVE::QemuConfig->snapshot_delete($vmid, $snapname, $force);
232 };
233 is($@, $exp_err, "\$@ correct");
234 is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
235 ok(test_file("snapshot-expected/delete/qemu-server/$vmid.conf", "snapshot-working/delete/qemu-server/$vmid.conf"), "config file correct");
236 };
237 }
238
239 sub testcase_rollback {
240 my ($vmid, $snapname, $exp_err, $exp_vol_snap_rollback) = @_;
241 subtest "Rolling back to snapshot '$snapname' of vm '$vmid'" => sub {
242 plan tests => 3;
243 $vol_snapshot_rollback = {};
244 $running = 1;
245 $exp_vol_snap_rollback = {} if !defined($exp_vol_snap_rollback);
246 $@ = undef;
247 eval {
248 PVE::QemuConfig->snapshot_rollback($vmid, $snapname);
249 };
250 is($@, $exp_err, "\$@ correct");
251 is_deeply($vol_snapshot_rollback, $exp_vol_snap_rollback, "rolled back to correct volume snapshots");
252 ok(test_file("snapshot-expected/rollback/qemu-server/$vmid.conf", "snapshot-working/rollback/qemu-server/$vmid.conf"), "config file correct");
253 };
254 }
255
256 # BEGIN mocked PVE::QemuConfig methods
257 sub config_file_lock {
258 return "snapshot-working/pve-test.lock";
259 }
260
261 sub cfs_config_path {
262 my ($class, $vmid, $node) = @_;
263
264 $node = $nodename if !$node;
265 return "snapshot-working/$node/qemu-server/$vmid.conf";
266 }
267
268 sub load_config {
269 my ($class, $vmid, $node) = @_;
270
271 my $filename = $class->cfs_config_path($vmid, $node);
272
273 my $raw = PVE::Tools::file_get_contents($filename);
274
275 my $conf = PVE::QemuServer::parse_vm_config($filename, $raw);
276 return $conf;
277 }
278
279 sub write_config {
280 my ($class, $vmid, $conf) = @_;
281
282 my $filename = $class->cfs_config_path($vmid);
283
284 if ($conf->{snapshots}) {
285 foreach my $snapname (keys %{$conf->{snapshots}}) {
286 $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
287 if $conf->{snapshots}->{$snapname}->{snaptime};
288 }
289 }
290
291 my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
292
293 PVE::Tools::file_set_contents($filename, $raw);
294 }
295
296 sub has_feature {
297 my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
298 return $snapshot_possible;
299 }
300
301 sub __snapshot_save_vmstate {
302 my ($class, $vmid, $conf, $snapname, $storecfg) = @_;
303 die "save_vmstate failed\n"
304 if !$save_vmstate_works;
305
306 my $snap = $conf->{snapshots}->{$snapname};
307 $snap->{vmstate} = "somestorage:state-volume";
308 $snap->{runningmachine} = "somemachine"
309 }
310
311 sub assert_config_exists_on_node {
312 my ($vmid, $node) = @_;
313 return -f cfs_config_path("PVE::QemuConfig", $vmid, $node);
314 }
315 # END mocked PVE::QemuConfig methods
316
317 # BEGIN mocked PVE::QemuServer::Helpers methods
318
319 sub vm_running_locally {
320 return $running;
321 }
322
323 # END mocked PVE::QemuServer::Helpers methods
324
325 # BEGIN mocked PVE::QemuServer::Monitor methods
326
327 sub qmp_cmd {
328 my ($vmid, $cmd) = @_;
329
330 my $exec = $cmd->{execute};
331 if ($exec eq "delete-drive-snapshot") {
332 return;
333 }
334 if ($exec eq "guest-ping") {
335 die "guest-ping disabled\n"
336 if !$vm_mon->{guest_ping};
337 return;
338 }
339 if ($exec eq "guest-fsfreeze-freeze" || $exec eq "guest-fsfreeze-thaw") {
340 die "freeze disabled\n"
341 if !$freeze_possible;
342 return;
343 }
344 if ($exec eq "savevm-start") {
345 die "savevm-start disabled\n"
346 if !$vm_mon->{savevm_start};
347 return;
348 }
349 if ($exec eq "savevm-end") {
350 die "savevm-end disabled\n"
351 if !$vm_mon->{savevm_end};
352 return;
353 }
354 if ($exec eq "query-savevm") {
355 return {
356 "status" => "completed",
357 "bytes" => 1024*1024*1024,
358 "total-time" => 5000,
359 };
360 }
361 die "unexpected vm_qmp_command!\n";
362 }
363
364 # END mocked PVE::QemuServer::Monitor methods
365
366 # BEGIN redefine PVE::QemuServer methods
367
368 sub do_snapshots_with_qemu {
369 return 0;
370 }
371
372 sub vm_start {
373 my ($storecfg, $vmid, $params, $migrate_opts) = @_;
374
375 die "Storage config not mocked! aborting\n"
376 if defined($storecfg);
377
378 die "statefile and forcemachine must be both defined or undefined! aborting\n"
379 if defined($params->{statefile}) xor defined($params->{forcemachine});
380
381 return;
382 }
383
384 sub vm_stop {
385 my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive, $migratedfrom) = @_;
386
387 $running = 0
388 if $stop_possible;
389
390 return;
391 }
392
393 sub set_migration_caps {} # ignored
394
395 # END redefine PVE::QemuServer methods
396
397 PVE::Tools::run_command("rm -rf snapshot-working");
398 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
399
400 my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
401 $qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
402
403 my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
404 $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
405
406 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
407 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
408 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
409 $qemu_config_module->mock('load_config', \&load_config);
410 $qemu_config_module->mock('write_config', \&write_config);
411 $qemu_config_module->mock('has_feature', \&has_feature);
412 $qemu_config_module->mock('__snapshot_save_vmstate', \&__snapshot_save_vmstate);
413 $qemu_config_module->mock('assert_config_exists_on_node', \&assert_config_exists_on_node);
414
415 # ignore existing replication config
416 my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
417 $repl_config_module->mock('new' => sub { return bless {}, "PVE::ReplicationConfig" });
418 $repl_config_module->mock('check_for_existing_jobs' => sub { return });
419
420 my $storage_module = Test::MockModule->new('PVE::Storage');
421 $storage_module->mock('config', sub { return; });
422 $storage_module->mock('path', sub { return "/some/store/statefile/path"; });
423 $storage_module->mock('activate_storage', \&mocked_activate_storage);
424 $storage_module->mock('activate_volumes', \&mocked_activate_volumes);
425 $storage_module->mock('deactivate_volumes', \&mocked_deactivate_volumes);
426 $storage_module->mock('vdisk_free', \&mocked_vdisk_free);
427 $storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
428 $storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
429 $storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
430 $storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
431
432 $running = 1;
433 $freeze_possible = 1;
434 $save_vmstate_works = 1;
435
436 printf("\n");
437 printf("Running prepare tests\n");
438 printf("\n");
439 $nodename = "prepare";
440
441 printf("\n");
442 printf("Setting has_feature to return true\n");
443 printf("\n");
444 $snapshot_possible = 1;
445
446 printf("Successful snapshot_prepare with no existing snapshots\n");
447 testcase_prepare("101", "test", 0, "test comment", '');
448
449 printf("Successful snapshot_prepare with no existing snapshots, including vmstate\n");
450 testcase_prepare("102", "test", 1, "test comment", '');
451
452 printf("Successful snapshot_prepare with one existing snapshot\n");
453 testcase_prepare("103", "test2", 0, "test comment", "");
454
455 printf("Successful snapshot_prepare with one existing snapshot, including vmstate\n");
456 testcase_prepare("104", "test2", 1, "test comment", "");
457
458 printf("Expected error for snapshot_prepare on locked container\n");
459 testcase_prepare("200", "test", 0, "test comment", "VM is locked (snapshot)\n");
460
461 printf("Expected error for snapshot_prepare with duplicate snapshot name\n");
462 testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
463
464 $save_vmstate_works = 0;
465
466 printf("Expected error for snapshot_prepare with failing save_vmstate\n");
467 testcase_prepare("202", "test", 1, "test comment", "save_vmstate failed\n");
468
469 $save_vmstate_works = 1;
470
471 printf("\n");
472 printf("Setting has_feature to return false\n");
473 printf("\n");
474 $snapshot_possible = 0;
475
476 printf("Expected error for snapshot_prepare if snapshots not possible\n");
477 testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
478
479 printf("\n");
480 printf("Running commit tests\n");
481 printf("\n");
482 $nodename = "commit";
483
484 printf("\n");
485 printf("Setting has_feature to return true\n");
486 printf("\n");
487 $snapshot_possible = 1;
488
489 printf("Successful snapshot_commit with one prepared snapshot\n");
490 testcase_commit("101", "test", "");
491
492 printf("Successful snapshot_commit with one committed and one prepared snapshot\n");
493 testcase_commit("102", "test2", "");
494
495 printf("Expected error for snapshot_commit with no snapshot lock\n");
496 testcase_commit("201", "test", "missing snapshot lock\n");
497
498 printf("Expected error for snapshot_commit with invalid snapshot name\n");
499 testcase_commit("202", "test", "snapshot 'test' does not exist\n");
500
501 printf("Expected error for snapshot_commit with invalid snapshot state\n");
502 testcase_commit("203", "test", "wrong snapshot state\n");
503
504 $vol_snapshot_possible->{"local:snapshotable-disk-1"} = 1;
505 $vol_snapshot_possible->{"local:snapshotable-disk-2"} = 1;
506 $vol_snapshot_possible->{"local:snapshotable-disk-3"} = 1;
507 $vol_snapshot_delete_possible->{"local:snapshotable-disk-1"} = 1;
508 $vol_snapshot_delete_possible->{"local:snapshotable-disk-3"} = 1;
509 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-1"} = 1;
510 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-2"} = 1;
511 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-3"} = 1;
512 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-1"} = 1;
513 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-2"} = 1;
514 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-3"} = 1;
515 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
516 $vm_mon->{guest_ping} = 1;
517 $vm_mon->{savevm_start} = 1;
518 $vm_mon->{savevm_end} = 1;
519
520 # possible, but fails
521 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
522
523
524 #printf("\n");
525 #printf("Setting up Mocking for PVE::Tools\n");
526 #my $tools_module = Test::MockModule->new('PVE::Tools');
527 #$tools_module->mock('run_command' => \&mocked_run_command);
528 #printf("\trun_command() mocked\n");
529 #
530 $nodename = "create";
531 printf("\n");
532 printf("Running create tests\n");
533 printf("\n");
534
535 printf("Successful snapshot_create with no existing snapshots\n");
536 testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
537
538 printf("Successful snapshot_create with no existing snapshots, including vmstate\n");
539 testcase_create("102", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
540
541 printf("Successful snapshot_create with one existing snapshots\n");
542 testcase_create("103", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
543
544 printf("Successful snapshot_create with one existing snapshots, including vmstate\n");
545 testcase_create("104", "test2", 1, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
546
547 printf("Successful snapshot_create with multiple mps\n");
548 testcase_create("105", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
549
550 $freeze_possible = 0;
551 printf("Successful snapshot_create with no existing snapshots and broken freeze\n");
552 testcase_create("106", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
553 $freeze_possible = 1;
554
555 printf("Expected error for snapshot_create when volume snapshot is not possible\n");
556 testcase_create("201", "test", 0, "test comment", "volume snapshot disabled\n\n");
557
558 printf("Expected error for snapshot_create when volume snapshot is not possible for one drive\n");
559 testcase_create("202", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" });
560
561 $vm_mon->{savevm_start} = 0;
562 printf("Expected error for snapshot_create when QEMU mon command 'savevm-start' fails\n");
563 testcase_create("203", "test", 0, "test comment", "savevm-start disabled\n\n");
564 $vm_mon->{savevm_start} = 1;
565
566 printf("Successful snapshot_create with no existing snapshots but set machine type\n");
567 testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
568
569 $activate_storage_possible = 0;
570
571 printf("Expected error for snapshot_create when storage activation is not possible\n");
572 testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n");
573
574 $activate_storage_possible = 1;
575
576 $nodename = "delete";
577 printf("\n");
578 printf("Running delete tests\n");
579 printf("\n");
580
581 printf("Successful snapshot_delete of only existing snapshot\n");
582 testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
583
584 printf("Successful snapshot_delete of leaf snapshot\n");
585 testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
586
587 printf("Successful snapshot_delete of root snapshot\n");
588 testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
589
590 printf("Successful snapshot_delete of intermediate snapshot\n");
591 testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
592
593 printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1\n");
594 testcase_delete("105", "test", 1, "");
595
596 printf("Successful snapshot_delete with mp broken volume_snapshot_delete and force=1\n");
597 testcase_delete("106", "test", 1, "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-3" => "test" });
598
599 printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0\n");
600 testcase_delete("201", "test", 0, "volume snapshot delete disabled\n");
601
602 printf("Expected error when snapshot_delete fails with broken mp volume_snapshot_delete and force=0\n");
603 testcase_delete("202", "test", 0, "volume snapshot delete disabled\n", { "local:snapshotable-disk-1" => "test" });
604
605 printf("Expected error for snapshot_delete with locked config\n");
606 testcase_delete("203", "test", 0, "VM is locked (backup)\n");
607
608 $activate_storage_possible = 0;
609
610 printf("Expected error for snapshot_delete when storage activation is not possible\n");
611 testcase_delete("204", "test", 0, "storage activation failed\n");
612
613 $activate_storage_possible = 1;
614
615 $nodename = "rollback";
616 printf("\n");
617 printf("Running rollback tests\n");
618 printf("\n");
619
620 $stop_possible = 1;
621
622 printf("Successful snapshot_rollback to only existing snapshot\n");
623 testcase_rollback("101", "test", "", { "local:snapshotable-disk-1" => "test" });
624
625 printf("Successful snapshot_rollback to leaf snapshot\n");
626 testcase_rollback("102", "test2", "", { "local:snapshotable-disk-1" => "test2" });
627
628 printf("Successful snapshot_rollback to root snapshot\n");
629 testcase_rollback("103", "test", "", { "local:snapshotable-disk-1" => "test" });
630
631 printf("Successful snapshot_rollback to intermediate snapshot\n");
632 testcase_rollback("104", "test2", "", { "local:snapshotable-disk-1" => "test2" });
633
634 printf("Successful snapshot_rollback with multiple mp\n");
635 testcase_rollback("105", "test", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
636
637 printf("Successful snapshot_rollback to only existing snapshot, with saved vmstate and machine config\n");
638 testcase_rollback("106", "test", "", { "local:snapshotable-disk-1" => "test" });
639
640 printf("Expected error for snapshot_rollback with non-existing snapshot\n");
641 testcase_rollback("201", "test2", "snapshot 'test2' does not exist\n");
642
643 printf("Expected error for snapshot_rollback if volume rollback not possible\n");
644 testcase_rollback("202", "test", "volume_rollback_is_possible failed\n");
645
646 printf("Expected error for snapshot_rollback with incomplete snapshot\n");
647 testcase_rollback("203", "test", "unable to rollback to incomplete snapshot (snapstate = delete)\n");
648
649 printf("Expected error for snapshot_rollback with lock\n");
650 testcase_rollback("204", "test", "VM is locked (backup)\n");
651
652 $stop_possible = 0;
653
654 printf("Expected error for snapshot_rollback with unkillable container\n");
655 testcase_rollback("205", "test", "unable to rollback vm 205: vm is running\n");
656
657 $stop_possible = 1;
658
659 printf("Expected error for snapshot_rollback with mp rollback_is_possible failure\n");
660 testcase_rollback("206", "test", "volume_rollback_is_possible failed\n");
661
662 printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
663 testcase_rollback("207", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
664
665 printf("Successful snapshot_rollback with saved vmstate and machine config only in snapshot\n");
666 testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" });
667
668 printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n");
669 testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
670
671 $activate_storage_possible = 0;
672
673 printf("Expected error for snapshot_rollback when storage activation is not possible\n");
674 testcase_rollback("303", "test", "storage activation failed\n");
675
676 $activate_storage_possible = 1;
677
678 done_testing();
679
680 1;