]> git.proxmox.com Git - qemu-server.git/blame - test/snapshot-test.pm
bump version to 7.2-12
[qemu-server.git] / test / snapshot-test.pm
CommitLineData
2bf945fc 1package PVE::QemuServer; ## no critic
a157d0fd
FG
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
fe2c5069 18my $activate_storage_possible = 1;
a157d0fd
FG
19my $nodename;
20my $snapshot_possible;
21my $vol_snapshot_possible = {};
22my $vol_snapshot_delete_possible = {};
23my $vol_snapshot_rollback_possible = {};
24my $vol_snapshot_rollback_enabled = {};
25my $vol_snapshot = {};
26my $vol_snapshot_delete = {};
27my $vol_snapshot_rollback = {};
28my $running;
29my $freeze_possible;
30my $stop_possible;
31my $save_vmstate_works;
32my $vm_mon = {};
33
34# Mocked methods
35
36sub 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
56sub 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
76sub 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
96sub 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
fe2c5069
FE
109sub 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
101a1b3f
FG
118sub 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
127sub 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
a157d0fd
FG
136sub 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
145sub 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
168sub 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
178sub 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 {
b2c9558d 184 PVE::QemuConfig->__snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
a157d0fd
FG
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
191sub 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 {
b2c9558d 197 PVE::QemuConfig->__snapshot_commit($vmid, $snapname);
a157d0fd
FG
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
204sub 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 {
b2c9558d 214 PVE::QemuConfig->snapshot_create($vmid, $snapname, $save_vmstate, $comment);
a157d0fd
FG
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
223sub 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 {
b2c9558d 231 PVE::QemuConfig->snapshot_delete($vmid, $snapname, $force);
a157d0fd
FG
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
239sub 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 {
b2c9558d 248 PVE::QemuConfig->snapshot_rollback($vmid, $snapname);
a157d0fd
FG
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
ffda963f 256# BEGIN mocked PVE::QemuConfig methods
a157d0fd
FG
257sub config_file_lock {
258 return "snapshot-working/pve-test.lock";
259}
260
261sub cfs_config_path {
ffda963f 262 my ($class, $vmid, $node) = @_;
a157d0fd
FG
263
264 $node = $nodename if !$node;
265 return "snapshot-working/$node/qemu-server/$vmid.conf";
266}
267
268sub load_config {
ffda963f 269 my ($class, $vmid, $node) = @_;
a157d0fd 270
ffda963f 271 my $filename = $class->cfs_config_path($vmid, $node);
a157d0fd
FG
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
279sub write_config {
ffda963f 280 my ($class, $vmid, $conf) = @_;
a157d0fd 281
ffda963f 282 my $filename = $class->cfs_config_path($vmid);
a157d0fd
FG
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
296sub has_feature {
b2c9558d 297 my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
a157d0fd
FG
298 return $snapshot_possible;
299}
300
b2c9558d
FG
301sub __snapshot_save_vmstate {
302 my ($class, $vmid, $conf, $snapname, $storecfg) = @_;
a157d0fd
FG
303 die "save_vmstate failed\n"
304 if !$save_vmstate_works;
305
306 my $snap = $conf->{snapshots}->{$snapname};
307 $snap->{vmstate} = "somestorage:state-volume";
c6737ef1 308 $snap->{runningmachine} = "somemachine"
a157d0fd 309}
babf613a
SR
310
311sub assert_config_exists_on_node {
312 my ($vmid, $node) = @_;
bf116bdf 313 return -f cfs_config_path("PVE::QemuConfig", $vmid, $node);
babf613a 314}
b2c9558d
FG
315# END mocked PVE::QemuConfig methods
316
babf613a 317# BEGIN mocked PVE::QemuServer::Helpers methods
b2c9558d 318
babf613a 319sub vm_running_locally {
b2c9558d
FG
320 return $running;
321}
322
babf613a
SR
323# END mocked PVE::QemuServer::Helpers methods
324
0a13e08e 325# BEGIN mocked PVE::QemuServer::Monitor methods
a157d0fd 326
0a13e08e 327sub qmp_cmd {
8b26544e 328 my ($vmid, $cmd) = @_;
a157d0fd
FG
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") {
483c9676
SR
355 return {
356 "status" => "completed",
357 "bytes" => 1024*1024*1024,
358 "total-time" => 5000,
359 };
a157d0fd
FG
360 }
361 die "unexpected vm_qmp_command!\n";
362}
363
0a13e08e
SR
364# END mocked PVE::QemuServer::Monitor methods
365
366# BEGIN redefine PVE::QemuServer methods
367
368sub do_snapshots_with_qemu {
369 return 0;
370}
371
a157d0fd 372sub vm_start {
0c498cca 373 my ($storecfg, $vmid, $params, $migrate_opts) = @_;
a157d0fd
FG
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"
0c498cca 379 if defined($params->{statefile}) xor defined($params->{forcemachine});
a157d0fd
FG
380
381 return;
382}
383
384sub 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
27a5be53
SR
393sub set_migration_caps {} # ignored
394
a157d0fd
FG
395# END redefine PVE::QemuServer methods
396
397PVE::Tools::run_command("rm -rf snapshot-working");
398PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
399
f7d1505b 400my $qemu_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
babf613a
SR
401$qemu_helpers_module->mock('vm_running_locally', \&vm_running_locally);
402
f7d1505b 403my $qemu_monitor_module = Test::MockModule->new('PVE::QemuServer::Monitor');
0a13e08e
SR
404$qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
405
f7d1505b 406my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
ffda963f
FG
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);
b2c9558d
FG
411$qemu_config_module->mock('has_feature', \&has_feature);
412$qemu_config_module->mock('__snapshot_save_vmstate', \&__snapshot_save_vmstate);
babf613a 413$qemu_config_module->mock('assert_config_exists_on_node', \&assert_config_exists_on_node);
ffda963f 414
d79a3e54 415# ignore existing replication config
f7d1505b 416my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
9bfca2ca 417$repl_config_module->mock('new' => sub { return bless {}, "PVE::ReplicationConfig" });
d1c1af4b 418$repl_config_module->mock('check_for_existing_jobs' => sub { return });
d79a3e54 419
f7d1505b 420my $storage_module = Test::MockModule->new('PVE::Storage');
d1c1af4b 421$storage_module->mock('config', sub { return; });
b4dab550 422$storage_module->mock('path', sub { return "/some/store/statefile/path"; });
fe2c5069 423$storage_module->mock('activate_storage', \&mocked_activate_storage);
b4dab550
FG
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
a157d0fd
FG
432$running = 1;
433$freeze_possible = 1;
434$save_vmstate_works = 1;
435
436printf("\n");
437printf("Running prepare tests\n");
438printf("\n");
439$nodename = "prepare";
440
441printf("\n");
442printf("Setting has_feature to return true\n");
443printf("\n");
444$snapshot_possible = 1;
445
446printf("Successful snapshot_prepare with no existing snapshots\n");
447testcase_prepare("101", "test", 0, "test comment", '');
448
449printf("Successful snapshot_prepare with no existing snapshots, including vmstate\n");
450testcase_prepare("102", "test", 1, "test comment", '');
451
452printf("Successful snapshot_prepare with one existing snapshot\n");
453testcase_prepare("103", "test2", 0, "test comment", "");
454
455printf("Successful snapshot_prepare with one existing snapshot, including vmstate\n");
456testcase_prepare("104", "test2", 1, "test comment", "");
457
458printf("Expected error for snapshot_prepare on locked container\n");
459testcase_prepare("200", "test", 0, "test comment", "VM is locked (snapshot)\n");
460
461printf("Expected error for snapshot_prepare with duplicate snapshot name\n");
462testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
463
464$save_vmstate_works = 0;
465
466printf("Expected error for snapshot_prepare with failing save_vmstate\n");
467testcase_prepare("202", "test", 1, "test comment", "save_vmstate failed\n");
468
469$save_vmstate_works = 1;
470
471printf("\n");
472printf("Setting has_feature to return false\n");
473printf("\n");
474$snapshot_possible = 0;
475
476printf("Expected error for snapshot_prepare if snapshots not possible\n");
477testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
478
479printf("\n");
480printf("Running commit tests\n");
481printf("\n");
482$nodename = "commit";
483
484printf("\n");
485printf("Setting has_feature to return true\n");
486printf("\n");
487$snapshot_possible = 1;
488
489printf("Successful snapshot_commit with one prepared snapshot\n");
490testcase_commit("101", "test", "");
491
492printf("Successful snapshot_commit with one committed and one prepared snapshot\n");
493testcase_commit("102", "test2", "");
494
495printf("Expected error for snapshot_commit with no snapshot lock\n");
496testcase_commit("201", "test", "missing snapshot lock\n");
497
498printf("Expected error for snapshot_commit with invalid snapshot name\n");
499testcase_commit("202", "test", "snapshot 'test' does not exist\n");
500
501printf("Expected error for snapshot_commit with invalid snapshot state\n");
502testcase_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
a157d0fd
FG
523
524#printf("\n");
525#printf("Setting up Mocking for PVE::Tools\n");
f7d1505b 526#my $tools_module = Test::MockModule->new('PVE::Tools');
a157d0fd
FG
527#$tools_module->mock('run_command' => \&mocked_run_command);
528#printf("\trun_command() mocked\n");
529#
530$nodename = "create";
531printf("\n");
532printf("Running create tests\n");
533printf("\n");
534
535printf("Successful snapshot_create with no existing snapshots\n");
536testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
537
538printf("Successful snapshot_create with no existing snapshots, including vmstate\n");
539testcase_create("102", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
540
541printf("Successful snapshot_create with one existing snapshots\n");
542testcase_create("103", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
543
544printf("Successful snapshot_create with one existing snapshots, including vmstate\n");
545testcase_create("104", "test2", 1, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
546
547printf("Successful snapshot_create with multiple mps\n");
548testcase_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;
551printf("Successful snapshot_create with no existing snapshots and broken freeze\n");
552testcase_create("106", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
553$freeze_possible = 1;
554
555printf("Expected error for snapshot_create when volume snapshot is not possible\n");
b2c9558d 556testcase_create("201", "test", 0, "test comment", "volume snapshot disabled\n\n");
a157d0fd
FG
557
558printf("Expected error for snapshot_create when volume snapshot is not possible for one drive\n");
b2c9558d 559testcase_create("202", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" });
a157d0fd
FG
560
561$vm_mon->{savevm_start} = 0;
562printf("Expected error for snapshot_create when Qemu mon command 'savevm-start' fails\n");
b2c9558d 563testcase_create("203", "test", 0, "test comment", "savevm-start disabled\n\n");
a157d0fd
FG
564$vm_mon->{savevm_start} = 1;
565
28831e10
DC
566printf("Successful snapshot_create with no existing snapshots but set machine type\n");
567testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" });
a157d0fd 568
fe2c5069
FE
569$activate_storage_possible = 0;
570
571printf("Expected error for snapshot_create when storage activation is not possible\n");
572testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n");
573
574$activate_storage_possible = 1;
575
a157d0fd
FG
576$nodename = "delete";
577printf("\n");
578printf("Running delete tests\n");
579printf("\n");
580
581printf("Successful snapshot_delete of only existing snapshot\n");
582testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
583
584printf("Successful snapshot_delete of leaf snapshot\n");
585testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
586
587printf("Successful snapshot_delete of root snapshot\n");
588testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
589
590printf("Successful snapshot_delete of intermediate snapshot\n");
591testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
592
593printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1\n");
594testcase_delete("105", "test", 1, "");
595
596printf("Successful snapshot_delete with mp broken volume_snapshot_delete and force=1\n");
597testcase_delete("106", "test", 1, "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-3" => "test" });
598
599printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0\n");
600testcase_delete("201", "test", 0, "volume snapshot delete disabled\n");
601
602printf("Expected error when snapshot_delete fails with broken mp volume_snapshot_delete and force=0\n");
603testcase_delete("202", "test", 0, "volume snapshot delete disabled\n", { "local:snapshotable-disk-1" => "test" });
604
605printf("Expected error for snapshot_delete with locked config\n");
606testcase_delete("203", "test", 0, "VM is locked (backup)\n");
607
fe2c5069
FE
608$activate_storage_possible = 0;
609
610printf("Expected error for snapshot_delete when storage activation is not possible\n");
611testcase_delete("204", "test", 0, "storage activation failed\n");
612
613$activate_storage_possible = 1;
614
a157d0fd
FG
615$nodename = "rollback";
616printf("\n");
617printf("Running rollback tests\n");
618printf("\n");
619
620$stop_possible = 1;
621
622printf("Successful snapshot_rollback to only existing snapshot\n");
623testcase_rollback("101", "test", "", { "local:snapshotable-disk-1" => "test" });
624
625printf("Successful snapshot_rollback to leaf snapshot\n");
626testcase_rollback("102", "test2", "", { "local:snapshotable-disk-1" => "test2" });
627
628printf("Successful snapshot_rollback to root snapshot\n");
629testcase_rollback("103", "test", "", { "local:snapshotable-disk-1" => "test" });
630
631printf("Successful snapshot_rollback to intermediate snapshot\n");
632testcase_rollback("104", "test2", "", { "local:snapshotable-disk-1" => "test2" });
633
634printf("Successful snapshot_rollback with multiple mp\n");
635testcase_rollback("105", "test", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
636
637printf("Successful snapshot_rollback to only existing snapshot, with saved vmstate and machine config\n");
638testcase_rollback("106", "test", "", { "local:snapshotable-disk-1" => "test" });
639
640printf("Expected error for snapshot_rollback with non-existing snapshot\n");
641testcase_rollback("201", "test2", "snapshot 'test2' does not exist\n");
642
643printf("Expected error for snapshot_rollback if volume rollback not possible\n");
644testcase_rollback("202", "test", "volume_rollback_is_possible failed\n");
645
646printf("Expected error for snapshot_rollback with incomplete snapshot\n");
647testcase_rollback("203", "test", "unable to rollback to incomplete snapshot (snapstate = delete)\n");
648
649printf("Expected error for snapshot_rollback with lock\n");
650testcase_rollback("204", "test", "VM is locked (backup)\n");
651
652$stop_possible = 0;
653
654printf("Expected error for snapshot_rollback with unkillable container\n");
655testcase_rollback("205", "test", "unable to rollback vm 205: vm is running\n");
656
657$stop_possible = 1;
658
659printf("Expected error for snapshot_rollback with mp rollback_is_possible failure\n");
660testcase_rollback("206", "test", "volume_rollback_is_possible failed\n");
661
662printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
663testcase_rollback("207", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
664
28831e10
DC
665printf("Successful snapshot_rollback with saved vmstate and machine config only in snapshot\n");
666testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" });
667
668printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n");
669testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" });
670
fe2c5069
FE
671$activate_storage_possible = 0;
672
673printf("Expected error for snapshot_rollback when storage activation is not possible\n");
674testcase_rollback("303", "test", "storage activation failed\n");
675
676$activate_storage_possible = 1;
677
a157d0fd 678done_testing();
2bf945fc
TL
679
6801;