]> git.proxmox.com Git - qemu-server.git/blob - test/snapshot-test.pm
schema: fix description of migrate_downtime parameter
[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} = "q35"
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 "guest-ping") {
332 die "guest-ping disabled\n"
333 if !$vm_mon->{guest_ping};
334 return;
335 }
336 if ($exec eq "guest-fsfreeze-freeze" || $exec eq "guest-fsfreeze-thaw") {
337 die "freeze disabled\n"
338 if !$freeze_possible;
339 return;
340 }
341 if ($exec eq "savevm-start") {
342 die "savevm-start disabled\n"
343 if !$vm_mon->{savevm_start};
344 return;
345 }
346 if ($exec eq "savevm-end") {
347 die "savevm-end disabled\n"
348 if !$vm_mon->{savevm_end};
349 return;
350 }
351 if ($exec eq "query-savevm") {
352 return {
353 "status" => "completed",
354 "bytes" => 1024*1024*1024,
355 "total-time" => 5000,
356 };
357 }
358 die "unexpected vm_qmp_command!\n";
359 }
360
361 # END mocked PVE::QemuServer::Monitor methods
362
363 # BEGIN redefine PVE::QemuServer methods
364
365 sub do_snapshots_with_qemu {
366 return 0;
367 }
368
369 sub vm_start {
370 my ($storecfg, $vmid, $params, $migrate_opts) = @_;
371
372 die "Storage config not mocked! aborting\n"
373 if defined($storecfg);
374
375 die "statefile and forcemachine must be both defined or undefined! aborting\n"
376 if defined($params->{statefile}) xor defined($params->{forcemachine});
377
378 return;
379 }
380
381 sub vm_stop {
382 my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive, $migratedfrom) = @_;
383
384 $running = 0
385 if $stop_possible;
386
387 return;
388 }
389
390 sub set_migration_caps {} # ignored
391
392 # END redefine PVE::QemuServer methods
393
394 PVE::Tools::run_command("rm -rf snapshot-working");
395 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
396
397 my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
398 $qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
399
400 my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
401 $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
402
403 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
404 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
405 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
406 $qemu_config_module->mock('load_config', \&load_config);
407 $qemu_config_module->mock('write_config', \&write_config);
408 $qemu_config_module->mock('has_feature', \&has_feature);
409 $qemu_config_module->mock('__snapshot_save_vmstate', \&__snapshot_save_vmstate);
410 $qemu_config_module->mock('assert_config_exists_on_node', \&assert_config_exists_on_node);
411
412 # ignore existing replication config
413 my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
414 $repl_config_module->mock('new' => sub { return bless {}, "PVE::ReplicationConfig" });
415 $repl_config_module->mock('check_for_existing_jobs' => sub { return });
416
417 my $storage_module = Test::MockModule->new('PVE::Storage');
418 $storage_module->mock('config', sub { return; });
419 $storage_module->mock('path', sub { return "/some/store/statefile/path"; });
420 $storage_module->mock('activate_storage', \&mocked_activate_storage);
421 $storage_module->mock('activate_volumes', \&mocked_activate_volumes);
422 $storage_module->mock('deactivate_volumes', \&mocked_deactivate_volumes);
423 $storage_module->mock('vdisk_free', \&mocked_vdisk_free);
424 $storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
425 $storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
426 $storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
427 $storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
428
429 $running = 1;
430 $freeze_possible = 1;
431 $save_vmstate_works = 1;
432
433 printf("\n");
434 printf("Running prepare tests\n");
435 printf("\n");
436 $nodename = "prepare";
437
438 printf("\n");
439 printf("Setting has_feature to return true\n");
440 printf("\n");
441 $snapshot_possible = 1;
442
443 printf("Successful snapshot_prepare with no existing snapshots\n");
444 testcase_prepare("101", "test", 0, "test comment", '');
445
446 printf("Successful snapshot_prepare with no existing snapshots, including vmstate\n");
447 testcase_prepare("102", "test", 1, "test comment", '');
448
449 printf("Successful snapshot_prepare with one existing snapshot\n");
450 testcase_prepare("103", "test2", 0, "test comment", "");
451
452 printf("Successful snapshot_prepare with one existing snapshot, including vmstate\n");
453 testcase_prepare("104", "test2", 1, "test comment", "");
454
455 printf("Expected error for snapshot_prepare on locked container\n");
456 testcase_prepare("200", "test", 0, "test comment", "VM is locked (snapshot)\n");
457
458 printf("Expected error for snapshot_prepare with duplicate snapshot name\n");
459 testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
460
461 $save_vmstate_works = 0;
462
463 printf("Expected error for snapshot_prepare with failing save_vmstate\n");
464 testcase_prepare("202", "test", 1, "test comment", "save_vmstate failed\n");
465
466 $save_vmstate_works = 1;
467
468 printf("\n");
469 printf("Setting has_feature to return false\n");
470 printf("\n");
471 $snapshot_possible = 0;
472
473 printf("Expected error for snapshot_prepare if snapshots not possible\n");
474 testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
475
476 printf("\n");
477 printf("Running commit tests\n");
478 printf("\n");
479 $nodename = "commit";
480
481 printf("\n");
482 printf("Setting has_feature to return true\n");
483 printf("\n");
484 $snapshot_possible = 1;
485
486 printf("Successful snapshot_commit with one prepared snapshot\n");
487 testcase_commit("101", "test", "");
488
489 printf("Successful snapshot_commit with one committed and one prepared snapshot\n");
490 testcase_commit("102", "test2", "");
491
492 printf("Expected error for snapshot_commit with no snapshot lock\n");
493 testcase_commit("201", "test", "missing snapshot lock\n");
494
495 printf("Expected error for snapshot_commit with invalid snapshot name\n");
496 testcase_commit("202", "test", "snapshot 'test' does not exist\n");
497
498 printf("Expected error for snapshot_commit with invalid snapshot state\n");
499 testcase_commit("203", "test", "wrong snapshot state\n");
500
501 $vol_snapshot_possible->{"local:snapshotable-disk-1"} = 1;
502 $vol_snapshot_possible->{"local:snapshotable-disk-2"} = 1;
503 $vol_snapshot_possible->{"local:snapshotable-disk-3"} = 1;
504 $vol_snapshot_delete_possible->{"local:snapshotable-disk-1"} = 1;
505 $vol_snapshot_delete_possible->{"local:snapshotable-disk-3"} = 1;
506 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-1"} = 1;
507 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-2"} = 1;
508 $vol_snapshot_rollback_enabled->{"local:snapshotable-disk-3"} = 1;
509 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-1"} = 1;
510 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-2"} = 1;
511 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-3"} = 1;
512 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
513 $vm_mon->{guest_ping} = 1;
514 $vm_mon->{savevm_start} = 1;
515 $vm_mon->{savevm_end} = 1;
516
517 # possible, but fails
518 $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
519
520
521 #printf("\n");
522 #printf("Setting up Mocking for PVE::Tools\n");
523 #my $tools_module = Test::MockModule->new('PVE::Tools');
524 #$tools_module->mock('run_command' => \&mocked_run_command);
525 #printf("\trun_command() mocked\n");
526 #
527 $nodename = "create";
528 printf("\n");
529 printf("Running create tests\n");
530 printf("\n");
531
532 printf("Successful snapshot_create with no existing snapshots\n");
533 testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
534
535 printf("Successful snapshot_create with no existing snapshots, including vmstate\n");
536 testcase_create("102", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
537
538 printf("Successful snapshot_create with one existing snapshots\n");
539 testcase_create("103", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
540
541 printf("Successful snapshot_create with one existing snapshots, including vmstate\n");
542 testcase_create("104", "test2", 1, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
543
544 printf("Successful snapshot_create with multiple mps\n");
545 testcase_create("105", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
546
547 $freeze_possible = 0;
548 printf("Successful snapshot_create with no existing snapshots and broken freeze\n");
549 testcase_create("106", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
550 $freeze_possible = 1;
551
552 printf("Expected error for snapshot_create when volume snapshot is not possible\n");
553 testcase_create("201", "test", 0, "test comment", "volume snapshot disabled\n\n");
554
555 printf("Expected error for snapshot_create when volume snapshot is not possible for one drive\n");
556 testcase_create("202", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" });
557
558 $vm_mon->{savevm_start} = 0;
559 printf("Expected error for snapshot_create when QEMU mon command 'savevm-start' fails\n");
560 testcase_create("203", "test", 0, "test comment", "savevm-start disabled\n\n");
561 $vm_mon->{savevm_start} = 1;
562
563 printf("Successful snapshot_create with no existing snapshots but set machine type\n");
564 testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
565
566 $activate_storage_possible = 0;
567
568 printf("Expected error for snapshot_create when storage activation is not possible\n");
569 testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n");
570
571 $activate_storage_possible = 1;
572
573 $nodename = "delete";
574 printf("\n");
575 printf("Running delete tests\n");
576 printf("\n");
577
578 printf("Successful snapshot_delete of only existing snapshot\n");
579 testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
580
581 printf("Successful snapshot_delete of leaf snapshot\n");
582 testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
583
584 printf("Successful snapshot_delete of root snapshot\n");
585 testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
586
587 printf("Successful snapshot_delete of intermediate snapshot\n");
588 testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
589
590 printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1\n");
591 testcase_delete("105", "test", 1, "");
592
593 printf("Successful snapshot_delete with mp broken volume_snapshot_delete and force=1\n");
594 testcase_delete("106", "test", 1, "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-3" => "test" });
595
596 printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0\n");
597 testcase_delete("201", "test", 0, "volume snapshot delete disabled\n");
598
599 printf("Expected error when snapshot_delete fails with broken mp volume_snapshot_delete and force=0\n");
600 testcase_delete("202", "test", 0, "volume snapshot delete disabled\n", { "local:snapshotable-disk-1" => "test" });
601
602 printf("Expected error for snapshot_delete with locked config\n");
603 testcase_delete("203", "test", 0, "VM is locked (backup)\n");
604
605 $activate_storage_possible = 0;
606
607 printf("Expected error for snapshot_delete when storage activation is not possible\n");
608 testcase_delete("204", "test", 0, "storage activation failed\n");
609
610 $activate_storage_possible = 1;
611
612 $nodename = "rollback";
613 printf("\n");
614 printf("Running rollback tests\n");
615 printf("\n");
616
617 $stop_possible = 1;
618
619 printf("Successful snapshot_rollback to only existing snapshot\n");
620 testcase_rollback("101", "test", "", { "local:snapshotable-disk-1" => "test" });
621
622 printf("Successful snapshot_rollback to leaf snapshot\n");
623 testcase_rollback("102", "test2", "", { "local:snapshotable-disk-1" => "test2" });
624
625 printf("Successful snapshot_rollback to root snapshot\n");
626 testcase_rollback("103", "test", "", { "local:snapshotable-disk-1" => "test" });
627
628 printf("Successful snapshot_rollback to intermediate snapshot\n");
629 testcase_rollback("104", "test2", "", { "local:snapshotable-disk-1" => "test2" });
630
631 printf("Successful snapshot_rollback with multiple mp\n");
632 testcase_rollback("105", "test", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
633
634 printf("Successful snapshot_rollback to only existing snapshot, with saved vmstate and machine config\n");
635 testcase_rollback("106", "test", "", { "local:snapshotable-disk-1" => "test" });
636
637 printf("Expected error for snapshot_rollback with non-existing snapshot\n");
638 testcase_rollback("201", "test2", "snapshot 'test2' does not exist\n");
639
640 printf("Expected error for snapshot_rollback if volume rollback not possible\n");
641 testcase_rollback("202", "test", "volume_rollback_is_possible failed\n");
642
643 printf("Expected error for snapshot_rollback with incomplete snapshot\n");
644 testcase_rollback("203", "test", "unable to rollback to incomplete snapshot (snapstate = delete)\n");
645
646 printf("Expected error for snapshot_rollback with lock\n");
647 testcase_rollback("204", "test", "VM is locked (backup)\n");
648
649 $stop_possible = 0;
650
651 printf("Expected error for snapshot_rollback with unkillable container\n");
652 testcase_rollback("205", "test", "unable to rollback vm 205: vm is running\n");
653
654 $stop_possible = 1;
655
656 printf("Expected error for snapshot_rollback with mp rollback_is_possible failure\n");
657 testcase_rollback("206", "test", "volume_rollback_is_possible failed\n");
658
659 printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
660 testcase_rollback("207", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
661
662 printf("Successful snapshot_rollback with saved vmstate and machine config only in snapshot\n");
663 testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" });
664
665 printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n");
666 testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
667
668 $activate_storage_possible = 0;
669
670 printf("Expected error for snapshot_rollback when storage activation is not possible\n");
671 testcase_rollback("303", "test", "storage activation failed\n");
672
673 $activate_storage_possible = 1;
674
675 done_testing();
676
677 1;