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