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