]> git.proxmox.com Git - qemu-server.git/blame - test/snapshot-test.pm
tree wide cleanups
[qemu-server.git] / test / snapshot-test.pm
CommitLineData
a157d0fd
FG
1package PVE::QemuServer;
2
3use strict;
4use warnings;
5
6use lib qw(..);
7
8use PVE::Storage;
9use PVE::Storage::Plugin;
10use PVE::QemuServer;
ffda963f 11use PVE::QemuConfig;
a157d0fd 12use PVE::Tools;
d79a3e54 13use PVE::ReplicationConfig;
a157d0fd
FG
14
15use Test::MockModule;
16use Test::More;
17
18my $nodename;
19my $snapshot_possible;
20my $vol_snapshot_possible = {};
21my $vol_snapshot_delete_possible = {};
22my $vol_snapshot_rollback_possible = {};
23my $vol_snapshot_rollback_enabled = {};
24my $vol_snapshot = {};
25my $vol_snapshot_delete = {};
26my $vol_snapshot_rollback = {};
27my $running;
28my $freeze_possible;
29my $stop_possible;
30my $save_vmstate_works;
31my $vm_mon = {};
32
33# Mocked methods
34
35sub 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
55sub 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
75sub 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
95sub 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
101a1b3f
FG
108sub 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
117sub 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
a157d0fd
FG
126sub 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
135sub 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
158sub 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
168sub 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 {
b2c9558d 174 PVE::QemuConfig->__snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
a157d0fd
FG
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
181sub 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 {
b2c9558d 187 PVE::QemuConfig->__snapshot_commit($vmid, $snapname);
a157d0fd
FG
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
194sub 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 {
b2c9558d 204 PVE::QemuConfig->snapshot_create($vmid, $snapname, $save_vmstate, $comment);
a157d0fd
FG
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
213sub 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 {
b2c9558d 221 PVE::QemuConfig->snapshot_delete($vmid, $snapname, $force);
a157d0fd
FG
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
229sub 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 {
b2c9558d 238 PVE::QemuConfig->snapshot_rollback($vmid, $snapname);
a157d0fd
FG
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
ffda963f 246# BEGIN mocked PVE::QemuConfig methods
a157d0fd
FG
247sub config_file_lock {
248 return "snapshot-working/pve-test.lock";
249}
250
251sub cfs_config_path {
ffda963f 252 my ($class, $vmid, $node) = @_;
a157d0fd
FG
253
254 $node = $nodename if !$node;
255 return "snapshot-working/$node/qemu-server/$vmid.conf";
256}
257
258sub load_config {
ffda963f 259 my ($class, $vmid, $node) = @_;
a157d0fd 260
ffda963f 261 my $filename = $class->cfs_config_path($vmid, $node);
a157d0fd
FG
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
269sub write_config {
ffda963f 270 my ($class, $vmid, $conf) = @_;
a157d0fd 271
ffda963f 272 my $filename = $class->cfs_config_path($vmid);
a157d0fd
FG
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
286sub has_feature {
b2c9558d 287 my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
a157d0fd
FG
288 return $snapshot_possible;
289}
290
b2c9558d
FG
291sub __snapshot_save_vmstate {
292 my ($class, $vmid, $conf, $snapname, $storecfg) = @_;
a157d0fd
FG
293 die "save_vmstate failed\n"
294 if !$save_vmstate_works;
295
296 my $snap = $conf->{snapshots}->{$snapname};
297 $snap->{vmstate} = "somestorage:state-volume";
c6737ef1 298 $snap->{runningmachine} = "somemachine"
a157d0fd 299}
babf613a
SR
300
301sub assert_config_exists_on_node {
302 my ($vmid, $node) = @_;
bf116bdf 303 return -f cfs_config_path("PVE::QemuConfig", $vmid, $node);
babf613a 304}
b2c9558d
FG
305# END mocked PVE::QemuConfig methods
306
babf613a 307# BEGIN mocked PVE::QemuServer::Helpers methods
b2c9558d 308
babf613a 309sub vm_running_locally {
b2c9558d
FG
310 return $running;
311}
312
babf613a
SR
313# END mocked PVE::QemuServer::Helpers methods
314
0a13e08e 315# BEGIN mocked PVE::QemuServer::Monitor methods
a157d0fd 316
0a13e08e 317sub qmp_cmd {
8b26544e 318 my ($vmid, $cmd) = @_;
a157d0fd
FG
319
320 my $exec = $cmd->{execute};
321 if ($exec eq "delete-drive-snapshot") {
322 return;
323 }
324 if ($exec eq "guest-ping") {
325 die "guest-ping disabled\n"
326 if !$vm_mon->{guest_ping};
327 return;
328 }
329 if ($exec eq "guest-fsfreeze-freeze" || $exec eq "guest-fsfreeze-thaw") {
330 die "freeze disabled\n"
331 if !$freeze_possible;
332 return;
333 }
334 if ($exec eq "savevm-start") {
335 die "savevm-start disabled\n"
336 if !$vm_mon->{savevm_start};
337 return;
338 }
339 if ($exec eq "savevm-end") {
340 die "savevm-end disabled\n"
341 if !$vm_mon->{savevm_end};
342 return;
343 }
344 if ($exec eq "query-savevm") {
345 return { "status" => "completed" };
346 }
347 die "unexpected vm_qmp_command!\n";
348}
349
0a13e08e
SR
350# END mocked PVE::QemuServer::Monitor methods
351
352# BEGIN redefine PVE::QemuServer methods
353
354sub do_snapshots_with_qemu {
355 return 0;
356}
357
a157d0fd 358sub vm_start {
0c498cca 359 my ($storecfg, $vmid, $params, $migrate_opts) = @_;
a157d0fd
FG
360
361 die "Storage config not mocked! aborting\n"
362 if defined($storecfg);
363
364 die "statefile and forcemachine must be both defined or undefined! aborting\n"
0c498cca 365 if defined($params->{statefile}) xor defined($params->{forcemachine});
a157d0fd
FG
366
367 return;
368}
369
370sub vm_stop {
371 my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive, $migratedfrom) = @_;
372
373 $running = 0
374 if $stop_possible;
375
376 return;
377}
378
379# END redefine PVE::QemuServer methods
380
381PVE::Tools::run_command("rm -rf snapshot-working");
382PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
383
f7d1505b 384my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
babf613a
SR
385$qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
386
f7d1505b 387my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
0a13e08e
SR
388$qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
389
f7d1505b 390my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
ffda963f
FG
391$qemu_config_module->mock('config_file_lock', \&config_file_lock);
392$qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
393$qemu_config_module->mock('load_config', \&load_config);
394$qemu_config_module->mock('write_config', \&write_config);
b2c9558d
FG
395$qemu_config_module->mock('has_feature', \&has_feature);
396$qemu_config_module->mock('__snapshot_save_vmstate', \&__snapshot_save_vmstate);
babf613a 397$qemu_config_module->mock('assert_config_exists_on_node', \&assert_config_exists_on_node);
ffda963f 398
d79a3e54 399# ignore existing replication config
f7d1505b 400my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
9bfca2ca 401$repl_config_module->mock('new' => sub { return bless {}, "PVE::ReplicationConfig" });
d1c1af4b 402$repl_config_module->mock('check_for_existing_jobs' => sub { return });
d79a3e54 403
f7d1505b 404my $storage_module = Test::MockModule->new('PVE::Storage');
d1c1af4b 405$storage_module->mock('config', sub { return; });
b4dab550
FG
406$storage_module->mock('path', sub { return "/some/store/statefile/path"; });
407$storage_module->mock('activate_volumes', \&mocked_activate_volumes);
408$storage_module->mock('deactivate_volumes', \&mocked_deactivate_volumes);
409$storage_module->mock('vdisk_free', \&mocked_vdisk_free);
410$storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
411$storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
412$storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
413$storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
414
a157d0fd
FG
415$running = 1;
416$freeze_possible = 1;
417$save_vmstate_works = 1;
418
419printf("\n");
420printf("Running prepare tests\n");
421printf("\n");
422$nodename = "prepare";
423
424printf("\n");
425printf("Setting has_feature to return true\n");
426printf("\n");
427$snapshot_possible = 1;
428
429printf("Successful snapshot_prepare with no existing snapshots\n");
430testcase_prepare("101", "test", 0, "test comment", '');
431
432printf("Successful snapshot_prepare with no existing snapshots, including vmstate\n");
433testcase_prepare("102", "test", 1, "test comment", '');
434
435printf("Successful snapshot_prepare with one existing snapshot\n");
436testcase_prepare("103", "test2", 0, "test comment", "");
437
438printf("Successful snapshot_prepare with one existing snapshot, including vmstate\n");
439testcase_prepare("104", "test2", 1, "test comment", "");
440
441printf("Expected error for snapshot_prepare on locked container\n");
442testcase_prepare("200", "test", 0, "test comment", "VM is locked (snapshot)\n");
443
444printf("Expected error for snapshot_prepare with duplicate snapshot name\n");
445testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
446
447$save_vmstate_works = 0;
448
449printf("Expected error for snapshot_prepare with failing save_vmstate\n");
450testcase_prepare("202", "test", 1, "test comment", "save_vmstate failed\n");
451
452$save_vmstate_works = 1;
453
454printf("\n");
455printf("Setting has_feature to return false\n");
456printf("\n");
457$snapshot_possible = 0;
458
459printf("Expected error for snapshot_prepare if snapshots not possible\n");
460testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
461
462printf("\n");
463printf("Running commit tests\n");
464printf("\n");
465$nodename = "commit";
466
467printf("\n");
468printf("Setting has_feature to return true\n");
469printf("\n");
470$snapshot_possible = 1;
471
472printf("Successful snapshot_commit with one prepared snapshot\n");
473testcase_commit("101", "test", "");
474
475printf("Successful snapshot_commit with one committed and one prepared snapshot\n");
476testcase_commit("102", "test2", "");
477
478printf("Expected error for snapshot_commit with no snapshot lock\n");
479testcase_commit("201", "test", "missing snapshot lock\n");
480
481printf("Expected error for snapshot_commit with invalid snapshot name\n");
482testcase_commit("202", "test", "snapshot 'test' does not exist\n");
483
484printf("Expected error for snapshot_commit with invalid snapshot state\n");
485testcase_commit("203", "test", "wrong snapshot state\n");
486
487$vol_snapshot_possible->{"local:snapshotable-disk-1"} = 1;
488$vol_snapshot_possible->{"local:snapshotable-disk-2"} = 1;
489$vol_snapshot_possible->{"local:snapshotable-disk-3"} = 1;
490$vol_snapshot_delete_possible->{"local:snapshotable-disk-1"} = 1;
491$vol_snapshot_delete_possible->{"local:snapshotable-disk-3"} = 1;
492$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-1"} = 1;
493$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-2"} = 1;
494$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-3"} = 1;
495$vol_snapshot_rollback_possible->{"local:snapshotable-disk-1"} = 1;
496$vol_snapshot_rollback_possible->{"local:snapshotable-disk-2"} = 1;
497$vol_snapshot_rollback_possible->{"local:snapshotable-disk-3"} = 1;
498$vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
499$vm_mon->{guest_ping} = 1;
500$vm_mon->{savevm_start} = 1;
501$vm_mon->{savevm_end} = 1;
502
503# possible, but fails
504$vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
505
a157d0fd
FG
506
507#printf("\n");
508#printf("Setting up Mocking for PVE::Tools\n");
f7d1505b 509#my $tools_module = Test::MockModule->new('PVE::Tools');
a157d0fd
FG
510#$tools_module->mock('run_command' => \&mocked_run_command);
511#printf("\trun_command() mocked\n");
512#
513$nodename = "create";
514printf("\n");
515printf("Running create tests\n");
516printf("\n");
517
518printf("Successful snapshot_create with no existing snapshots\n");
519testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
520
521printf("Successful snapshot_create with no existing snapshots, including vmstate\n");
522testcase_create("102", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
523
524printf("Successful snapshot_create with one existing snapshots\n");
525testcase_create("103", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
526
527printf("Successful snapshot_create with one existing snapshots, including vmstate\n");
528testcase_create("104", "test2", 1, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
529
530printf("Successful snapshot_create with multiple mps\n");
531testcase_create("105", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
532
533$freeze_possible = 0;
534printf("Successful snapshot_create with no existing snapshots and broken freeze\n");
535testcase_create("106", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
536$freeze_possible = 1;
537
538printf("Expected error for snapshot_create when volume snapshot is not possible\n");
b2c9558d 539testcase_create("201", "test", 0, "test comment", "volume snapshot disabled\n\n");
a157d0fd
FG
540
541printf("Expected error for snapshot_create when volume snapshot is not possible for one drive\n");
b2c9558d 542testcase_create("202", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" });
a157d0fd
FG
543
544$vm_mon->{savevm_start} = 0;
545printf("Expected error for snapshot_create when Qemu mon command 'savevm-start' fails\n");
b2c9558d 546testcase_create("203", "test", 0, "test comment", "savevm-start disabled\n\n");
a157d0fd
FG
547$vm_mon->{savevm_start} = 1;
548
28831e10
DC
549printf("Successful snapshot_create with no existing snapshots but set machine type\n");
550testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
a157d0fd
FG
551
552$nodename = "delete";
553printf("\n");
554printf("Running delete tests\n");
555printf("\n");
556
557printf("Successful snapshot_delete of only existing snapshot\n");
558testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
559
560printf("Successful snapshot_delete of leaf snapshot\n");
561testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
562
563printf("Successful snapshot_delete of root snapshot\n");
564testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
565
566printf("Successful snapshot_delete of intermediate snapshot\n");
567testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
568
569printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1\n");
570testcase_delete("105", "test", 1, "");
571
572printf("Successful snapshot_delete with mp broken volume_snapshot_delete and force=1\n");
573testcase_delete("106", "test", 1, "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-3" => "test" });
574
575printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0\n");
576testcase_delete("201", "test", 0, "volume snapshot delete disabled\n");
577
578printf("Expected error when snapshot_delete fails with broken mp volume_snapshot_delete and force=0\n");
579testcase_delete("202", "test", 0, "volume snapshot delete disabled\n", { "local:snapshotable-disk-1" => "test" });
580
581printf("Expected error for snapshot_delete with locked config\n");
582testcase_delete("203", "test", 0, "VM is locked (backup)\n");
583
584$nodename = "rollback";
585printf("\n");
586printf("Running rollback tests\n");
587printf("\n");
588
589$stop_possible = 1;
590
591printf("Successful snapshot_rollback to only existing snapshot\n");
592testcase_rollback("101", "test", "", { "local:snapshotable-disk-1" => "test" });
593
594printf("Successful snapshot_rollback to leaf snapshot\n");
595testcase_rollback("102", "test2", "", { "local:snapshotable-disk-1" => "test2" });
596
597printf("Successful snapshot_rollback to root snapshot\n");
598testcase_rollback("103", "test", "", { "local:snapshotable-disk-1" => "test" });
599
600printf("Successful snapshot_rollback to intermediate snapshot\n");
601testcase_rollback("104", "test2", "", { "local:snapshotable-disk-1" => "test2" });
602
603printf("Successful snapshot_rollback with multiple mp\n");
604testcase_rollback("105", "test", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
605
606printf("Successful snapshot_rollback to only existing snapshot, with saved vmstate and machine config\n");
607testcase_rollback("106", "test", "", { "local:snapshotable-disk-1" => "test" });
608
609printf("Expected error for snapshot_rollback with non-existing snapshot\n");
610testcase_rollback("201", "test2", "snapshot 'test2' does not exist\n");
611
612printf("Expected error for snapshot_rollback if volume rollback not possible\n");
613testcase_rollback("202", "test", "volume_rollback_is_possible failed\n");
614
615printf("Expected error for snapshot_rollback with incomplete snapshot\n");
616testcase_rollback("203", "test", "unable to rollback to incomplete snapshot (snapstate = delete)\n");
617
618printf("Expected error for snapshot_rollback with lock\n");
619testcase_rollback("204", "test", "VM is locked (backup)\n");
620
621$stop_possible = 0;
622
623printf("Expected error for snapshot_rollback with unkillable container\n");
624testcase_rollback("205", "test", "unable to rollback vm 205: vm is running\n");
625
626$stop_possible = 1;
627
628printf("Expected error for snapshot_rollback with mp rollback_is_possible failure\n");
629testcase_rollback("206", "test", "volume_rollback_is_possible failed\n");
630
631printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
632testcase_rollback("207", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
633
28831e10
DC
634printf("Successful snapshot_rollback with saved vmstate and machine config only in snapshot\n");
635testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" });
636
637printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n");
638testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
639
a157d0fd 640done_testing();