]> git.proxmox.com Git - pve-container.git/blame - src/test/snapshot-test.pm
backup: log errors from rsync
[pve-container.git] / src / test / snapshot-test.pm
CommitLineData
4518000b 1package PVE::LXC::Test;
0fdbd016
FG
2
3use strict;
4use warnings;
b0c4f065 5use Carp;
0fdbd016 6
0fff7963
DM
7use lib qw(..);
8
0fdbd016
FG
9use PVE::Storage;
10use PVE::Storage::Plugin;
11use PVE::LXC;
67afe46e 12use PVE::LXC::Config;
0fdbd016 13use PVE::Tools;
87dfc305 14use PVE::ReplicationConfig;
0fdbd016
FG
15
16use Test::MockModule;
17use Test::More;
18
7402b360 19my $activate_storage_possible = 1;
0fdbd016
FG
20my $nodename;
21my $snapshot_possible;
22my $vol_snapshot_possible = {};
23my $vol_snapshot_delete_possible = {};
5ab55c6d
FG
24my $vol_snapshot_rollback_possible = {};
25my $vol_snapshot_rollback_enabled = {};
0fdbd016
FG
26my $vol_snapshot = {};
27my $vol_snapshot_delete = {};
5ab55c6d 28my $vol_snapshot_rollback = {};
0fdbd016
FG
29my $running;
30my $freeze_possible;
5ab55c6d 31my $kill_possible;
0fdbd016
FG
32
33# Mocked methods
34
4518000b
FG
35sub mocked_has_feature {
36 my ($feature, $conf, $storecfg, $snapname) = @_;
37 return $snapshot_possible;
38}
39
40sub mocked_check_running {
41 return $running;
42}
43
0fdbd016
FG
44sub mocked_volume_snapshot {
45 my ($storecfg, $volid, $snapname) = @_;
19d36a45 46 die "Storage config not mocked! aborting\n"
0fdbd016 47 if defined($storecfg);
19d36a45 48 die "volid undefined\n"
0fdbd016 49 if !defined($volid);
19d36a45 50 die "snapname undefined\n"
0fdbd016
FG
51 if !defined($snapname);
52 if ($vol_snapshot_possible->{$volid}) {
53 if (defined($vol_snapshot->{$volid})) {
54 $vol_snapshot->{$volid} .= ",$snapname";
55 } else {
56 $vol_snapshot->{$volid} = $snapname;
57 }
58 return 1;
59 } else {
19d36a45 60 die "volume snapshot disabled\n";
0fdbd016
FG
61 }
62}
63
64sub mocked_volume_snapshot_delete {
65 my ($storecfg, $volid, $snapname) = @_;
19d36a45 66 die "Storage config not mocked! aborting\n"
0fdbd016 67 if defined($storecfg);
19d36a45 68 die "volid undefined\n"
0fdbd016 69 if !defined($volid);
19d36a45 70 die "snapname undefined\n"
0fdbd016
FG
71 if !defined($snapname);
72 if ($vol_snapshot_delete_possible->{$volid}) {
73 if (defined($vol_snapshot_delete->{$volid})) {
74 $vol_snapshot_delete->{$volid} .= ",$snapname";
75 } else {
76 $vol_snapshot_delete->{$volid} = $snapname;
77 }
78 return 1;
79 } else {
19d36a45 80 die "volume snapshot delete disabled\n";
0fdbd016
FG
81 }
82}
83
5ab55c6d
FG
84sub mocked_volume_snapshot_rollback {
85 my ($storecfg, $volid, $snapname) = @_;
86 die "Storage config not mocked! aborting\n"
87 if defined($storecfg);
88 die "volid undefined\n"
89 if !defined($volid);
90 die "snapname undefined\n"
91 if !defined($snapname);
92 if ($vol_snapshot_rollback_enabled->{$volid}) {
93 if (defined($vol_snapshot_rollback->{$volid})) {
94 $vol_snapshot_rollback->{$volid} .= ",$snapname";
95 } else {
96 $vol_snapshot_rollback->{$volid} = $snapname;
97 }
98 return 1;
99 } else {
100 die "volume snapshot rollback disabled\n";
101 }
102}
103
104sub mocked_volume_rollback_is_possible {
105 my ($storecfg, $volid, $snapname) = @_;
106 die "Storage config not mocked! aborting\n"
107 if defined($storecfg);
108 die "volid undefined\n"
109 if !defined($volid);
110 die "snapname undefined\n"
111 if !defined($snapname);
112 return $vol_snapshot_rollback_possible->{$volid}
113 if ($vol_snapshot_rollback_possible->{$volid});
114 die "volume_rollback_is_possible failed\n";
115}
116
8463099d
SI
117sub mocked_volume_snapshot_needs_fsfreeze {
118 my ($storecfg, $volid) = @_;
119 die "Storage config not mocked! aborting\n"
120 if defined($storecfg);
121 die "volid undefined\n"
122 if !defined($volid);
123 return 0;
124}
125
7402b360
FE
126sub mocked_activate_storage {
127 my ($storecfg, $storeid) = @_;
128 die "Storage config not mocked! aborting\n"
129 if defined($storecfg);
130 die "storage activation failed\n"
131 if !$activate_storage_possible;
132 return;
133}
134
b1bad293
WB
135sub mocked_vm_stop {
136 if ($kill_possible) {
137 $running = 0;
138 return 1;
139 } else {
140 return 0;
141 }
142}
143
89424a8b
TL
144sub mocked_freeze{
145 my ($vmid) = @_;
4fb6ecca 146 return () if $freeze_possible;
89424a8b 147 die "freeze disabled\n";
4fb6ecca
WB
148}
149
0fdbd016
FG
150sub mocked_run_command {
151 my ($cmd, %param) = @_;
152 my $cmdstring;
153 if (my $ref = ref($cmd)) {
154 $cmdstring = PVE::Tools::cmd2string($cmd);
5ab55c6d 155 if ($cmdstring =~ m/.*\/lxc-stop.*--kill.*/) {
b1bad293 156 mocked_vm_stop();
5ab55c6d 157 }
0fdbd016 158 }
e2f2d0dc 159 die "unexpected run_command call: '$cmdstring', aborting\n";
0fdbd016
FG
160}
161
162# Testing methods
163
164sub test_file {
165 my ($exp_fn, $real_fn) = @_;
166 my $ret;
167 eval {
168 $ret = system("diff -u '$exp_fn' '$real_fn'");
169 };
170 die if $@;
171 return !$ret;
172}
173
174sub testcase_prepare {
175 my ($vmid, $snapname, $save_vmstate, $comment, $exp_err) = @_;
176 subtest "Preparing snapshot '$snapname' for vm '$vmid'" => sub {
177 plan tests => 2;
178 $@ = undef;
179 eval {
4518000b 180 PVE::LXC::Config->__snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
0fdbd016
FG
181 };
182 is($@, $exp_err, "\$@ correct");
183 ok(test_file("snapshot-expected/prepare/lxc/$vmid.conf", "snapshot-working/prepare/lxc/$vmid.conf"), "config file correct");
184 };
185}
186
187sub testcase_commit {
188 my ($vmid, $snapname, $exp_err) = @_;
189 subtest "Committing snapshot '$snapname' for vm '$vmid'" => sub {
190 plan tests => 2;
191 $@ = undef;
192 eval {
4518000b 193 PVE::LXC::Config->__snapshot_commit($vmid, $snapname);
0fdbd016
FG
194 };
195 is($@, $exp_err, "\$@ correct");
196 ok(test_file("snapshot-expected/commit/lxc/$vmid.conf", "snapshot-working/commit/lxc/$vmid.conf"), "config file correct");
197 }
198}
199
200sub testcase_create {
201 my ($vmid, $snapname, $save_vmstate, $comment, $exp_err, $exp_vol_snap, $exp_vol_snap_delete) = @_;
202 subtest "Creating snapshot '$snapname' for vm '$vmid'" => sub {
203 plan tests => 4;
204 $vol_snapshot = {};
205 $vol_snapshot_delete = {};
206 $exp_vol_snap = {} if !defined($exp_vol_snap);
207 $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
208 $@ = undef;
209 eval {
4518000b 210 PVE::LXC::Config->snapshot_create($vmid, $snapname, $save_vmstate, $comment);
0fdbd016
FG
211 };
212 is($@, $exp_err, "\$@ correct");
213 is_deeply($vol_snapshot, $exp_vol_snap, "created correct volume snapshots");
214 is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
215 ok(test_file("snapshot-expected/create/lxc/$vmid.conf", "snapshot-working/create/lxc/$vmid.conf"), "config file correct");
216 };
217}
218
219sub testcase_delete {
220 my ($vmid, $snapname, $force, $exp_err, $exp_vol_snap_delete) = @_;
221 subtest "Deleting snapshot '$snapname' of vm '$vmid'" => sub {
222 plan tests => 3;
223 $vol_snapshot_delete = {};
224 $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
225 $@ = undef;
226 eval {
4518000b 227 PVE::LXC::Config->snapshot_delete($vmid, $snapname, $force);
0fdbd016
FG
228 };
229 is($@, $exp_err, "\$@ correct");
230 is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
231 ok(test_file("snapshot-expected/delete/lxc/$vmid.conf", "snapshot-working/delete/lxc/$vmid.conf"), "config file correct");
232 };
233}
234
5ab55c6d
FG
235sub testcase_rollback {
236 my ($vmid, $snapname, $exp_err, $exp_vol_snap_rollback) = @_;
237 subtest "Rolling back to snapshot '$snapname' of vm '$vmid'" => sub {
238 plan tests => 3;
239 $vol_snapshot_rollback = {};
240 $running = 1;
241 $exp_vol_snap_rollback = {} if !defined($exp_vol_snap_rollback);
242 $@ = undef;
243 eval {
4518000b 244 PVE::LXC::Config->snapshot_rollback($vmid, $snapname);
5ab55c6d
FG
245 };
246 is($@, $exp_err, "\$@ correct");
247 is_deeply($vol_snapshot_rollback, $exp_vol_snap_rollback, "rolled back to correct volume snapshots");
248 ok(test_file("snapshot-expected/rollback/lxc/$vmid.conf", "snapshot-working/rollback/lxc/$vmid.conf"), "config file correct");
249 };
250}
251
67afe46e
FG
252# BEGIN mocked PVE::LXC::Config methods
253sub mocked_config_file_lock {
0fdbd016
FG
254 return "snapshot-working/pve-test.lock";
255}
256
67afe46e
FG
257sub mocked_cfs_config_path {
258 my ($class, $vmid, $node) = @_;
0fdbd016
FG
259
260 $node = $nodename if !$node;
261 return "snapshot-working/$node/lxc/$vmid.conf";
262}
263
67afe46e
FG
264sub mocked_load_config {
265 my ($class, $vmid, $node) = @_;
0fdbd016 266
67afe46e 267 my $filename = PVE::LXC::Config->cfs_config_path($vmid, $node);
0fdbd016
FG
268
269 my $raw = PVE::Tools::file_get_contents($filename);
270
1b4cf758 271 my $conf = PVE::LXC::Config::parse_pct_config($filename, $raw);
0fdbd016
FG
272 return $conf;
273}
274
67afe46e
FG
275sub mocked_write_config {
276 my ($class, $vmid, $conf) = @_;
0fdbd016 277
67afe46e 278 my $filename = PVE::LXC::Config->cfs_config_path($vmid);
0fdbd016
FG
279
280 if ($conf->{snapshots}) {
281 foreach my $snapname (keys %{$conf->{snapshots}}) {
282 $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
283 if $conf->{snapshots}->{$snapname}->{snaptime};
284 }
285 }
286
1b4cf758 287 my $raw = PVE::LXC::Config::write_pct_config($filename, $conf);
0fdbd016
FG
288
289 PVE::Tools::file_set_contents($filename, $raw);
290}
291
67afe46e 292# END mocked PVE::LXC methods
0fdbd016 293
0fdbd016
FG
294
295PVE::Tools::run_command("rm -rf snapshot-working");
296PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
297
4518000b
FG
298printf("\n");
299printf("Setting up Mocking for PVE::LXC and PVE::LXC::Config\n");
5a08f779 300my $lxc_module = Test::MockModule->new('PVE::LXC');
4518000b
FG
301$lxc_module->mock('sync_container_namespace', sub { return; });
302$lxc_module->mock('check_running', \&mocked_check_running);
b1bad293 303$lxc_module->mock('vm_stop', \&mocked_vm_stop);
89424a8b
TL
304$lxc_module->mock('freeze', \&mocked_freeze);
305$lxc_module->mock('thaw', \&mocked_freeze); # re-use, as for now we don't care
4518000b 306
5a08f779 307my $lxc_config_module = Test::MockModule->new('PVE::LXC::Config');
67afe46e
FG
308$lxc_config_module->mock('config_file_lock', sub { return "snapshot-working/pve-test.lock"; });
309$lxc_config_module->mock('cfs_config_path', \&mocked_cfs_config_path);
310$lxc_config_module->mock('load_config', \&mocked_load_config);
311$lxc_config_module->mock('write_config', \&mocked_write_config);
4518000b 312$lxc_config_module->mock('has_feature', \&mocked_has_feature);
67afe46e 313
5a08f779 314my $pve_cluster_module = Test::MockModule->new('PVE::Cluster');
b0c4f065
WB
315sub mocked_get_config {
316 my ($path) = @_;
317 return PVE::Tools::file_get_contents("snapshot-working/$path");
318}
319$pve_cluster_module->mock('get_config', \&mocked_get_config);
320
87dfc305 321# ignore existing replication config
5a08f779 322my $repl_config_module = Test::MockModule->new('PVE::ReplicationConfig');
87dfc305
DM
323$repl_config_module->mock('check_for_existing_jobs' => sub { return undef });
324
0fdbd016
FG
325$running = 1;
326$freeze_possible = 1;
327
e2f2d0dc
FG
328printf("\n");
329printf("Running prepare tests\n");
330printf("\n");
0fdbd016
FG
331$nodename = "prepare";
332
e2f2d0dc
FG
333printf("\n");
334printf("Setting has_feature to return true\n");
335printf("\n");
0fdbd016
FG
336$snapshot_possible = 1;
337
e2f2d0dc 338printf("Successful snapshot_prepare with no existing snapshots\n");
0fdbd016
FG
339testcase_prepare("101", "test", 0, "test comment", '');
340
e2f2d0dc 341printf("Successful snapshot_prepare with one existing snapshot\n");
0fdbd016
FG
342testcase_prepare("102", "test2", 0, "test comment", "");
343
e2f2d0dc 344printf("Expected error for snapshot_prepare on locked container\n");
67afe46e 345testcase_prepare("200", "test", 0, "test comment", "CT is locked (snapshot)\n");
0fdbd016 346
e2f2d0dc 347printf("Expected error for snapshot_prepare with duplicate snapshot name\n");
0fdbd016
FG
348testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
349
e2f2d0dc 350printf("Expected error for snapshot_prepare with save_vmstate\n");
0fdbd016
FG
351testcase_prepare("202", "test", 1, "test comment", "implement me - snapshot_save_vmstate\n");
352
e2f2d0dc
FG
353printf("\n");
354printf("Setting has_feature to return false\n");
355printf("\n");
0fdbd016
FG
356$snapshot_possible = 0;
357
e2f2d0dc 358printf("Expected error for snapshot_prepare if snapshots not possible\n");
0fdbd016
FG
359testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
360
e2f2d0dc
FG
361printf("\n");
362printf("Running commit tests\n");
363printf("\n");
0fdbd016
FG
364$nodename = "commit";
365
e2f2d0dc
FG
366printf("\n");
367printf("Setting has_feature to return true\n");
368printf("\n");
0fdbd016
FG
369$snapshot_possible = 1;
370
e2f2d0dc 371printf("Successful snapshot_commit with one prepared snapshot\n");
0fdbd016
FG
372testcase_commit("101", "test", "");
373
e2f2d0dc 374printf("Successful snapshot_commit with one committed and one prepared snapshot\n");
0fdbd016
FG
375testcase_commit("102", "test2", "");
376
e2f2d0dc 377printf("Expected error for snapshot_commit with no snapshot lock\n");
0fdbd016
FG
378testcase_commit("201", "test", "missing snapshot lock\n");
379
e2f2d0dc 380printf("Expected error for snapshot_commit with invalid snapshot name\n");
0fdbd016
FG
381testcase_commit("202", "test", "snapshot 'test' does not exist\n");
382
e2f2d0dc 383printf("Expected error for snapshot_commit with invalid snapshot state\n");
0fdbd016
FG
384testcase_commit("203", "test", "wrong snapshot state\n");
385
386$vol_snapshot_possible->{"local:snapshotable-disk-1"} = 1;
3c8677f8
FG
387$vol_snapshot_possible->{"local:snapshotable-disk-2"} = 1;
388$vol_snapshot_possible->{"local:snapshotable-disk-3"} = 1;
0fdbd016 389$vol_snapshot_delete_possible->{"local:snapshotable-disk-1"} = 1;
5ab55c6d 390$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-1"} = 1;
3c8677f8
FG
391$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-2"} = 1;
392$vol_snapshot_rollback_enabled->{"local:snapshotable-disk-3"} = 1;
5ab55c6d 393$vol_snapshot_rollback_possible->{"local:snapshotable-disk-1"} = 1;
3c8677f8
FG
394$vol_snapshot_rollback_possible->{"local:snapshotable-disk-2"} = 1;
395$vol_snapshot_rollback_possible->{"local:snapshotable-disk-3"} = 1;
396
397# possible, but fails
398$vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1;
5ab55c6d 399
e2f2d0dc
FG
400printf("\n");
401printf("Setting up Mocking for PVE::Storage\n");
5a08f779 402my $storage_module = Test::MockModule->new('PVE::Storage');
7402b360 403$storage_module->mock('activate_storage', \&mocked_activate_storage);
0fdbd016
FG
404$storage_module->mock('config', sub { return undef; });
405$storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
406$storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
5ab55c6d
FG
407$storage_module->mock('volume_snapshot_rollback', \&mocked_volume_snapshot_rollback);
408$storage_module->mock('volume_rollback_is_possible', \&mocked_volume_rollback_is_possible);
8463099d
SI
409$storage_module->mock('volume_snapshot_needs_fsfreeze', \&mocked_volume_snapshot_needs_fsfreeze);
410printf("\tconfig(), volume_snapshot(), volume_snapshot_delete(), volume_snapshot_rollback(), volume_rollback_is_possible() and volume_snapshot_needs_fsfreeze() mocked\n");
0fdbd016 411
e2f2d0dc
FG
412printf("\n");
413printf("Setting up Mocking for PVE::Tools\n");
5a08f779 414my $tools_module = Test::MockModule->new('PVE::Tools');
0fdbd016 415$tools_module->mock('run_command' => \&mocked_run_command);
e2f2d0dc 416printf("\trun_command() mocked\n");
0fdbd016
FG
417
418$nodename = "create";
e2f2d0dc
FG
419printf("\n");
420printf("Running create tests\n");
421printf("\n");
0fdbd016 422
e2f2d0dc 423printf("Successful snapshot_create with no existing snapshots\n");
0fdbd016
FG
424testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
425
e2f2d0dc 426printf("Successful snapshot_create with one existing snapshots\n");
0fdbd016
FG
427testcase_create("102", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
428
3c8677f8
FG
429printf("Successful snapshot_create with multiple mps\n");
430testcase_create("103", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
431
e2f2d0dc 432printf("Expected error for snapshot_create when volume snapshot is not possible\n");
19d36a45 433testcase_create("201", "test", 0, "test comment", "volume snapshot disabled\n\n");
0fdbd016 434
e2f2d0dc 435printf("Expected error for snapshot_create with broken lxc-freeze\n");
0fdbd016 436$freeze_possible = 0;
89424a8b 437testcase_create("202", "test", 0, "test comment", "freeze disabled\n\n");
0fdbd016
FG
438$freeze_possible = 1;
439
3c8677f8
FG
440printf("Expected error for snapshot_create when mp volume snapshot is not possible\n");
441testcase_create("203", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" });
442
7402b360
FE
443$activate_storage_possible = 0;
444
445printf("Expected error for snapshot_create when storage activation is not possible\n");
446testcase_create("204", "test", 0, "test comment", "storage activation failed\n\n");
447
448$activate_storage_possible = 1;
449
0fdbd016 450$nodename = "delete";
e2f2d0dc
FG
451printf("\n");
452printf("Running delete tests\n");
453printf("\n");
0fdbd016 454
e2f2d0dc 455printf("Successful snapshot_delete of only existing snapshot\n");
0fdbd016
FG
456testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
457
e2f2d0dc 458printf("Successful snapshot_delete of leaf snapshot\n");
0fdbd016
FG
459testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
460
e2f2d0dc 461printf("Successful snapshot_delete of root snapshot\n");
0fdbd016
FG
462testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
463
e2f2d0dc 464printf("Successful snapshot_delete of intermediate snapshot\n");
0fdbd016
FG
465testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
466
e2f2d0dc 467printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1\n");
0fdbd016
FG
468testcase_delete("105", "test", 1, "");
469
3c8677f8
FG
470printf("Successful snapshot_delete with mp broken volume_snapshot_delete and force=1\n");
471testcase_delete("106", "test", 1, "", { "local:snapshotable-disk-1" => "test" });
472
e2f2d0dc 473printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0\n");
19d36a45 474testcase_delete("201", "test", 0, "volume snapshot delete disabled\n");
0fdbd016 475
3c8677f8
FG
476printf("Expected error when snapshot_delete fails with broken mp volume_snapshot_delete and force=0\n");
477testcase_delete("203", "test", 0, "volume snapshot delete disabled\n", { "local:snapshotable-disk-1" => "test" });
478
e2f2d0dc 479printf("Expected error for snapshot_delete with locked config\n");
67afe46e 480testcase_delete("202", "test", 0, "CT is locked (backup)\n");
0fdbd016 481
7402b360
FE
482$activate_storage_possible = 0;
483
484printf("Expected error for snapshot_delete when storage activation is not possible\n");
485testcase_delete("204", "test", 0, "storage activation failed\n");
486
487$activate_storage_possible = 1;
488
5ab55c6d
FG
489$nodename = "rollback";
490printf("\n");
491printf("Running rollback tests\n");
492printf("\n");
493
494$kill_possible = 1;
495
496printf("Successful snapshot_rollback to only existing snapshot\n");
497testcase_rollback("101", "test", "", { "local:snapshotable-disk-1" => "test" });
498
499printf("Successful snapshot_rollback to leaf snapshot\n");
500testcase_rollback("102", "test2", "", { "local:snapshotable-disk-1" => "test2" });
501
502printf("Successful snapshot_rollback to root snapshot\n");
503testcase_rollback("103", "test", "", { "local:snapshotable-disk-1" => "test" });
504
505printf("Successful snapshot_rollback to intermediate snapshot\n");
506testcase_rollback("104", "test2", "", { "local:snapshotable-disk-1" => "test2" });
507
3c8677f8
FG
508printf("Successful snapshot_rollback with multiple mp\n");
509testcase_rollback("105", "test", "", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test", "local:snapshotable-disk-3" => "test" });
510
5ab55c6d
FG
511printf("Expected error for snapshot_rollback with non-existing snapshot\n");
512testcase_rollback("201", "test2", "snapshot 'test2' does not exist\n");
513
514printf("Expected error for snapshot_rollback if volume rollback not possible\n");
515testcase_rollback("202", "test", "volume_rollback_is_possible failed\n");
516
517printf("Expected error for snapshot_rollback with incomplete snapshot\n");
518testcase_rollback("203", "test", "unable to rollback to incomplete snapshot (snapstate = delete)\n");
519
520printf("Expected error for snapshot_rollback with lock\n");
67afe46e 521testcase_rollback("204", "test", "CT is locked (backup)\n");
5ab55c6d
FG
522
523printf("Expected error for snapshot_rollback with saved vmstate\n");
524testcase_rollback("205", "test", "implement me - save vmstate\n", { "local:snapshotable-disk-1" => "test" });
525
526$kill_possible = 0;
527
528printf("Expected error for snapshot_rollback with unkillable container\n");
529testcase_rollback("206", "test", "unable to rollback vm 206: vm is running\n");
0fdbd016 530
3c8677f8
FG
531$kill_possible = 1;
532
533printf("Expected error for snapshot_rollback with mp rollback_is_possible failure\n");
534testcase_rollback("207", "test", "volume_rollback_is_possible failed\n");
535
536printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n");
537testcase_rollback("208", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" });
538
7402b360
FE
539$activate_storage_possible = 0;
540
541printf("Expected error for snapshot_rollback when storage activation is not possible\n");
542testcase_rollback("209", "test", "storage activation failed\n");
543
544$activate_storage_possible = 1;
545
0fdbd016 546done_testing();