]> git.proxmox.com Git - pve-storage.git/blob - test/run_test_zfspoolplugin.pl
b70aad8971f63eb2696e6a440644ea9d887dc0d4
[pve-storage.git] / test / run_test_zfspoolplugin.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Data::Dumper qw(Dumper);
6 use PVE::Storage;
7 use PVE::Cluster;
8 use PVE::Tools qw(run_command);
9 use Cwd;
10 $Data::Dumper::Sortkeys = 1;
11
12 my $verbose = undef;
13
14 my $storagename = "zfstank99";
15 my $subvol = 'regressiontest';
16
17 #volsize in GB
18 my $volsize = 1;
19 my $vmdisk = "vm-102-disk-1";
20 my $vmbase = "base-100-disk-1";
21 my $vmlinked = "vm-101-disk-1";
22 my $ctdisk = "subvol-202-disk-1";
23 my $ctbase = "basevol-200-disk-1";
24 my $ctlinked = "subvol-201-disk-1";
25
26 my $basesnap = '@__base__';
27 my $tests = {};
28
29 #create zfs subvol for testing
30 my $pool = undef;
31 my $zpath = undef;
32 my $cfg = undef;
33 my $scfg = undef;
34 my $count = 0;
35 my $testnum = 19;
36 my $end_test = $testnum;
37 my $start_test = 1;
38
39 if (@ARGV == 2) {
40 $end_test = $ARGV[1];
41 $start_test = $ARGV[0];
42 } elsif (@ARGV == 1) {
43 $start_test = $ARGV[0];
44 $end_test = $ARGV[0];
45 }
46
47 my $test19 = sub {
48
49 print "\nrun test19 \"path\"\n";
50
51 my @res;
52 my $fail = 0;
53 eval {
54 @res = PVE::Storage::path($cfg, "$storagename:$vmdisk");
55 if ($res[0] ne "\/dev\/zvol\/regressiontest\/$vmdisk") {
56 $count++;
57 $fail = 1;
58 warn "Test 19 a: path is not correct: expected \'\/dev\/zvol\/regressiontest\/$vmdisk'\ get \'$res[0]\'";
59 }
60 if ($res[1] ne "102") {
61 if (!$fail) {
62 $count++;
63 $fail = 1;
64 }
65 warn "Test 19 a: owner is not correct: expected \'102\' get \'$res[1]\'";
66 }
67 if ($res[2] ne "images") {
68 if (!$fail) {
69 $count++;
70 $fail = 1;
71 }
72 warn "Test 19 a: owner is not correct: expected \'images\' get \'$res[2]\'";
73 }
74 };
75 if ( $@ ) {
76 $count++;
77 warn "Test 19 a: $@";
78 }
79
80 @res = undef;
81 $fail = 0;
82 eval {
83 @res = PVE::Storage::path($cfg, "$storagename:$vmbase");
84 if ($res[0] ne "\/dev\/zvol\/regressiontest\/$vmbase") {
85 $count++;
86 $fail = 1;
87 warn "Test 19 b: path is not correct: expected \'\/dev\/zvol\/regressiontest\/$vmbase'\ get \'$res[0]\'";
88 }
89 if ($res[1] ne "100") {
90 if (!$fail) {
91 $count++;
92 $fail = 1;
93 }
94 warn "Test 19 b: owner is not correct: expected \'100\' get \'$res[1]\'";
95 }
96 if ($res[2] ne "images") {
97 if (!$fail) {
98 $count++;
99 $fail = 1;
100 }
101 warn "Test 19 b: owner is not correct: expected \'images\' get \'$res[2]\'";
102 }
103 };
104 if ( $@ ) {
105 $count++;
106 warn "Test 19 b: $@";
107 }
108
109 @res = undef;
110 $fail = 0;
111 eval {
112 @res = PVE::Storage::path($cfg, "$storagename:$vmbase\/$vmlinked");
113 if ($res[0] ne "\/dev\/zvol\/regressiontest\/$vmlinked") {
114 $count++;
115 $fail = 1;
116 warn "Test 19 c: path is not correct: expected \'\/dev\/zvol\/regressiontest\/$vmlinked'\ get \'$res[0]\'";
117 }
118 if ($res[1] ne "101") {
119 if (!$fail) {
120 $count++;
121 $fail = 1;
122 }
123 warn "Test 19 c: owner is not correct: expected \'101\' get \'$res[1]\'";
124 }
125 if ($res[2] ne "images") {
126 if (!$fail) {
127 $count++;
128 $fail = 1;
129 }
130 warn "Test 19 c: owner is not correct: expected \'images\' get \'$res[2]\'";
131 }
132 };
133 if ( $@ ) {
134 $count++;
135 warn "Test 19 c: $@";
136 }
137
138 @res = undef;
139 $fail = 0;
140 eval {
141 @res = PVE::Storage::path($cfg, "$storagename:$ctdisk");
142 if ($res[0] ne "\/regressiontest\/$ctdisk") {
143 $count++;
144 $fail = 1;
145 warn "Test 19 d: path is not correct: expected \'/regressiontest\/$ctdisk'\ get \'$res[0]\'";
146 }
147 if ($res[1] ne "202") {
148 if (!$fail) {
149 $count++;
150 $fail = 1;
151 }
152 warn "Test 19 d: owner is not correct: expected \'202\' get \'$res[1]\'";
153 }
154 if ($res[2] ne "images") {
155 if (!$fail) {
156 $count++;
157 $fail = 1;
158 }
159 warn "Test 19 d: owner is not correct: expected \'images\' get \'$res[2]\'";
160 }
161 };
162 if ( $@ ) {
163 $count++;
164 warn "Test 19 d: $@";
165 }
166
167 @res = undef;
168 $fail = 0;
169 eval {
170 @res = PVE::Storage::path($cfg, "$storagename:$ctbase");
171 if ($res[0] ne "\/regressiontest\/$ctbase") {
172 $count++;
173 $fail = 1;
174 warn "Test 19 e: path is not correct: expected \'\/regressiontest\/$ctbase'\ get \'$res[0]\'";
175 }
176 if ($res[1] ne "200") {
177 if (!$fail) {
178 $count++;
179 $fail = 1;
180 }
181 warn "Test 19 e: owner is not correct: expected \'200\' get \'$res[1]\'";
182 }
183 if ($res[2] ne "images") {
184 if (!$fail) {
185 $count++;
186 $fail = 1;
187 }
188 warn "Test 19 e: owner is not correct: expected \'images\' get \'$res[2]\'";
189 }
190 };
191 if ( $@ ) {
192 $count++;
193 warn "Test 19 e: $@";
194 }
195
196 @res = undef;
197 $fail = 0;
198 eval {
199 @res = PVE::Storage::path($cfg, "$storagename:$ctbase\/$ctlinked");
200 if ($res[0] ne "\/regressiontest\/$ctlinked") {
201 $count++;
202 $fail = 1;
203 warn "Test 19 f: path is not correct: expected \'\/regressiontest\/$ctlinked'\ get \'$res[0]\'";
204 }
205 if ($res[1] ne "201") {
206 if (!$fail) {
207 $count++;
208 $fail = 1;
209 }
210 warn "Test 19 f: owner is not correct: expected \'201\' get \'$res[1]\'";
211 }
212 if ($res[2] ne "images") {
213 if (!$fail) {
214 $count++;
215 $fail = 1;
216 }
217 warn "Test 19 f: owner is not correct: expected \'images\' get \'$res[2]\'";
218 }
219 };
220 if ( $@ ) {
221 $count++;
222 warn "Test 19 f: $@";
223 }
224 };
225 $tests->{19} = $test19;
226
227 my $test18 = sub {
228
229 print "\nrun test18 \"scan_zfs\"\n";
230 my $res;
231
232 eval {
233 $res = PVE::Storage::scan_zfs($cfg, $storagename);
234
235 my $exists = 0;
236 foreach my $subvol (@$res){
237 if ($subvol->{pool} eq 'regressiontest') {
238 $exists++;
239 }
240 }
241 if (!$exists) {
242 $count++;
243 warn "Test 18 a: not pool";
244 }
245 };
246 if ( $@ ) {
247 $count++;
248 warn "Test 18 a: $@";
249 }
250 $res = undef;
251
252 eval {
253 $res = PVE::Storage::scan_zfs($cfg, $storagename);
254
255 foreach my $subvol (@$res){
256 if ($subvol->{pool} eq 'zfspool/subvol') {
257 $count++;
258 warn "Test 18 b:";
259 }
260 }
261
262 foreach my $subvol (@$res){
263 if ($subvol->{pool} eq 'zfspool/basevol') {
264 $count++;
265 warn "Test 18 c";
266 }
267 }
268 };
269 if ( $@ ) {
270 $count++;
271 warn "Test 18 a: $@";
272 }
273 };
274 $tests->{18} = $test18;
275
276 my $test17 = sub {
277
278 print "\nrun test17 \"deactivate_storage\"\n";
279
280 eval {
281 PVE::Storage::activate_storage($cfg, $storagename);
282 PVE::Storage::deactivate_storage($cfg, $storagename);
283 };
284 if ($@) {
285 $count++;
286 warn "Test 17 a: $@";
287 }
288 };
289 $tests->{17} = $test17;
290
291 my $test16 = sub {
292
293 print "\nrun test16 \"activate_storage\"\n";
294
295 eval {
296 PVE::Storage::activate_storage($cfg, $storagename);
297 };
298 if ($@) {
299 $count++;
300 warn "Test 16 a: $@";
301 }
302 };
303 $tests->{16} = $test16;
304
305 my $test15 = sub {
306
307 print "\nrun test15 \"template_list and vdisk_list\"\n";
308
309 my $hash = Dumper {};
310
311 my $res = Dumper PVE::Storage::template_list($cfg, $storagename, "vztmpl");
312 if ( $hash ne $res ) {
313 $count++;
314 warn "Test 15 a failed\n";
315 }
316 $res = undef;
317
318 $res = Dumper PVE::Storage::template_list($cfg, $storagename, "iso");
319 if ( $hash ne $res ) {
320 $count++;
321 warn "Test 15 b failed\n";
322 }
323 $res = undef;
324
325 $res = Dumper PVE::Storage::template_list($cfg, $storagename, "backup");
326 if ( $hash ne $res ) {
327 $count++;
328 warn "Test 15 c failed\n";
329 }
330 $res = undef;
331
332 $hash = Dumper {'zfstank99' => [
333 {
334 'parent' => undef,
335 'volid' => 'zfstank99:base-100-disk-1',
336 'name' => 'base-100-disk-1',
337 'vmid' => '100',
338 'size' => 1073741824,
339 'format' => 'raw'
340 }
341 ]};
342
343 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 100, ["$storagename:$vmbase"]);
344
345 if ( $hash ne $res ) {
346 $count++;
347 warn "Test 15 d failed\n";
348 }
349 $res = undef;
350
351 $hash = Dumper {'zfstank99' => [
352 {
353 'parent' => undef,
354 'volid' => 'zfstank99:vm-102-disk-1',
355 'name' => 'vm-102-disk-1',
356 'vmid' => '102',
357 'size' => 1073741824,
358 'format' => 'raw'
359 }
360 ]};
361
362 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 102, ["$storagename:$vmdisk"]);
363 if ( $hash ne $res ) {
364 $count++;
365 warn "Test 15 e failed\n";
366 }
367 $res = undef;
368
369 $hash = Dumper {'zfstank99' => [
370 {
371 'parent' => 'base-100-disk-1@__base__',
372 'volid' => "$storagename:$vmbase\/$vmlinked",
373 'name' => 'vm-101-disk-1',
374 'vmid' => '101',
375 'size' => 1073741824,
376 'format' => 'raw'
377 }
378 ]};
379
380 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 101, ["$storagename:$vmbase\/$vmlinked"]);
381 if ( $hash ne $res ) {
382 $count++;
383 warn "Test 15 f failed\n";
384 }
385 $res = undef;
386
387 $hash = Dumper {'zfstank99' => [
388 {
389 'parent' => undef,
390 'volid' => 'zfstank99:basevol-200-disk-1',
391 'name' => 'basevol-200-disk-1',
392 'vmid' => '200',
393 'size' => 1073741824,
394 'format' => 'subvol'
395 }
396 ]};
397
398 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 200, ["$storagename:$ctbase"]);
399 if ( $hash ne $res ) {
400 $count++;
401 warn "Test 15 g failed\n";
402 }
403 $res = undef;
404
405 $hash = Dumper {'zfstank99' => [
406 {
407 'parent' => undef,
408 'volid' => 'zfstank99:subvol-202-disk-1',
409 'name' => 'subvol-202-disk-1',
410 'vmid' => '202',
411 'size' => 1073741824,
412 'format' => 'subvol'
413 }
414 ]};
415
416 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 202, ["$storagename:$ctdisk"]);
417 if ( $hash ne $res ) {
418 $count++;
419 warn "Test 15 h failed\n";
420 }
421 $res = undef;
422
423 $hash = Dumper {'zfstank99' => [
424 {
425 'parent' => 'basevol-200-disk-1@__base__',
426 'volid' => "$storagename:$ctbase\/$ctlinked",
427 'name' => 'subvol-201-disk-1',
428 'vmid' => '201',
429 'size' => 1073741824,
430 'format' => 'subvol'
431 }
432 ]};
433 $res = Dumper PVE::Storage::vdisk_list($cfg, $storagename, 201, ["$storagename:$ctbase\/$ctlinked"]);
434 if ( $hash ne $res ) {
435 $count++;
436 warn "Test 15 i failed\n";
437 }
438 };
439 $tests->{15} = $test15;
440
441 my $test14 = sub {
442
443 print "\nrun test14 \"vdisk_free\"\n";
444
445 eval {
446 PVE::Storage::vdisk_free($cfg, "$storagename:$vmdisk");
447
448 eval {
449 run_command("zfs list $zpath\/$vmdisk", outfunc => sub {}, errfunc => sub {});
450 };
451 if (!$@) {
452 $count++;
453 warn "Test14 a: vdisk still exists\n";
454 }
455 };
456 if ($@) {
457 $count++;
458 warn "Test14 a: $@";
459 }
460
461 eval {
462 PVE::Storage::vdisk_free($cfg, "$storagename:$vmbase");
463 };
464 if (!$@) {
465 $count++;
466 warn "Test14 b: free vdisk should not work\n";
467 }
468
469 eval {
470 PVE::Storage::vdisk_free($cfg, "$storagename:$vmbase\/$vmlinked");
471
472 eval {
473 run_command("zfs list $zpath\/$vmlinked", outfunc => sub {}, errfunc => sub {});
474 };
475 if (!$@) {
476 $count++;
477 warn "Test14 c: vdisk still exists\n";
478 }
479 };
480 if ($@) {
481 $count++;
482 warn "Test14 c: $@";
483 }
484
485 eval {
486 PVE::Storage::vdisk_free($cfg, "$storagename:$ctdisk");
487
488 eval {
489 run_command("zfs list $zpath\/$ctdisk", outfunc => sub {}, errfunc => sub {});
490 };
491 if (!$@) {
492 $count++;
493 warn "Test14 d: vdisk still exists\n";
494 }
495 };
496 if ($@) {
497 $count++;
498 warn "Test14 d: $@";
499 }
500
501 eval {
502 PVE::Storage::vdisk_free($cfg, "$storagename:$ctbase");
503 };
504 if (!$@) {
505 $count++;
506 warn "Test14 e: free vdisk should not work\n";
507 }
508
509 eval {
510 PVE::Storage::vdisk_free($cfg, "$storagename:$ctbase\/$ctlinked");
511
512 eval {
513 run_command("zfs list $zpath\/$ctlinked", outfunc => sub {}, errfunc => sub {});
514 };
515 if (!$@) {
516 $count++;
517 warn "Test14 f: vdisk still exists\n";
518 }
519 };
520 if ($@) {
521 $count++;
522 warn "Test14 f: $@";
523 }
524
525 eval {
526 PVE::Storage::vdisk_free($cfg, "$storagename:$vmbase");
527
528 eval {
529 run_command("zfs list $zpath\/$vmbase", outfunc => sub {}, errfunc => sub {});
530 };
531 if (!$@) {
532 $count++;
533 warn "Test14 g: vdisk still exists\n";
534 }
535 };
536 if ($@) {
537 $count++;
538 warn "Test14 g: $@";
539 }
540
541 eval {
542 PVE::Storage::vdisk_free($cfg, "$storagename:$ctbase");
543
544 eval {
545 run_command("zfs list $zpath\/$ctbase", outfunc => sub {}, errfunc => sub {});
546 };
547 if (!$@) {
548 $count++;
549 warn "Test14 h: vdisk still exists\n";
550 }
551 };
552 if ($@) {
553 $count++;
554 warn "Test14 h: $@";
555 }
556 };
557 $tests->{14} = $test14;
558
559 my $test13 = sub {
560
561 print "\nrun test13 \"vdisk_alloc\"\n";
562
563 eval {
564 my $tmp_volid = PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef ,1024 * 1024);
565
566 if ($tmp_volid ne "$storagename:vm-112-disk-1") {
567 die "volname:$tmp_volid don't match\n";
568 }
569 eval {
570 run_command("zfs get -H volsize $zpath\/vm-112-disk-1", outfunc =>
571 sub { my $tmp = shift;
572 if ($tmp !~ m/^$zpath\/vm-112-disk-1.*volsize.*1G.*$/) {
573 die "size don't match\n";
574 }
575 });
576 };
577 if ($@) {
578 $count++;
579 warn "Test13 a: $@";
580 }
581 };
582 if ($@) {
583 $count++;
584 warn "Test13 a: $@";
585 }
586
587 eval {
588 my $tmp_volid = PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef ,2048 * 1024);
589
590 if ($tmp_volid ne "$storagename:vm-112-disk-2") {
591 die "volname:$tmp_volid don't match\n";
592 }
593 eval {
594 run_command("zfs get -H volsize $zpath\/vm-112-disk-2", outfunc =>
595 sub { my $tmp = shift;
596 if ($tmp !~ m/^$zpath\/vm-112-disk-2.*volsize.*2G.*$/) {
597 die "size don't match\n";
598 }
599 });
600 };
601 if ($@) {
602 $count++;
603 warn "Test13 b: $@";
604 }
605 };
606 if ($@) {
607 $count++;
608 warn "Test13 b: $@";
609 }
610
611 eval {
612 my $tmp_volid = PVE::Storage::vdisk_alloc($cfg, $storagename, "113", "subvol", undef ,1024 * 1024);
613
614 if ($tmp_volid ne "$storagename:subvol-113-disk-1") {
615 die "volname:$tmp_volid don't match\n";
616 }
617 eval {
618 run_command("zfs get -H refquota $zpath\/subvol-113-disk-1", outfunc =>
619 sub { my $tmp = shift;
620 if ($tmp !~ m/^$zpath\/subvol-113-disk-1.*refquota.*1G.*$/) {
621 die "size don't match\n";
622 }
623 });
624 };
625 if ($@) {
626 $count++;
627 warn "Test13 c: $@";
628 }
629 };
630 if ($@) {
631 $count++;
632 warn "Test13 c: $@";
633 }
634
635 eval {
636 my $tmp_volid = PVE::Storage::vdisk_alloc($cfg, $storagename, "113", "subvol", undef ,2048 * 1024);
637
638 if ($tmp_volid ne "$storagename:subvol-113-disk-2") {
639 die "volname:$tmp_volid don't match\n";
640 }
641 eval {
642 run_command("zfs get -H refquota $zpath\/subvol-113-disk-2", outfunc =>
643 sub { my $tmp = shift;
644 if ($tmp !~ m/^$zpath\/subvol-113-disk-2.*refquota.*G.*$/) {
645 die "size don't match\n";
646 }
647 });
648 };
649 if ($@) {
650 $count++;
651 warn "Test13 d: $@";
652 }
653 };
654 if ($@) {
655 $count++;
656 warn "Test13 d: $@";
657 }
658 };
659 $tests->{13} = $test13;
660
661 my $test12 = sub {
662
663 print "\nrun test12 \"vdisk_create_base\"\n";
664
665 eval {
666 my $tmp_volid = PVE::Storage::vdisk_create_base($cfg, "$storagename:$vmdisk");
667
668 if ($tmp_volid ne "$storagename:base-102-disk-1") {
669 die;
670 }
671 eval {
672 run_command("zfs list $zpath\/base-102-disk-1", outfunc => sub {});
673 };
674 if ($@) {
675 $count++;
676 warn "Test12 a: $@";
677 }
678 };
679 if ($@) {
680 $count++;
681 warn "Test12 a: $@";
682 }
683
684 eval {
685 my $tmp_volid = PVE::Storage::vdisk_create_base($cfg, "$storagename:$vmlinked");
686
687 if ($tmp_volid ne "$storagename:base-101-disk-1") {
688 die;
689 }
690 eval {
691 run_command("zfs list $zpath\/base-101-disk-1", outfunc => sub {});
692 };
693 if ($@) {
694 $count++;
695 warn "Test12 b: $@";
696 }
697 };
698 if ($@) {
699 $count++;
700 warn "Test12 b: $@";
701 }
702
703 eval {
704 my $tmp_volid = PVE::Storage::vdisk_create_base($cfg, "$storagename:$ctdisk");
705
706 if ($tmp_volid ne "$storagename:basevol-202-disk-1") {
707 die ;
708 }
709 eval {
710 run_command("zfs list $zpath\/basevol-202-disk-1", outfunc => sub {});
711 };
712 if ($@) {
713 $count++;
714 warn "Test12 c: $@";
715 }
716 };
717 if ($@) {
718 $count++;
719 warn "Test12 c: $@";
720 }
721
722 eval {
723 my $tmp_volid = PVE::Storage::vdisk_create_base($cfg, "$storagename:$ctlinked");
724
725 if ($tmp_volid ne "$storagename:basevol-201-disk-1") {
726 die;
727 }
728 eval {
729 run_command("zfs list $zpath\/basevol-201-disk-1", outfunc => sub {});
730 };
731 if ($@) {
732 $count++;
733 warn "Test12 d: $@";
734 }
735 };
736 if ($@) {
737 $count++;
738 warn "Test12 d: $@";
739 }
740 };
741 $tests->{12} = $test12;
742
743 my $test11 = sub {
744
745 print "\nrun test11 \"volume_is_base\"\n";
746
747 eval {
748 PVE::Storage::vdisk_clone($cfg, "$storagename:$vmdisk", 110);
749 };
750 if (!$@) {
751 $count++;
752 warn "Test11 a: clone_image only works on base images";
753 }
754
755 eval {
756 if ("$storagename:$vmbase\/vm-110-disk-1" ne
757 PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase", 110, '__base__')){
758 $count++;
759 warn "Test11 b";
760 }
761 run_command("zfs list -H -o volsize $zpath\/vm-110-disk-1", outfunc => sub {
762 my $line = shift;
763
764 chomp($line);
765 warn "Test11 b not correct volsize" if $line !~ m/$volsize/;
766 });
767 };
768 if ($@) {
769 $count++;
770 warn "Test11 b: $@";
771 }
772
773 eval {
774 PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase\/$vmlinked", 111);
775 };
776 if (!$@) {
777 $count++;
778 warn "Test11 c: clone_image only works on base images";
779 }
780
781 eval {
782 PVE::Storage::vdisk_clone($cfg, "$storagename:$ctdisk", 110);
783 };
784 if (!$@) {
785 $count++;
786 warn "Test11 d: clone_image only works on base images";
787 }
788
789 eval {
790 if ( "$storagename:$ctbase\/subvol-210-disk-1" ne
791 PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase", 210, '__base__')){
792 $count++;
793 warn "Test11 e";
794 }
795 run_command("zfs list -H -o refquota $zpath\/subvol-210-disk-1", outfunc => sub {
796 my $line = shift;
797
798 chomp($line);
799 warn "Test11 e not correct volsize" if $line !~ m/$volsize/;
800 });
801 };
802 if ($@) {
803 $count++;
804 warn "Test11 e: $@";
805 }
806
807 eval {
808 PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase\/$ctlinked", 211);
809 };
810 if (!$@) {
811 $count++;
812 warn "Test11 f: clone_image only works on base images";
813 }
814 };
815 $tests->{11} = $test11;
816
817 my $test10 =sub {
818
819 print "\nrun test10 \"volume_is_base\"\n";
820
821 eval {
822 if (1 == volume_is_base($cfg, "$storagename:$vmdisk")) {
823 $count++;
824 warn "Test10 a: is no base";
825 }
826
827 };
828 if ($@) {
829 $count++;
830 warn "Test10 a: $@";
831 }
832
833 eval {
834 if (0 == volume_is_base($cfg, "$storagename:$vmbase")) {
835 $count++;
836 warn "Test10 b: is base";
837 }
838
839 };
840 if ($@) {
841 $count++;
842 warn "Test10 b: $@";
843 }
844
845 eval {
846 if (1 == volume_is_base($cfg, "$storagename:$vmbase\/$vmlinked")) {
847 $count++;
848 warn "Test10 c: is no base";
849 }
850
851 };
852 if ($@) {
853 $count++;
854 warn "Test10 c: $@";
855 }
856
857 eval {
858 if (1 == volume_is_base($cfg, "$storagename:$ctdisk")) {
859 $count++;
860 warn "Test10 d: is no base";
861 }
862
863 };
864 if ($@) {
865 $count++;
866 warn "Test10 d: $@";
867 }
868
869 eval {
870 if (0 == volume_is_base($cfg, "$storagename:$ctbase")) {
871 $count++;
872 warn "Test10 e: is base";
873 }
874
875 };
876 if ($@) {
877 $count++;
878 warn "Test10 e: $@";
879 }
880
881 eval {
882 if (1 == volume_is_base($cfg, "$storagename:$ctbase\/$ctlinked")) {
883 $count++;
884 warn "Test10 f: is no base";
885 }
886
887 };
888 if ($@) {
889 $count++;
890 warn "Test10 f: $@";
891 }
892 };
893 $tests->{10} = $test10;
894
895 my $test9 =sub {
896
897 print "\nrun test9 \"parse_volume_id\"\n";
898
899 eval {
900 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$vmdisk");
901
902 if ($store ne $storagename || $disk ne $vmdisk) {
903 $count++;
904 warn "Test9 a: parsing wrong";
905 }
906
907 };
908 if ($@) {
909 $count++;
910 warn "Test9 a: $@";
911 }
912
913 eval {
914 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$vmbase");
915
916 if ($store ne $storagename || $disk ne $vmbase) {
917 $count++;
918 warn "Test9 b: parsing wrong";
919 }
920
921 };
922 if ($@) {
923 $count++;
924 warn "Test9 b: $@";
925 }
926
927 eval {
928 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$vmbase\/$vmlinked");
929
930 if ($store ne $storagename || $disk ne "$vmbase\/$vmlinked") {
931 $count++;
932 warn "Test9 c: parsing wrong";
933 }
934
935 };
936 if ($@) {
937 $count++;
938 warn "Test9 c: $@";
939 }
940
941 eval {
942 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$ctdisk");
943
944 if ($store ne $storagename || $disk ne $ctdisk) {
945 $count++;
946 warn "Test9 d: parsing wrong";
947 }
948
949 };
950 if ($@) {
951 $count++;
952 warn "Test9 d: $@";
953 }
954
955 eval {
956 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$ctbase");
957
958 if ($store ne $storagename || $disk ne $ctbase) {
959 $count++;
960 warn "Test9 e: parsing wrong";
961 }
962
963 };
964 if ($@) {
965 $count++;
966 warn "Test9 e: $@";
967 }
968
969 eval {
970 my ($store, $disk) = PVE::Storage::parse_volume_id("$storagename:$ctbase\/$ctlinked");
971
972 if ($store ne $storagename || $disk ne "$ctbase\/$ctlinked") {
973 $count++;
974 warn "Test9 f: parsing wrong";
975 }
976
977 };
978 if ($@) {
979 $count++;
980 warn "Test9 f: $@";
981 }
982 };
983 $tests->{9} = $test9;
984
985 my $test8 = sub {
986
987 print "\nrun test8 \"parse_volname\"\n";
988
989 eval {
990 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$vmdisk");
991
992 if ($vtype ne 'images' || $vmid ne '102' || $name ne $vmdisk ||
993 defined($basename) || defined($basevmid) || $isBase ||
994 $format ne 'raw') {
995 $count++;
996 warn "Test8 a: parsing wrong";
997 }
998
999 };
1000 if ($@) {
1001 $count++;
1002 warn "Test8 a: $@";
1003 }
1004
1005 eval {
1006 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$vmbase");
1007
1008 if ($vtype ne 'images' || $vmid ne '100' || $name ne $vmbase ||
1009 defined($basename) || defined($basevmid) || !$isBase ||
1010 $format ne 'raw') {
1011 $count++;
1012 warn "Test8 b: parsing wrong";
1013 }
1014 };
1015 if ($@) {
1016 $count++;
1017 warn "Test8 b: $@";
1018 }
1019
1020 eval {
1021 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$vmbase\/$vmlinked");
1022
1023 if ($vtype ne 'images' || $name ne $vmlinked || $vmid ne '101' ||
1024 $basename ne $vmbase || $basevmid ne '100' || $isBase ||
1025 $format ne 'raw') {
1026 $count++;
1027 warn "Test8 c: parsing wrong";
1028 }
1029 };
1030 if ($@) {
1031 $count++;
1032 warn "Test8 c: $@";
1033 }
1034
1035 eval {
1036 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$ctdisk");
1037
1038 if ($vtype ne 'images' || $vmid ne '202' || $name ne $ctdisk ||
1039 defined($basename) || defined($basevmid) || $isBase ||
1040 $format ne 'subvol') {
1041 $count++;
1042 warn "Test8 d: parsing wrong";
1043 }
1044
1045 };
1046 if ($@) {
1047 $count++;
1048 warn "Test8 d: $@";
1049 }
1050
1051 eval {
1052 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$ctbase");
1053 if ($vtype ne 'images' || $vmid ne '200' || $name ne $ctbase ||
1054 defined($basename) || defined($basevmid) || !$isBase ||
1055 $format ne 'subvol') {
1056 $count++;
1057 warn "Test8 e: parsing wrong";
1058 }
1059 };
1060 if ($@) {
1061 $count++;
1062 warn "Test8 e: $@";
1063 }
1064
1065 eval {
1066 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = PVE::Storage::parse_volname($cfg, "$storagename:$ctbase\/$ctlinked");
1067
1068 if ($vtype ne 'images' || $name ne $ctlinked || $vmid ne '201' ||
1069 $basename ne $ctbase || $basevmid ne '200' || $isBase ||
1070 $format ne 'subvol') {
1071 $count++;
1072 warn "Test8 f: parsing wrong";
1073 }
1074 };
1075 if ($@) {
1076 $count++;
1077 warn "Test8 f: $@";
1078 }
1079 };
1080 $tests->{8} = $test8;
1081
1082 my $test7 = sub {
1083
1084 print "\nrun test7 \"volume_rollback\"\n";
1085
1086 my $tmp_guid;
1087 my $parse_guid = sub {
1088 my ($line) = shift;
1089
1090 if ( $line =~ m/^Disk identifier \(GUID\)\: (.*)$/ ) {
1091 $tmp_guid = $1;
1092 }
1093 };
1094
1095 eval {
1096 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmdisk", outfunc => $parse_guid);
1097 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmdisk", outfunc => $parse_guid);
1098
1099 my $old_guid = $tmp_guid;
1100 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap1');
1101
1102 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmdisk", outfunc => $parse_guid);
1103 eval {
1104 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmdisk", 'snap1');
1105 $tmp_guid = undef;
1106 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmdisk", outfunc => $parse_guid);
1107 if ($old_guid ne $tmp_guid) {
1108 $count++;
1109 warn "Test7 a: Zvol makes no rollback";
1110 }
1111 };
1112 if ($@) {
1113 $count++;
1114 warn "Test7 a: $@";
1115 }
1116 };
1117 if ($@) {
1118 $count++;
1119 warn "Test7 a: $@";
1120 }
1121 $tmp_guid = undef;
1122
1123 eval {
1124 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmbase", outfunc => $parse_guid);
1125 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmbase", outfunc => $parse_guid);
1126
1127 my $old_guid = $tmp_guid;
1128 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap1');
1129
1130 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmbase", outfunc => $parse_guid);
1131 eval {
1132 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmbase", 'snap1');
1133 $tmp_guid = undef;
1134 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmbase", outfunc => $parse_guid);
1135 if ($old_guid ne $tmp_guid) {
1136 $count++;
1137 warn "Test7 b: Zvol makes no rollback";
1138 }
1139 };
1140 if ($@) {
1141 $count++;
1142 warn "Test7 b: $@";
1143 }
1144 };
1145 if ($@) {
1146 $count++;
1147 warn "Test7 b: $@";
1148 }
1149 $tmp_guid = undef;
1150
1151 eval {
1152 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmlinked", outfunc => $parse_guid);
1153 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmlinked", outfunc => $parse_guid);
1154
1155 my $old_guid = $tmp_guid;
1156 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1');
1157
1158 run_command("sgdisk --randomize-guids \/dev\/zvol\/$zpath\/$vmlinked", outfunc => $parse_guid);
1159 eval {
1160 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1');
1161 $tmp_guid = undef;
1162 run_command("sgdisk -p \/dev\/zvol\/$zpath\/$vmlinked", outfunc => $parse_guid);
1163 if ($old_guid ne $tmp_guid) {
1164 $count++;
1165 warn "Test7 c: Zvol makes no rollback";
1166 }
1167 };
1168 if ($@) {
1169 $count++;
1170 warn "Test7 c: $@";
1171 }
1172 };
1173 if ($@) {
1174 $count++;
1175 warn "Test7 c: $@";
1176 }
1177 $tmp_guid = undef;
1178
1179 eval {
1180 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap1');
1181
1182 run_command("touch \/$zpath\/$ctdisk\/test.txt", outfunc => $parse_guid);
1183 eval {
1184 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctdisk", 'snap1');
1185 eval {
1186 run_command("ls \/$zpath\/$ctdisk\/test.txt", errofunc => sub {});
1187 };
1188 if (!$@) {
1189 $count++;
1190 warn "Test7 d: $@";
1191 }
1192 };
1193 if ($@) {
1194 $count++;
1195 warn "Test7 d: $@";
1196 }
1197 };
1198 if ($@) {
1199 $count++;
1200 warn "Test7 d: $@";
1201 }
1202
1203 eval {
1204 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap1');
1205
1206 run_command("touch \/$zpath\/$ctbase\/test.txt", outfunc => $parse_guid);
1207 eval {
1208 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctbase", 'snap1');
1209 eval {
1210 run_command("ls \/$zpath\/$ctbase\/test.txt", errofunc => sub {});
1211 };
1212 if (!$@) {
1213 $count++;
1214 warn "Test7 e: $@";
1215 }
1216 };
1217 if ($@) {
1218 $count++;
1219 warn "Test7 e: $@";
1220 }
1221 };
1222 if ($@) {
1223 $count++;
1224 warn "Test7 f: $@";
1225 }
1226
1227 eval {
1228 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase/$ctlinked", 'snap1');
1229
1230 run_command("touch \/$zpath\/$ctlinked\/test.txt", outfunc => $parse_guid);
1231 eval {
1232 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctbase/$ctlinked", 'snap1');
1233 eval {
1234 run_command("ls \/$zpath\/$ctlinked\/test.txt", errofunc => sub {});
1235 };
1236 if (!$@) {
1237 $count++;
1238 warn "Test7 g: $@";
1239 }
1240 };
1241 if ($@) {
1242 $count++;
1243 warn "Test7 g: $@";
1244 }
1245 };
1246 if ($@) {
1247 $count++;
1248 warn "Test7 g: $@";
1249 }
1250
1251 eval {
1252 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap2');
1253
1254 eval {
1255 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmdisk", 'snap1');
1256 };
1257 if (!$@) {
1258 $count++;
1259 warn "Test7 h: Not allowed to rollback";
1260 }
1261 };
1262 if ($@) {
1263 $count++;
1264 warn "Test7 h: $@";
1265 }
1266
1267 eval {
1268 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap2');
1269
1270 eval {
1271 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmbase", 'snap1');
1272 };
1273 if (!$@) {
1274 $count++;
1275 warn "Test7 i: Not allowed to rollback";
1276 }
1277 };
1278 if ($@) {
1279 $count++;
1280 warn "Test7 i: $@";
1281 }
1282
1283 eval {
1284 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase\/$vmlinked", 'snap2');
1285
1286 eval {
1287 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1');
1288 };
1289 if (!$@) {
1290 $count++;
1291 warn "Test7 j: Not allowed to rollback";
1292 }
1293 };
1294 if ($@) {
1295 $count++;
1296 warn "Test7 j: $@";
1297 }
1298
1299 eval {
1300 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap2');
1301
1302 eval {
1303 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctdisk", 'snap1');
1304 };
1305 if (!$@) {
1306 $count++;
1307 warn "Test7 k: Not allowed to rollback";
1308 }
1309 };
1310 if ($@) {
1311 $count++;
1312 warn "Test7 k: $@";
1313 }
1314
1315 eval {
1316 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap2');
1317
1318 eval {
1319 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctbase", 'snap1');
1320 };
1321 if (!$@) {
1322 $count++;
1323 warn "Test7 l: Not allowed to rollback";
1324 }
1325 };
1326 if ($@) {
1327 $count++;
1328 warn "Test7 l: $@";
1329 }
1330
1331 eval {
1332 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase/$ctlinked", 'snap2');
1333
1334 eval {
1335 PVE::Storage::volume_snapshot_rollback($cfg, "$storagename:$ctbase/$ctlinked", 'snap1');
1336 };
1337 if (!$@) {
1338 $count++;
1339 warn "Test7 m: Not allowed to rollback";
1340 }
1341 };
1342 if ($@) {
1343 $count++;
1344 warn "Test7 m: $@";
1345 }
1346 };
1347 $tests->{7} = $test7;
1348
1349 my $test6 = sub {
1350
1351 print "\nrun test6 \"volume_rollback_is_possible\"\n";
1352
1353 eval {
1354 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap1');
1355 if ( 1 !=
1356 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmdisk", 'snap1')) {
1357 $count++;
1358 warn "Test6 a: Rollback sould possible"
1359 }
1360 };
1361 if ($@) {
1362 $count++;
1363 warn "Test6 a: $@";
1364 }
1365
1366 eval {
1367 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap1');
1368 if ( 1 !=
1369 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase", 'snap1')) {
1370 $count++;
1371 warn "Test6 b: Rollback sould possible"
1372 }
1373 };
1374 if ($@) {
1375 $count++;
1376 warn "Test6 b: $@";
1377 }
1378
1379 eval {
1380 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmlinked", 'snap1');
1381 if ( 1 !=
1382 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1')) {
1383 $count++;
1384 warn "Test6 c: Rollback sould possible"
1385 }
1386 };
1387 if ($@) {
1388 $count++;
1389 warn "Test6 c: $@";
1390 }
1391
1392 eval {
1393 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap1');
1394 if ( 1 !=
1395 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctdisk", 'snap1')) {
1396 $count++;
1397 warn "Test6 d: Rollback sould possible"
1398 }
1399 };
1400 if ($@) {
1401 $count++;
1402 warn "Test6 d: $@";
1403 }
1404
1405 eval {
1406 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap1');
1407 if ( 1 !=
1408 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase", 'snap1')) {
1409 $count++;
1410 warn "Test6 e: Rollback sould possible"
1411 }
1412 };
1413 if ($@) {
1414 $count++;
1415 warn "Test6 e: $@";
1416 }
1417
1418 eval {
1419 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctlinked", 'snap1');
1420 if ( 1 !=
1421 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase\/$ctlinked", 'snap1')) {
1422 $count++;
1423 warn "Test6 f: Rollback sould possible"
1424 }
1425 };
1426 if ($@) {
1427 $count++;
1428 warn "Test6 f: $@";
1429 }
1430
1431 eval {
1432 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap2');
1433 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmdisk", 'snap1');
1434 };
1435 if (!$@) {
1436 $count++;
1437 warn "Test6 g: Rollback should not possible";
1438 }
1439
1440 eval {
1441 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap2');
1442 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase", 'snap1');
1443 };
1444 if (!$@) {
1445 $count++;
1446 warn "Test6 h: Rollback should not possible";
1447 }
1448
1449 eval {
1450 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmlinked", 'snap2');
1451 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1');
1452 };
1453 if (!$@) {
1454 $count++;
1455 warn "Test6 j: Rollback should not possible";
1456 }
1457
1458 eval {
1459 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap2');
1460 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctdisk", 'snap1');
1461 };
1462 if (!$@) {
1463 $count++;
1464 warn "Test6 k: Rollback should not possible";
1465 }
1466
1467 eval {
1468 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap2');
1469 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase", 'snap1');
1470 };
1471 if (!$@) {
1472 $count++;
1473 warn "Test6 l: Rollback should not possible";
1474 }
1475
1476 eval {
1477 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctlinked", 'snap2');
1478 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase\/$ctlinked", 'snap1');
1479 };
1480 if (!$@) {
1481 $count++;
1482 warn "Test6 m: Rollback should not possible";
1483 }
1484 };
1485 $tests->{6} = $test6;
1486
1487 my $test5 = sub {
1488
1489 print "\nrun test5 \"volume_snapshot_delete\"\n";
1490 my $out = sub{my $tmp = shift;};
1491
1492 eval {
1493 run_command("zfs snapshot $zpath\/$vmdisk\@snap");
1494 eval{
1495 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmdisk", 'snap');
1496 eval{
1497 run_command("zfs list $zpath\/$vmdisk\@snap", errfunc => $out, outfunc => $out);
1498 };
1499 if (!$@) {
1500 $count++;
1501 warn "Test5 a: snapshot still exists";
1502 }
1503 };
1504 if ($@) {
1505 $count++;
1506 warn "Test5 PVE a: $@";
1507 }
1508 };
1509 if ($@) {
1510 $count++;
1511 warn "Test5 a: $@";
1512 }
1513
1514 eval {
1515 run_command("zfs snapshot $zpath\/$vmbase\@snap");
1516 eval{
1517 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase", 'snap');
1518 eval{
1519 run_command("zfs list $zpath\/$vmbase\@snap", errmsg => $out, outfunc => $out);
1520 };
1521 if (!$@) {
1522 $count++;
1523 warn "Test5 b: snapshot still exists";
1524 }
1525 };
1526 if ($@) {
1527 $count++;
1528 warn "Test5 PVE b: $@";
1529 }
1530 };
1531 if ($@) {
1532 $count++;
1533 warn "Test5 b: $@";
1534 }
1535
1536 eval {
1537 run_command("zfs snapshot $zpath\/$vmlinked\@snap");
1538 eval{
1539 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase\/$vmlinked", 'snap');
1540 eval{
1541 run_command("zfs list $zpath\/$vmlinked\@snap", errmsg => $out, outfunc => $out);
1542 };
1543 if (!$@) {
1544 $count++;
1545 warn "Test5 c: snapshot still exists";
1546 }
1547 };
1548 if ($@) {
1549 $count++;
1550 warn "Test5 PVE c: $@";
1551 }
1552 };
1553 if ($@) {
1554 $count++;
1555 warn "Test5 c: $@";
1556 }
1557
1558 eval {
1559 run_command("zfs snapshot $zpath\/$ctdisk\@snap");
1560 eval{
1561 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctdisk", 'snap');
1562 eval{
1563 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1564 };
1565 if (!$@) {
1566 $count++;
1567 warn "Test5 d: snapshot still exists";
1568 }
1569 };
1570 if ($@) {
1571 $count++;
1572 warn "Test5 PVE d: $@";
1573 }
1574 };
1575 if ($@) {
1576 $count++;
1577 warn "Test5 d: $@";
1578 }
1579
1580 eval {
1581 run_command("zfs snapshot $zpath\/$ctbase\@snap");
1582 eval{
1583 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctbase", 'snap');
1584 eval{
1585 run_command("zfs list $zpath\/$ctbase\@snap", errmsg => $out, outfunc => $out);
1586 };
1587 if (!$@) {
1588 $count++;
1589 warn "Test5 e: snapshot still exists";
1590 }
1591 };
1592 if ($@) {
1593 $count++;
1594 warn "Test5 PVE e: $@";
1595 }
1596 };
1597 if ($@) {
1598 $count++;
1599 warn "Test5 e: $@";
1600 }
1601
1602 eval {
1603 run_command("zfs snapshot $zpath\/$ctlinked\@snap");
1604 eval{
1605 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctbase\/$ctlinked", 'snap');
1606 eval{
1607 run_command("zfs list $zpath\/$ctlinked\@snap", errmsg => $out, outfunc => $out);
1608 };
1609 if (!$@) {
1610 $count++;
1611 warn "Test5 f: snapshot still exists";
1612 }
1613 };
1614 if ($@) {
1615 $count++;
1616 warn "Test5 PVE f: $@";
1617 }
1618 };
1619 if ($@) {
1620 $count++;
1621 warn "Test5 f: $@";
1622 }
1623 print "######Ignore Output if no Test5 g: is included######\n";
1624 eval{
1625 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase", '__base__');
1626 eval{
1627 run_command("zfs list $zpath\/$vmbase\@__base__", outfunc => $out);
1628 };
1629 if ($@) {
1630 $count++;
1631 warn "Test5 g: $@";
1632 }
1633 };
1634 if (!$@) {
1635 $count++;
1636 warn "Test5 PVE g: snapshot __base__ can be erased";
1637 }
1638 print "######End Ignore#######\n";
1639 };
1640 $tests->{5} = $test5;
1641
1642 my $test4 = sub {
1643
1644 print "\nrun test4 \"volume_snapshot\"\n";
1645 my $out = sub{};
1646
1647 eval {
1648 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap');
1649 eval{
1650 run_command("zfs list $zpath\/$vmdisk\@snap", errmsg => $out, outfunc => $out);
1651 };
1652 if ($@) {
1653 $count++;
1654 warn "Test4 a: $@";
1655 }
1656 };
1657 if ($@) {
1658 $count++;
1659 warn "Test4 a: $@";
1660 }
1661
1662 eval {
1663 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap');
1664 eval{
1665 run_command("zfs list $zpath\/$vmbase\@snap", errmsg => $out, outfunc => $out);
1666 };
1667 if ($@) {
1668 $count++;
1669 warn "Test4 b: $@";
1670 }
1671 };
1672 if ($@) {
1673 $count++;
1674 warn "Test4 c: $@";
1675 }
1676
1677 eval {
1678 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase\/$vmlinked", 'snap');
1679 eval{
1680 run_command("zfs list $zpath\/$vmdisk\@snap", errmsg => $out, outfunc => $out);
1681 };
1682 if ($@) {
1683 $count++;
1684 warn "Test4 c: $@";
1685 }
1686 };
1687 if ($@) {
1688 $count++;
1689 warn "Test4 c: $@";
1690 }
1691
1692 eval {
1693 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap');
1694 eval{
1695 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1696 };
1697 if ($@) {
1698 $count++;
1699 warn "Test4 d: $@";
1700 }
1701 };
1702 if ($@) {
1703 $count++;
1704 warn "Test4 d: $@";
1705 }
1706
1707 eval {
1708 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap');
1709 eval{
1710 run_command("zfs list $zpath\/$ctbase\@snap", errmsg => $out, outfunc => $out);
1711 };
1712 if ($@) {
1713 $count++;
1714 warn "Test4 e: $@";
1715 }
1716 };
1717 if ($@) {
1718 $count++;
1719 warn "Test4 e: $@";
1720 }
1721
1722 eval {
1723 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase\/$ctlinked", 'snap');
1724 eval{
1725 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1726 };
1727 if ($@) {
1728 $count++;
1729 warn "Test4 f: $@";
1730 }
1731 };
1732 if ($@) {
1733 $count++;
1734 warn "Test4 f: $@";
1735 }
1736 };
1737 $tests->{4} = $test4;
1738
1739 my $test3 = sub {
1740
1741 print "\nrun test3 \"volume_has_feature\"\n";
1742
1743 eval {
1744 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmdisk", undef, 0)) {
1745 $count++;
1746 warn "Test3 a failed";
1747 }
1748 };
1749 if ($@) {
1750 $count++;
1751 warn "Test3 a: $@";
1752 }
1753
1754 eval {
1755 if (PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase", undef, 0)) {
1756 $count++;
1757 warn "Test3 b failed";
1758 }
1759 };
1760 if ($@) {
1761 $count++;
1762 warn "Test3 b: $@";
1763 }
1764
1765 eval {
1766 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1767 $count++;
1768 warn "Test3 c failed";
1769 }
1770 };
1771 if ($@) {
1772 $count++;
1773 warn "Test3 c: $@";
1774 }
1775
1776 eval {
1777 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctdisk", undef, 0)) {
1778 $count++;
1779 warn "Test3 d failed";
1780 }
1781 };
1782 if ($@) {
1783 $count++;
1784 warn "Test3 d: $@";
1785 }
1786
1787 eval {
1788 if (PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase", undef, 0)) {
1789 $count++;
1790 warn "Test3 e failed";
1791 }
1792 };
1793 if ($@) {
1794 $count++;
1795 warn "Test3 e: $@";
1796 }
1797
1798 eval {
1799 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1800 $count++;
1801 warn "Test3 f failed";
1802 }
1803 };
1804 if ($@) {
1805 $count++;
1806 warn "Test3 f: $@";
1807 }
1808
1809 eval {
1810 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmdisk", undef, 0)) {
1811 $count++;
1812 warn "Test3 g failed";
1813 }
1814 };
1815 if ($@) {
1816 $count++;
1817 warn "Test3 g: $@";
1818 }
1819
1820 eval {
1821 if (!PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase", undef, 0)) {
1822 $count++;
1823 warn "Test3 h failed";
1824 }
1825 };
1826 if ($@) {
1827 $count++;
1828 warn "Test3 h: $@";
1829 }
1830
1831 eval {
1832 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1833 $count++;
1834 warn "Test3 h failed";
1835 }
1836 };
1837 if ($@) {
1838 $count++;
1839 warn "Test3 h: $@";
1840 }
1841
1842 eval {
1843 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctdisk", undef, 0)) {
1844 $count++;
1845 warn "Test3 i failed";
1846 }
1847 };
1848 if ($@) {
1849 $count++;
1850 warn "Test3 i: $@";
1851 }
1852
1853 eval {
1854 if (!PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase", undef, 0)) {
1855 $count++;
1856 warn "Test3 j failed";
1857 }
1858 };
1859 if ($@) {
1860 $count++;
1861 warn "Test3 j: $@";
1862 }
1863
1864 eval {
1865 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1866 $count++;
1867 warn "Test3 k failed";
1868 }
1869 };
1870 if ($@) {
1871 $count++;
1872 warn "Test3 k: $@";
1873 }
1874
1875 eval {
1876 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmdisk", undef, 0)) {
1877 $count++;
1878 warn "Test3 l failed";
1879 }
1880 };
1881 if ($@) {
1882 $count++;
1883 warn "Test3 l: $@";
1884 }
1885
1886 eval {
1887 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase", undef, 0)) {
1888 $count++;
1889 warn "Test3 m failed";
1890 }
1891 };
1892 if ($@) {
1893 $count++;
1894 warn "Test3 m: $@";
1895 }
1896
1897 eval {
1898 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1899 $count++;
1900 warn "Test3 n failed";
1901 }
1902 };
1903 if ($@) {
1904 $count++;
1905 warn "Test3 n: $@";
1906 }
1907
1908 eval {
1909 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctdisk", undef, 0)) {
1910 $count++;
1911 warn "Test3 o failed";
1912 }
1913 };
1914 if ($@) {
1915 $count++;
1916 warn "Test3 o: $@";
1917 }
1918
1919 eval {
1920 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase", undef, 0)) {
1921 $count++;
1922 warn "Test3 p failed";
1923 }
1924 };
1925 if ($@) {
1926 $count++;
1927 warn "Test3 p: $@";
1928 }
1929
1930 eval {
1931 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1932 $count++;
1933 warn "Test3 q failed";
1934 }
1935 };
1936 if ($@) {
1937 $count++;
1938 warn "Test3 q: $@";
1939 }
1940
1941 eval {
1942 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmdisk", undef, 0)) {
1943 $count++;
1944 warn "Test3 r failed";
1945 }
1946 };
1947 if ($@) {
1948 $count++;
1949 warn "Test3 r: $@";
1950 }
1951
1952 eval {
1953 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase", undef, 0)) {
1954 $count++;
1955 warn "Test3 s failed";
1956 }
1957 };
1958 if ($@) {
1959 $count++;
1960 warn "Test3 s: $@";
1961 }
1962
1963 eval {
1964 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1965 $count++;
1966 warn "Test3 t failed";
1967 }
1968 };
1969 if ($@) {
1970 $count++;
1971 warn "Test3 t: $@";
1972 }
1973
1974 eval {
1975 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctdisk", undef, 0)) {
1976 $count++;
1977 warn "Test3 u failed";
1978 }
1979 };
1980 if ($@) {
1981 $count++;
1982 warn "Test3 u: $@";
1983 }
1984
1985 eval {
1986 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase", undef, 0)) {
1987 $count++;
1988 warn "Test3 v failed";
1989 }
1990 };
1991 if ($@) {
1992 $count++;
1993 warn "Test3 v: $@";
1994 }
1995
1996 eval {
1997 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1998 $count++;
1999 warn "Test3 w failed";
2000 }
2001 };
2002 if ($@) {
2003 $count++;
2004 warn "Test3 w: $@";
2005 }
2006
2007 eval {
2008 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmdisk", undef, 0)) {
2009 $count++;
2010 warn "Test3 x failed";
2011 }
2012 };
2013 if ($@) {
2014 $count++;
2015 warn "Test3 x: $@";
2016 }
2017
2018 eval {
2019 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase", undef, 0)) {
2020 $count++;
2021 warn "Test3 y failed";
2022 }
2023 };
2024 if ($@) {
2025 $count++;
2026 warn "Test3 y: $@";
2027 }
2028
2029 eval {
2030 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
2031 $count++;
2032 warn "Test3 z failed";
2033 }
2034 };
2035 if ($@) {
2036 $count++;
2037 warn "Test3 z: $@";
2038 }
2039
2040 eval {
2041 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctdisk", undef, 0)) {
2042 $count++;
2043 warn "Test3 A failed";
2044 }
2045 };
2046 if ($@) {
2047 $count++;
2048 warn "Test3 A: $@";
2049 }
2050
2051 eval {
2052 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase", undef, 0)) {
2053 $count++;
2054 warn "Test3 B failed";
2055 }
2056 };
2057 if ($@) {
2058 $count++;
2059 warn "Test3 B: $@";
2060 }
2061
2062 eval {
2063 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
2064 $count++;
2065 warn "Test3 C failed";
2066 }
2067 };
2068 if ($@) {
2069 $count++;
2070 warn "Test3 C: $@";
2071 }
2072
2073 eval {
2074 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmdisk", 'test', 0)) {
2075 $count++;
2076 warn "Test3 a1 failed";
2077 }
2078 };
2079 if ($@) {
2080 $count++;
2081 warn "Test3 a1: $@";
2082 }
2083
2084 eval {
2085 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase", 'test', 0)) {
2086 $count++;
2087 warn "Test3 b1 failed";
2088 }
2089 };
2090 if ($@) {
2091 $count++;
2092 warn "Test3 b1: $@";
2093 }
2094
2095 eval {
2096 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2097 $count++;
2098 warn "Test3 c1 failed";
2099 }
2100 };
2101 if ($@) {
2102 $count++;
2103 warn "Test3 c1: $@";
2104 }
2105
2106 eval {
2107 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctdisk", 'test', 0)) {
2108 $count++;
2109 warn "Test3 d1 failed";
2110 }
2111 };
2112 if ($@) {
2113 $count++;
2114 warn "Test3 d1: $@";
2115 }
2116
2117 eval {
2118 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase", 'test', 0)) {
2119 $count++;
2120 warn "Test3 e1 failed";
2121 }
2122 };
2123 if ($@) {
2124 $count++;
2125 warn "Test3 e1: $@";
2126 }
2127
2128 eval {
2129 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2130 $count++;
2131 warn "Test3 f1 failed";
2132 }
2133 };
2134 if ($@) {
2135 $count++;
2136 warn "Test3 f1: $@";
2137 }
2138
2139 eval {
2140 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmdisk", 'test', 0)) {
2141 $count++;
2142 warn "Test3 g1 failed";
2143 }
2144 };
2145 if ($@) {
2146 $count++;
2147 warn "Test3 g1: $@";
2148 }
2149
2150 eval {
2151 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase", 'test', 0)) {
2152 $count++;
2153 warn "Test3 h1 failed";
2154 }
2155 };
2156 if ($@) {
2157 $count++;
2158 warn "Test3 h1: $@";
2159 }
2160
2161 eval {
2162 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2163 $count++;
2164 warn "Test3 h1 failed";
2165 }
2166 };
2167 if ($@) {
2168 $count++;
2169 warn "Test3 h1: $@";
2170 }
2171
2172 eval {
2173 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctdisk", 'test', 0)) {
2174 $count++;
2175 warn "Test3 i1 failed";
2176 }
2177 };
2178 if ($@) {
2179 $count++;
2180 warn "Test3 i1: $@";
2181 }
2182
2183 eval {
2184 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase", 'test', 0)) {
2185 $count++;
2186 warn "Test3 j1 failed";
2187 }
2188 };
2189 if ($@) {
2190 $count++;
2191 warn "Test3 j1: $@";
2192 }
2193
2194 eval {
2195 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2196 $count++;
2197 warn "Test3 k1 failed";
2198 }
2199 };
2200 if ($@) {
2201 $count++;
2202 warn "Test3 k1: $@";
2203 }
2204
2205 eval {
2206 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmdisk", 'test', 0)) {
2207 $count++;
2208 warn "Test3 l1 failed";
2209 }
2210 };
2211 if ($@) {
2212 $count++;
2213 warn "Test3 l1: $@";
2214 }
2215
2216 eval {
2217 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase", 'test', 0)) {
2218 $count++;
2219 warn "Test3 m1 failed";
2220 }
2221 };
2222 if ($@) {
2223 $count++;
2224 warn "Test3 m1: $@";
2225 }
2226
2227 eval {
2228 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2229 $count++;
2230 warn "Test3 n1 failed";
2231 }
2232 };
2233 if ($@) {
2234 $count++;
2235 warn "Test3 n1: $@";
2236 }
2237
2238 eval {
2239 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctdisk", 'test', 0)) {
2240 $count++;
2241 warn "Test3 o1 failed";
2242 }
2243 };
2244 if ($@) {
2245 $count++;
2246 warn "Test3 o1: $@";
2247 }
2248
2249 eval {
2250 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase", 'test', 0)) {
2251 $count++;
2252 warn "Test3 p1 failed";
2253 }
2254 };
2255 if ($@) {
2256 $count++;
2257 warn "Test3 p1: $@";
2258 }
2259
2260 eval {
2261 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2262 $count++;
2263 warn "Test3 q1 failed";
2264 }
2265 };
2266 if ($@) {
2267 $count++;
2268 warn "Test3 q1: $@";
2269 }
2270
2271 eval {
2272 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmdisk", 'test', 0)) {
2273 $count++;
2274 warn "Test3 r1 failed";
2275 }
2276 };
2277 if ($@) {
2278 $count++;
2279 warn "Test3 r1: $@";
2280 }
2281
2282 eval {
2283 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase", 'test', 0)) {
2284 $count++;
2285 warn "Test3 s1 failed";
2286 }
2287 };
2288 if ($@) {
2289 $count++;
2290 warn "Test3 s1: $@";
2291 }
2292
2293 eval {
2294 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2295 $count++;
2296 warn "Test3 t1 failed";
2297 }
2298 };
2299 if ($@) {
2300 $count++;
2301 warn "Test3 t1: $@";
2302 }
2303
2304 eval {
2305 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctdisk", 'test', 0)) {
2306 $count++;
2307 warn "Test3 u1 failed";
2308 }
2309 };
2310 if ($@) {
2311 $count++;
2312 warn "Test3 u1: $@";
2313 }
2314
2315 eval {
2316 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase", 'test', 0)) {
2317 $count++;
2318 warn "Test3 v1 failed";
2319 }
2320 };
2321 if ($@) {
2322 $count++;
2323 warn "Test3 v1: $@";
2324 }
2325
2326 eval {
2327 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2328 $count++;
2329 warn "Test3 w1 failed";
2330 }
2331 };
2332 if ($@) {
2333 $count++;
2334 warn "Test3 w1: $@";
2335 }
2336
2337 eval {
2338 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmdisk", 'test', 0)) {
2339 $count++;
2340 warn "Test3 x1 failed";
2341 }
2342 };
2343 if ($@) {
2344 $count++;
2345 warn "Test3 x1: $@";
2346 }
2347
2348 eval {
2349 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase", 'test', 0)) {
2350 $count++;
2351 warn "Test3 y1 failed";
2352 }
2353 };
2354 if ($@) {
2355 $count++;
2356 warn "Test3 y1: $@";
2357 }
2358
2359 eval {
2360 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2361 $count++;
2362 warn "Test3 z1 failed";
2363 }
2364 };
2365 if ($@) {
2366 $count++;
2367 warn "Test3 z1: $@";
2368 }
2369
2370 eval {
2371 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctdisk", 'test', 0)) {
2372 $count++;
2373 warn "Test3 A1 failed";
2374 }
2375 };
2376 if ($@) {
2377 $count++;
2378 warn "Test3 A1: $@";
2379 }
2380
2381 eval {
2382 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase", 'test', 0)) {
2383 $count++;
2384 warn "Test3 B1 failed";
2385 }
2386 };
2387 if ($@) {
2388 $count++;
2389 warn "Test3 B1: $@";
2390 }
2391
2392 eval {
2393 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2394 $count++;
2395 warn "Test3 C1 failed";
2396 }
2397 };
2398 if ($@) {
2399 $count++;
2400 warn "Test3 C1: $@";
2401 }
2402 };
2403 $tests->{3} = $test3;
2404
2405 my $test2 = sub {
2406
2407 print "\nrun test2 \"volume_resize\"\n";
2408 my $newsize = ($volsize + 1) * 1024 * 1024 * 1024;
2409
2410 eval {
2411 if (($newsize/1024) !=
2412 PVE::Storage::volume_resize($cfg, "$storagename:$vmdisk", $newsize, 0)) {
2413 $count++;
2414 warn "Test2 a failed";
2415 }
2416 if ($newsize !=
2417 PVE::Storage::volume_size_info($cfg, "$storagename:$vmdisk")) {
2418 $count++;
2419 warn "Test2 a failed";
2420 }
2421 };
2422 if ($@) {
2423 $count++;
2424 warn "Test2 a: $@";
2425 }
2426
2427 eval {
2428 warn "Test2 b failed" if ($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$vmbase", $newsize, 0);
2429 warn "Test2 b failed" if $newsize !=
2430 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase");
2431 };
2432 if ($@) {
2433 $count++;
2434 warn "Test2 b: $@";
2435 }
2436
2437 eval {
2438 if (($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$vmbase\/$vmlinked", $newsize, 0)) {
2439 $count++;
2440 warn "Test2 c failed";
2441 }
2442 if ($newsize !=
2443 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2444 $count++;
2445 warn "Test2 c failed";
2446 }
2447 };
2448 if ($@) {
2449 $count++;
2450 warn "Test2 c: $@";
2451 }
2452
2453 eval {
2454 if (($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$ctdisk", $newsize, 0)) {
2455 $count++;
2456 warn "Test2 d failed";
2457 }
2458 if ($newsize !=
2459 PVE::Storage::volume_size_info($cfg, "$storagename:$ctdisk")) {
2460 $count++;
2461 warn "Test2 d failed"
2462 }
2463 };
2464 if ($@) {
2465 $count++;
2466 warn "Test2 d: $@";
2467 }
2468
2469 eval {
2470 if (($newsize/1024) !=
2471 PVE::Storage::volume_resize($cfg, "$storagename:$ctbase", $newsize, 0)) {
2472 $count++;
2473 warn "Test2 e failed";
2474 }
2475 if ($newsize !=
2476 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase")) {
2477 $count++;
2478 warn "Test2 e failed";
2479 }
2480 };
2481 if ($@) {
2482 $count++;
2483 warn "Test2 e: $@";
2484 }
2485
2486 eval {
2487 if (($newsize/1024) !=
2488 PVE::Storage::volume_resize($cfg, "$storagename:$ctbase\/$ctlinked", $newsize, 0)) {
2489 $count++;
2490 warn "Test2 f failed";
2491 }
2492 if ($newsize !=
2493 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase\/$ctlinked")) {
2494 $count++;
2495 warn "Test2 f failed";
2496 }
2497 };
2498 if ($@) {
2499 $count++;
2500 warn "Test2 f: $@";
2501 }
2502 };
2503 $tests->{2} = $test2;
2504
2505 my $test1 = sub {
2506
2507 print "\nrun test1 \"volume_size_info\"\n";
2508 my $size = ($volsize * 1024 * 1024 * 1024);
2509
2510 eval {
2511 if ($size != PVE::Storage::volume_size_info($cfg, "$storagename:$vmdisk")) {
2512 $count++;
2513 warn "Test1 a failed";
2514 }
2515 };
2516 if ($@) {
2517 $count++;
2518 warn "Test1 a : $@";
2519 }
2520
2521 eval {
2522 if ($size != PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase")) {
2523 $count++;
2524 warn "Test1 b failed";
2525 }
2526
2527 };
2528 if ($@) {
2529 $count++;
2530 warn "Test1 b : $@";
2531 }
2532
2533 eval {
2534 if ($size !=
2535 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2536 $count++;
2537 warn "Test1 c failed";
2538 }
2539 };
2540 if ($@) {
2541 $count++;
2542 warn "Test1 c : $@";
2543 }
2544
2545 eval {
2546 if ($size !=
2547 PVE::Storage::volume_size_info($cfg, "$storagename:$ctdisk")) {
2548 $count++;
2549 warn "Test1 d failed";
2550 }
2551 };
2552 if ($@) {
2553 $count++;
2554 warn "Test1 d : $@";
2555 }
2556
2557 eval {
2558 if ($size !=
2559 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase")) {
2560 $count++;
2561 warn "Test1 e failed";
2562 }
2563 };
2564 if ($@) {
2565 $count++;
2566 warn "Test1 e : $@";
2567 }
2568
2569 eval {
2570 if ($size !=
2571 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2572 $count++;
2573 warn "Test1 f failed"
2574 }
2575 };
2576 if ($@) {
2577 $count++;
2578 warn "Test1 f : $@";
2579 }
2580
2581 };
2582 $tests->{1} = $test1;
2583
2584 sub setup_zfs {
2585
2586 #create VM zvol
2587 print "create zvol $vmdisk\n" if $verbose;
2588 run_command("zfs create -V${volsize}G $zpath\/$vmdisk");
2589
2590 print "create zvol $vmbase\n" if $verbose;
2591 run_command("zfs create -V${volsize}G $zpath\/$vmbase");
2592 run_command("zfs snapshot $zpath\/$vmbase$basesnap");
2593
2594 print "create linked clone $vmlinked\n" if $verbose;
2595 run_command("zfs clone $zpath\/$vmbase$basesnap $zpath\/$vmlinked");
2596
2597 #create CT subvol
2598 print "create subvol $ctdisk\n" if $verbose;
2599 run_command("zfs create -o refquota=${volsize}G $zpath\/$ctdisk");
2600
2601 print "create subvol $vmbase\n" if $verbose;
2602 run_command("zfs create -o refquota=${volsize}G $zpath\/$ctbase");
2603 run_command("zfs snapshot $zpath\/$ctbase$basesnap");
2604
2605 print "create linked clone $vmlinked\n" if $verbose;
2606 run_command("zfs clone $zpath\/$ctbase$basesnap $zpath\/$ctlinked -o refquota=${volsize}G");
2607 run_command("udevadm trigger --subsystem-match block");
2608 run_command("udevadm settle --timeout 10 --exit-if-exists=/dev/zvol/$zpath\/$ctlinked");
2609 }
2610
2611 sub cleanup_zfs {
2612
2613 print "destroy $pool\/$subvol\n" if $verbose;
2614 eval { run_command("zfs destroy $zpath -r"); };
2615 if ($@) {
2616 print "cleanup failed: $@\nretrying once\n" if $verbose;
2617 eval { run_command("zfs destroy $zpath -r"); };
2618 if ($@) {
2619 clean_up_zpool();
2620 setup_zpool();
2621 }
2622 }
2623 }
2624
2625 sub setup_zpool {
2626
2627 unlink 'zpool.img';
2628 eval {
2629 run_command("truncate -s 8G zpool.img");
2630 };
2631 if ($@) {
2632 clean_up_zpool();
2633 }
2634 my $pwd = cwd();
2635 eval {
2636 run_command("zpool create $subvol $pwd\/zpool.img");
2637 };
2638 if ($@) {
2639 clean_up_zpool();
2640 }
2641 }
2642
2643 sub clean_up_zpool {
2644
2645 eval {
2646 run_command("zpool destroy $subvol");
2647 };
2648 if ($@) {
2649 warn $@;}
2650 unlink 'zpool.img';
2651 }
2652
2653 sub volume_is_base {
2654 my ($cfg, $volid) = @_;
2655
2656 my (undef, undef, undef, undef, undef, $isBase, undef) = PVE::Storage::parse_volname($cfg, $volid);
2657
2658 return $isBase;
2659 }
2660
2661 eval { run_command("zpool status"); };
2662 if ($@) {
2663 warn "zpool status failed, not running tests: $@\n";
2664 exit 0;
2665 }
2666
2667 setup_zpool();
2668
2669 my $time = time;
2670 print "Start tests for ZFSPoolPlugin\n";
2671
2672 $cfg = {'ids' => {
2673 $storagename => {
2674 'content' => {
2675 'images' => 1,
2676 'rootdir' => 1
2677 },
2678 'pool' => $subvol,
2679 'type' => 'zfspool'
2680 },
2681 },
2682 'order' => {'zfstank99' => 1,}
2683 };
2684
2685 $zpath = $subvol;
2686
2687 for (my $i = $start_test; $i <= $end_test; $i++) {
2688 setup_zfs();
2689
2690 eval {
2691 $tests->{$i}();
2692 };
2693 warn $@ if $@;
2694 cleanup_zfs();
2695 }
2696
2697 clean_up_zpool();
2698
2699 $time = time - $time;
2700
2701 print "Stop tests for ZFSPoolPlugin\n";
2702 print "$count tests failed\n";
2703 print "Time: ${time}s\n";