]> git.proxmox.com Git - pve-storage.git/blob - src/test/run_test_zfspoolplugin.pl
separate packaging and source build system
[pve-storage.git] / src / 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
1366 my $blockers = [];
1367 my $res = PVE::Storage::volume_rollback_is_possible(
1368 $cfg,
1369 "$storagename:$vmdisk",
1370 'snap1',
1371 $blockers,
1372 );
1373 if ($res != 1) {
1374 $count++;
1375 warn "Test6 a: Rollback should be possible";
1376 }
1377 if (scalar($blockers->@*) != 0) {
1378 $count++;
1379 warn "Test6 a: 'blockers' should be empty";
1380 }
1381 };
1382 if ($@) {
1383 $count++;
1384 warn "Test6 a: $@";
1385 }
1386
1387 eval {
1388 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap1');
1389 if ( 1 !=
1390 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase", 'snap1')) {
1391 $count++;
1392 warn "Test6 b: Rollback should be possible";
1393 }
1394 };
1395 if ($@) {
1396 $count++;
1397 warn "Test6 b: $@";
1398 }
1399
1400 eval {
1401 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmlinked", 'snap1');
1402 if ( 1 !=
1403 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1')) {
1404 $count++;
1405 warn "Test6 c: Rollback should be possible";
1406 }
1407 };
1408 if ($@) {
1409 $count++;
1410 warn "Test6 c: $@";
1411 }
1412
1413 eval {
1414 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap1');
1415 if ( 1 !=
1416 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctdisk", 'snap1')) {
1417 $count++;
1418 warn "Test6 d: Rollback should be possible";
1419 }
1420 };
1421 if ($@) {
1422 $count++;
1423 warn "Test6 d: $@";
1424 }
1425
1426 eval {
1427 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap1');
1428 if ( 1 !=
1429 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase", 'snap1')) {
1430 $count++;
1431 warn "Test6 e: Rollback should be possible";
1432 }
1433 };
1434 if ($@) {
1435 $count++;
1436 warn "Test6 e: $@";
1437 }
1438
1439 eval {
1440 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctlinked", 'snap1');
1441 if ( 1 !=
1442 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase\/$ctlinked", 'snap1')) {
1443 $count++;
1444 warn "Test6 f: Rollback should be possible";
1445 }
1446 };
1447 if ($@) {
1448 $count++;
1449 warn "Test6 f: $@";
1450 }
1451
1452 my $blockers = [];
1453 eval {
1454 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap2');
1455 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmdisk", 'snap1', $blockers);
1456 };
1457 if (!$@) {
1458 $count++;
1459 warn "Test6 g: Rollback should not be possible";
1460 } elsif (scalar($blockers->@*) != 1 || $blockers->[0] ne 'snap2') {
1461 $count++;
1462 warn "Test6 g: 'blockers' should be ['snap2']";
1463 }
1464 undef $blockers;
1465
1466 $blockers = [];
1467 eval {
1468 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap2');
1469 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap3');
1470 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase", 'snap1', $blockers);
1471 };
1472 if (!$@) {
1473 $count++;
1474 warn "Test6 h: Rollback should not be possible";
1475 } else {
1476 if (scalar($blockers->@*) != 2) {
1477 $count++;
1478 warn "Test6 g: 'blockers' should contain two elements";
1479 }
1480 my $blockers_hash = { map { $_ => 1 } $blockers->@* };
1481 if (!$blockers_hash->{'snap2'}) {
1482 $count++;
1483 warn "Test6 g: 'blockers' should contain 'snap2'";
1484 }
1485 if (!$blockers_hash->{'snap3'}) {
1486 $count++;
1487 warn "Test6 g: 'blockers' should contain 'snap3'";
1488 }
1489 }
1490 undef $blockers;
1491
1492 eval {
1493 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmlinked", 'snap2');
1494 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$vmbase\/$vmlinked", 'snap1');
1495 };
1496 if (!$@) {
1497 $count++;
1498 warn "Test6 j: Rollback should not be possible";
1499 }
1500
1501 eval {
1502 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap2');
1503 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctdisk", 'snap1');
1504 };
1505 if (!$@) {
1506 $count++;
1507 warn "Test6 k: Rollback should not be possible";
1508 }
1509
1510 eval {
1511 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap2');
1512 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase", 'snap1');
1513 };
1514 if (!$@) {
1515 $count++;
1516 warn "Test6 l: Rollback should not be possible";
1517 }
1518
1519 eval {
1520 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctlinked", 'snap2');
1521 PVE::Storage::volume_rollback_is_possible($cfg, "$storagename:$ctbase\/$ctlinked", 'snap1');
1522 };
1523 if (!$@) {
1524 $count++;
1525 warn "Test6 m: Rollback should not be possible";
1526 }
1527 };
1528 $tests->{6} = $test6;
1529
1530 my $test5 = sub {
1531
1532 print "\nrun test5 \"volume_snapshot_delete\"\n";
1533 my $out = sub{my $tmp = shift;};
1534
1535 eval {
1536 run_command("zfs snapshot $zpath\/$vmdisk\@snap");
1537 eval{
1538 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmdisk", 'snap');
1539 eval{
1540 run_command("zfs list $zpath\/$vmdisk\@snap", errfunc => $out, outfunc => $out);
1541 };
1542 if (!$@) {
1543 $count++;
1544 warn "Test5 a: snapshot still exists";
1545 }
1546 };
1547 if ($@) {
1548 $count++;
1549 warn "Test5 PVE a: $@";
1550 }
1551 };
1552 if ($@) {
1553 $count++;
1554 warn "Test5 a: $@";
1555 }
1556
1557 eval {
1558 run_command("zfs snapshot $zpath\/$vmbase\@snap");
1559 eval{
1560 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase", 'snap');
1561 eval{
1562 run_command("zfs list $zpath\/$vmbase\@snap", errmsg => $out, outfunc => $out);
1563 };
1564 if (!$@) {
1565 $count++;
1566 warn "Test5 b: snapshot still exists";
1567 }
1568 };
1569 if ($@) {
1570 $count++;
1571 warn "Test5 PVE b: $@";
1572 }
1573 };
1574 if ($@) {
1575 $count++;
1576 warn "Test5 b: $@";
1577 }
1578
1579 eval {
1580 run_command("zfs snapshot $zpath\/$vmlinked\@snap");
1581 eval{
1582 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase\/$vmlinked", 'snap');
1583 eval{
1584 run_command("zfs list $zpath\/$vmlinked\@snap", errmsg => $out, outfunc => $out);
1585 };
1586 if (!$@) {
1587 $count++;
1588 warn "Test5 c: snapshot still exists";
1589 }
1590 };
1591 if ($@) {
1592 $count++;
1593 warn "Test5 PVE c: $@";
1594 }
1595 };
1596 if ($@) {
1597 $count++;
1598 warn "Test5 c: $@";
1599 }
1600
1601 eval {
1602 run_command("zfs snapshot $zpath\/$ctdisk\@snap");
1603 eval{
1604 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctdisk", 'snap');
1605 eval{
1606 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1607 };
1608 if (!$@) {
1609 $count++;
1610 warn "Test5 d: snapshot still exists";
1611 }
1612 };
1613 if ($@) {
1614 $count++;
1615 warn "Test5 PVE d: $@";
1616 }
1617 };
1618 if ($@) {
1619 $count++;
1620 warn "Test5 d: $@";
1621 }
1622
1623 eval {
1624 run_command("zfs snapshot $zpath\/$ctbase\@snap");
1625 eval{
1626 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctbase", 'snap');
1627 eval{
1628 run_command("zfs list $zpath\/$ctbase\@snap", errmsg => $out, outfunc => $out);
1629 };
1630 if (!$@) {
1631 $count++;
1632 warn "Test5 e: snapshot still exists";
1633 }
1634 };
1635 if ($@) {
1636 $count++;
1637 warn "Test5 PVE e: $@";
1638 }
1639 };
1640 if ($@) {
1641 $count++;
1642 warn "Test5 e: $@";
1643 }
1644
1645 eval {
1646 run_command("zfs snapshot $zpath\/$ctlinked\@snap");
1647 eval{
1648 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$ctbase\/$ctlinked", 'snap');
1649 eval{
1650 run_command("zfs list $zpath\/$ctlinked\@snap", errmsg => $out, outfunc => $out);
1651 };
1652 if (!$@) {
1653 $count++;
1654 warn "Test5 f: snapshot still exists";
1655 }
1656 };
1657 if ($@) {
1658 $count++;
1659 warn "Test5 PVE f: $@";
1660 }
1661 };
1662 if ($@) {
1663 $count++;
1664 warn "Test5 f: $@";
1665 }
1666 print "######Ignore Output if no Test5 g: is included######\n";
1667 eval{
1668 PVE::Storage::volume_snapshot_delete($cfg, "$storagename:$vmbase", '__base__');
1669 eval{
1670 run_command("zfs list $zpath\/$vmbase\@__base__", outfunc => $out);
1671 };
1672 if ($@) {
1673 $count++;
1674 warn "Test5 g: $@";
1675 }
1676 };
1677 if (!$@) {
1678 $count++;
1679 warn "Test5 PVE g: snapshot __base__ can be erased";
1680 }
1681 print "######End Ignore#######\n";
1682 };
1683 $tests->{5} = $test5;
1684
1685 my $test4 = sub {
1686
1687 print "\nrun test4 \"volume_snapshot\"\n";
1688 my $out = sub{};
1689
1690 eval {
1691 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmdisk", 'snap');
1692 eval{
1693 run_command("zfs list $zpath\/$vmdisk\@snap", errmsg => $out, outfunc => $out);
1694 };
1695 if ($@) {
1696 $count++;
1697 warn "Test4 a: $@";
1698 }
1699 };
1700 if ($@) {
1701 $count++;
1702 warn "Test4 a: $@";
1703 }
1704
1705 eval {
1706 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase", 'snap');
1707 eval{
1708 run_command("zfs list $zpath\/$vmbase\@snap", errmsg => $out, outfunc => $out);
1709 };
1710 if ($@) {
1711 $count++;
1712 warn "Test4 b: $@";
1713 }
1714 };
1715 if ($@) {
1716 $count++;
1717 warn "Test4 c: $@";
1718 }
1719
1720 eval {
1721 PVE::Storage::volume_snapshot($cfg, "$storagename:$vmbase\/$vmlinked", 'snap');
1722 eval{
1723 run_command("zfs list $zpath\/$vmdisk\@snap", errmsg => $out, outfunc => $out);
1724 };
1725 if ($@) {
1726 $count++;
1727 warn "Test4 c: $@";
1728 }
1729 };
1730 if ($@) {
1731 $count++;
1732 warn "Test4 c: $@";
1733 }
1734
1735 eval {
1736 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctdisk", 'snap');
1737 eval{
1738 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1739 };
1740 if ($@) {
1741 $count++;
1742 warn "Test4 d: $@";
1743 }
1744 };
1745 if ($@) {
1746 $count++;
1747 warn "Test4 d: $@";
1748 }
1749
1750 eval {
1751 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase", 'snap');
1752 eval{
1753 run_command("zfs list $zpath\/$ctbase\@snap", errmsg => $out, outfunc => $out);
1754 };
1755 if ($@) {
1756 $count++;
1757 warn "Test4 e: $@";
1758 }
1759 };
1760 if ($@) {
1761 $count++;
1762 warn "Test4 e: $@";
1763 }
1764
1765 eval {
1766 PVE::Storage::volume_snapshot($cfg, "$storagename:$ctbase\/$ctlinked", 'snap');
1767 eval{
1768 run_command("zfs list $zpath\/$ctdisk\@snap", errmsg => $out, outfunc => $out);
1769 };
1770 if ($@) {
1771 $count++;
1772 warn "Test4 f: $@";
1773 }
1774 };
1775 if ($@) {
1776 $count++;
1777 warn "Test4 f: $@";
1778 }
1779 };
1780 $tests->{4} = $test4;
1781
1782 my $test3 = sub {
1783
1784 print "\nrun test3 \"volume_has_feature\"\n";
1785
1786 eval {
1787 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmdisk", undef, 0)) {
1788 $count++;
1789 warn "Test3 a failed";
1790 }
1791 };
1792 if ($@) {
1793 $count++;
1794 warn "Test3 a: $@";
1795 }
1796
1797 eval {
1798 if (PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase", undef, 0)) {
1799 $count++;
1800 warn "Test3 b failed";
1801 }
1802 };
1803 if ($@) {
1804 $count++;
1805 warn "Test3 b: $@";
1806 }
1807
1808 eval {
1809 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1810 $count++;
1811 warn "Test3 c failed";
1812 }
1813 };
1814 if ($@) {
1815 $count++;
1816 warn "Test3 c: $@";
1817 }
1818
1819 eval {
1820 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctdisk", undef, 0)) {
1821 $count++;
1822 warn "Test3 d failed";
1823 }
1824 };
1825 if ($@) {
1826 $count++;
1827 warn "Test3 d: $@";
1828 }
1829
1830 eval {
1831 if (PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase", undef, 0)) {
1832 $count++;
1833 warn "Test3 e failed";
1834 }
1835 };
1836 if ($@) {
1837 $count++;
1838 warn "Test3 e: $@";
1839 }
1840
1841 eval {
1842 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1843 $count++;
1844 warn "Test3 f failed";
1845 }
1846 };
1847 if ($@) {
1848 $count++;
1849 warn "Test3 f: $@";
1850 }
1851
1852 eval {
1853 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmdisk", undef, 0)) {
1854 $count++;
1855 warn "Test3 g failed";
1856 }
1857 };
1858 if ($@) {
1859 $count++;
1860 warn "Test3 g: $@";
1861 }
1862
1863 eval {
1864 if (!PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase", undef, 0)) {
1865 $count++;
1866 warn "Test3 h failed";
1867 }
1868 };
1869 if ($@) {
1870 $count++;
1871 warn "Test3 h: $@";
1872 }
1873
1874 eval {
1875 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1876 $count++;
1877 warn "Test3 h failed";
1878 }
1879 };
1880 if ($@) {
1881 $count++;
1882 warn "Test3 h: $@";
1883 }
1884
1885 eval {
1886 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctdisk", undef, 0)) {
1887 $count++;
1888 warn "Test3 i failed";
1889 }
1890 };
1891 if ($@) {
1892 $count++;
1893 warn "Test3 i: $@";
1894 }
1895
1896 eval {
1897 if (!PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase", undef, 0)) {
1898 $count++;
1899 warn "Test3 j failed";
1900 }
1901 };
1902 if ($@) {
1903 $count++;
1904 warn "Test3 j: $@";
1905 }
1906
1907 eval {
1908 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1909 $count++;
1910 warn "Test3 k failed";
1911 }
1912 };
1913 if ($@) {
1914 $count++;
1915 warn "Test3 k: $@";
1916 }
1917
1918 eval {
1919 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmdisk", undef, 0)) {
1920 $count++;
1921 warn "Test3 l failed";
1922 }
1923 };
1924 if ($@) {
1925 $count++;
1926 warn "Test3 l: $@";
1927 }
1928
1929 eval {
1930 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase", undef, 0)) {
1931 $count++;
1932 warn "Test3 m failed";
1933 }
1934 };
1935 if ($@) {
1936 $count++;
1937 warn "Test3 m: $@";
1938 }
1939
1940 eval {
1941 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
1942 $count++;
1943 warn "Test3 n failed";
1944 }
1945 };
1946 if ($@) {
1947 $count++;
1948 warn "Test3 n: $@";
1949 }
1950
1951 eval {
1952 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctdisk", undef, 0)) {
1953 $count++;
1954 warn "Test3 o failed";
1955 }
1956 };
1957 if ($@) {
1958 $count++;
1959 warn "Test3 o: $@";
1960 }
1961
1962 eval {
1963 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase", undef, 0)) {
1964 $count++;
1965 warn "Test3 p failed";
1966 }
1967 };
1968 if ($@) {
1969 $count++;
1970 warn "Test3 p: $@";
1971 }
1972
1973 eval {
1974 if (!PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
1975 $count++;
1976 warn "Test3 q failed";
1977 }
1978 };
1979 if ($@) {
1980 $count++;
1981 warn "Test3 q: $@";
1982 }
1983
1984 eval {
1985 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmdisk", undef, 0)) {
1986 $count++;
1987 warn "Test3 r failed";
1988 }
1989 };
1990 if ($@) {
1991 $count++;
1992 warn "Test3 r: $@";
1993 }
1994
1995 eval {
1996 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase", undef, 0)) {
1997 $count++;
1998 warn "Test3 s failed";
1999 }
2000 };
2001 if ($@) {
2002 $count++;
2003 warn "Test3 s: $@";
2004 }
2005
2006 eval {
2007 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
2008 $count++;
2009 warn "Test3 t failed";
2010 }
2011 };
2012 if ($@) {
2013 $count++;
2014 warn "Test3 t: $@";
2015 }
2016
2017 eval {
2018 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctdisk", undef, 0)) {
2019 $count++;
2020 warn "Test3 u failed";
2021 }
2022 };
2023 if ($@) {
2024 $count++;
2025 warn "Test3 u: $@";
2026 }
2027
2028 eval {
2029 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase", undef, 0)) {
2030 $count++;
2031 warn "Test3 v failed";
2032 }
2033 };
2034 if ($@) {
2035 $count++;
2036 warn "Test3 v: $@";
2037 }
2038
2039 eval {
2040 if (!PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
2041 $count++;
2042 warn "Test3 w failed";
2043 }
2044 };
2045 if ($@) {
2046 $count++;
2047 warn "Test3 w: $@";
2048 }
2049
2050 eval {
2051 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmdisk", undef, 0)) {
2052 $count++;
2053 warn "Test3 x failed";
2054 }
2055 };
2056 if ($@) {
2057 $count++;
2058 warn "Test3 x: $@";
2059 }
2060
2061 eval {
2062 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase", undef, 0)) {
2063 $count++;
2064 warn "Test3 y failed";
2065 }
2066 };
2067 if ($@) {
2068 $count++;
2069 warn "Test3 y: $@";
2070 }
2071
2072 eval {
2073 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase\/$vmlinked", undef, 0)) {
2074 $count++;
2075 warn "Test3 z failed";
2076 }
2077 };
2078 if ($@) {
2079 $count++;
2080 warn "Test3 z: $@";
2081 }
2082
2083 eval {
2084 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctdisk", undef, 0)) {
2085 $count++;
2086 warn "Test3 A failed";
2087 }
2088 };
2089 if ($@) {
2090 $count++;
2091 warn "Test3 A: $@";
2092 }
2093
2094 eval {
2095 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase", undef, 0)) {
2096 $count++;
2097 warn "Test3 B failed";
2098 }
2099 };
2100 if ($@) {
2101 $count++;
2102 warn "Test3 B: $@";
2103 }
2104
2105 eval {
2106 if (!PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase\/$ctlinked", undef, 0)) {
2107 $count++;
2108 warn "Test3 C failed";
2109 }
2110 };
2111 if ($@) {
2112 $count++;
2113 warn "Test3 C: $@";
2114 }
2115
2116 eval {
2117 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmdisk", 'test', 0)) {
2118 $count++;
2119 warn "Test3 a1 failed";
2120 }
2121 };
2122 if ($@) {
2123 $count++;
2124 warn "Test3 a1: $@";
2125 }
2126
2127 eval {
2128 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase", 'test', 0)) {
2129 $count++;
2130 warn "Test3 b1 failed";
2131 }
2132 };
2133 if ($@) {
2134 $count++;
2135 warn "Test3 b1: $@";
2136 }
2137
2138 eval {
2139 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2140 $count++;
2141 warn "Test3 c1 failed";
2142 }
2143 };
2144 if ($@) {
2145 $count++;
2146 warn "Test3 c1: $@";
2147 }
2148
2149 eval {
2150 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctdisk", 'test', 0)) {
2151 $count++;
2152 warn "Test3 d1 failed";
2153 }
2154 };
2155 if ($@) {
2156 $count++;
2157 warn "Test3 d1: $@";
2158 }
2159
2160 eval {
2161 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase", 'test', 0)) {
2162 $count++;
2163 warn "Test3 e1 failed";
2164 }
2165 };
2166 if ($@) {
2167 $count++;
2168 warn "Test3 e1: $@";
2169 }
2170
2171 eval {
2172 if (!PVE::Storage::volume_has_feature($cfg, 'snapshot', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2173 $count++;
2174 warn "Test3 f1 failed";
2175 }
2176 };
2177 if ($@) {
2178 $count++;
2179 warn "Test3 f1: $@";
2180 }
2181
2182 eval {
2183 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmdisk", 'test', 0)) {
2184 $count++;
2185 warn "Test3 g1 failed";
2186 }
2187 };
2188 if ($@) {
2189 $count++;
2190 warn "Test3 g1: $@";
2191 }
2192
2193 eval {
2194 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase", 'test', 0)) {
2195 $count++;
2196 warn "Test3 h1 failed";
2197 }
2198 };
2199 if ($@) {
2200 $count++;
2201 warn "Test3 h1: $@";
2202 }
2203
2204 eval {
2205 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2206 $count++;
2207 warn "Test3 h1 failed";
2208 }
2209 };
2210 if ($@) {
2211 $count++;
2212 warn "Test3 h1: $@";
2213 }
2214
2215 eval {
2216 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctdisk", 'test', 0)) {
2217 $count++;
2218 warn "Test3 i1 failed";
2219 }
2220 };
2221 if ($@) {
2222 $count++;
2223 warn "Test3 i1: $@";
2224 }
2225
2226 eval {
2227 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase", 'test', 0)) {
2228 $count++;
2229 warn "Test3 j1 failed";
2230 }
2231 };
2232 if ($@) {
2233 $count++;
2234 warn "Test3 j1: $@";
2235 }
2236
2237 eval {
2238 if (PVE::Storage::volume_has_feature($cfg, 'clone', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2239 $count++;
2240 warn "Test3 k1 failed";
2241 }
2242 };
2243 if ($@) {
2244 $count++;
2245 warn "Test3 k1: $@";
2246 }
2247
2248 eval {
2249 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmdisk", 'test', 0)) {
2250 $count++;
2251 warn "Test3 l1 failed";
2252 }
2253 };
2254 if ($@) {
2255 $count++;
2256 warn "Test3 l1: $@";
2257 }
2258
2259 eval {
2260 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase", 'test', 0)) {
2261 $count++;
2262 warn "Test3 m1 failed";
2263 }
2264 };
2265 if ($@) {
2266 $count++;
2267 warn "Test3 m1: $@";
2268 }
2269
2270 eval {
2271 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2272 $count++;
2273 warn "Test3 n1 failed";
2274 }
2275 };
2276 if ($@) {
2277 $count++;
2278 warn "Test3 n1: $@";
2279 }
2280
2281 eval {
2282 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctdisk", 'test', 0)) {
2283 $count++;
2284 warn "Test3 o1 failed";
2285 }
2286 };
2287 if ($@) {
2288 $count++;
2289 warn "Test3 o1: $@";
2290 }
2291
2292 eval {
2293 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase", 'test', 0)) {
2294 $count++;
2295 warn "Test3 p1 failed";
2296 }
2297 };
2298 if ($@) {
2299 $count++;
2300 warn "Test3 p1: $@";
2301 }
2302
2303 eval {
2304 if (PVE::Storage::volume_has_feature($cfg, 'template', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2305 $count++;
2306 warn "Test3 q1 failed";
2307 }
2308 };
2309 if ($@) {
2310 $count++;
2311 warn "Test3 q1: $@";
2312 }
2313
2314 eval {
2315 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmdisk", 'test', 0)) {
2316 $count++;
2317 warn "Test3 r1 failed";
2318 }
2319 };
2320 if ($@) {
2321 $count++;
2322 warn "Test3 r1: $@";
2323 }
2324
2325 eval {
2326 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase", 'test', 0)) {
2327 $count++;
2328 warn "Test3 s1 failed";
2329 }
2330 };
2331 if ($@) {
2332 $count++;
2333 warn "Test3 s1: $@";
2334 }
2335
2336 eval {
2337 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2338 $count++;
2339 warn "Test3 t1 failed";
2340 }
2341 };
2342 if ($@) {
2343 $count++;
2344 warn "Test3 t1: $@";
2345 }
2346
2347 eval {
2348 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctdisk", 'test', 0)) {
2349 $count++;
2350 warn "Test3 u1 failed";
2351 }
2352 };
2353 if ($@) {
2354 $count++;
2355 warn "Test3 u1: $@";
2356 }
2357
2358 eval {
2359 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase", 'test', 0)) {
2360 $count++;
2361 warn "Test3 v1 failed";
2362 }
2363 };
2364 if ($@) {
2365 $count++;
2366 warn "Test3 v1: $@";
2367 }
2368
2369 eval {
2370 if (PVE::Storage::volume_has_feature($cfg, 'copy', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2371 $count++;
2372 warn "Test3 w1 failed";
2373 }
2374 };
2375 if ($@) {
2376 $count++;
2377 warn "Test3 w1: $@";
2378 }
2379
2380 eval {
2381 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmdisk", 'test', 0)) {
2382 $count++;
2383 warn "Test3 x1 failed";
2384 }
2385 };
2386 if ($@) {
2387 $count++;
2388 warn "Test3 x1: $@";
2389 }
2390
2391 eval {
2392 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase", 'test', 0)) {
2393 $count++;
2394 warn "Test3 y1 failed";
2395 }
2396 };
2397 if ($@) {
2398 $count++;
2399 warn "Test3 y1: $@";
2400 }
2401
2402 eval {
2403 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$vmbase\/$vmlinked", 'test', 0)) {
2404 $count++;
2405 warn "Test3 z1 failed";
2406 }
2407 };
2408 if ($@) {
2409 $count++;
2410 warn "Test3 z1: $@";
2411 }
2412
2413 eval {
2414 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctdisk", 'test', 0)) {
2415 $count++;
2416 warn "Test3 A1 failed";
2417 }
2418 };
2419 if ($@) {
2420 $count++;
2421 warn "Test3 A1: $@";
2422 }
2423
2424 eval {
2425 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase", 'test', 0)) {
2426 $count++;
2427 warn "Test3 B1 failed";
2428 }
2429 };
2430 if ($@) {
2431 $count++;
2432 warn "Test3 B1: $@";
2433 }
2434
2435 eval {
2436 if (PVE::Storage::volume_has_feature($cfg, 'sparseinit', "$storagename:$ctbase\/$ctlinked", 'test', 0)) {
2437 $count++;
2438 warn "Test3 C1 failed";
2439 }
2440 };
2441 if ($@) {
2442 $count++;
2443 warn "Test3 C1: $@";
2444 }
2445 };
2446 $tests->{3} = $test3;
2447
2448 my $test2 = sub {
2449
2450 print "\nrun test2 \"volume_resize\"\n";
2451 my $newsize = ($volsize + 1) * 1024 * 1024 * 1024;
2452
2453 eval {
2454 if (($newsize/1024) !=
2455 PVE::Storage::volume_resize($cfg, "$storagename:$vmdisk", $newsize, 0)) {
2456 $count++;
2457 warn "Test2 a failed";
2458 }
2459 if ($newsize !=
2460 PVE::Storage::volume_size_info($cfg, "$storagename:$vmdisk")) {
2461 $count++;
2462 warn "Test2 a failed";
2463 }
2464 };
2465 if ($@) {
2466 $count++;
2467 warn "Test2 a: $@";
2468 }
2469
2470 eval {
2471 warn "Test2 b failed" if ($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$vmbase", $newsize, 0);
2472 warn "Test2 b failed" if $newsize !=
2473 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase");
2474 };
2475 if ($@) {
2476 $count++;
2477 warn "Test2 b: $@";
2478 }
2479
2480 eval {
2481 if (($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$vmbase\/$vmlinked", $newsize, 0)) {
2482 $count++;
2483 warn "Test2 c failed";
2484 }
2485 if ($newsize !=
2486 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2487 $count++;
2488 warn "Test2 c failed";
2489 }
2490 };
2491 if ($@) {
2492 $count++;
2493 warn "Test2 c: $@";
2494 }
2495
2496 eval {
2497 if (($newsize/1024) != PVE::Storage::volume_resize($cfg, "$storagename:$ctdisk", $newsize, 0)) {
2498 $count++;
2499 warn "Test2 d failed";
2500 }
2501 if ($newsize !=
2502 PVE::Storage::volume_size_info($cfg, "$storagename:$ctdisk")) {
2503 $count++;
2504 warn "Test2 d failed"
2505 }
2506 };
2507 if ($@) {
2508 $count++;
2509 warn "Test2 d: $@";
2510 }
2511
2512 eval {
2513 if (($newsize/1024) !=
2514 PVE::Storage::volume_resize($cfg, "$storagename:$ctbase", $newsize, 0)) {
2515 $count++;
2516 warn "Test2 e failed";
2517 }
2518 if ($newsize !=
2519 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase")) {
2520 $count++;
2521 warn "Test2 e failed";
2522 }
2523 };
2524 if ($@) {
2525 $count++;
2526 warn "Test2 e: $@";
2527 }
2528
2529 eval {
2530 if (($newsize/1024) !=
2531 PVE::Storage::volume_resize($cfg, "$storagename:$ctbase\/$ctlinked", $newsize, 0)) {
2532 $count++;
2533 warn "Test2 f failed";
2534 }
2535 if ($newsize !=
2536 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase\/$ctlinked")) {
2537 $count++;
2538 warn "Test2 f failed";
2539 }
2540 };
2541 if ($@) {
2542 $count++;
2543 warn "Test2 f: $@";
2544 }
2545 };
2546 $tests->{2} = $test2;
2547
2548 my $test1 = sub {
2549
2550 print "\nrun test1 \"volume_size_info\"\n";
2551 my $size = ($volsize * 1024 * 1024 * 1024);
2552
2553 eval {
2554 if ($size != PVE::Storage::volume_size_info($cfg, "$storagename:$vmdisk")) {
2555 $count++;
2556 warn "Test1 a failed";
2557 }
2558 };
2559 if ($@) {
2560 $count++;
2561 warn "Test1 a : $@";
2562 }
2563
2564 eval {
2565 if ($size != PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase")) {
2566 $count++;
2567 warn "Test1 b failed";
2568 }
2569
2570 };
2571 if ($@) {
2572 $count++;
2573 warn "Test1 b : $@";
2574 }
2575
2576 eval {
2577 if ($size !=
2578 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2579 $count++;
2580 warn "Test1 c failed";
2581 }
2582 };
2583 if ($@) {
2584 $count++;
2585 warn "Test1 c : $@";
2586 }
2587
2588 eval {
2589 if ($size !=
2590 PVE::Storage::volume_size_info($cfg, "$storagename:$ctdisk")) {
2591 $count++;
2592 warn "Test1 d failed";
2593 }
2594 };
2595 if ($@) {
2596 $count++;
2597 warn "Test1 d : $@";
2598 }
2599
2600 eval {
2601 if ($size !=
2602 PVE::Storage::volume_size_info($cfg, "$storagename:$ctbase")) {
2603 $count++;
2604 warn "Test1 e failed";
2605 }
2606 };
2607 if ($@) {
2608 $count++;
2609 warn "Test1 e : $@";
2610 }
2611
2612 eval {
2613 if ($size !=
2614 PVE::Storage::volume_size_info($cfg, "$storagename:$vmbase\/$vmlinked")) {
2615 $count++;
2616 warn "Test1 f failed"
2617 }
2618 };
2619 if ($@) {
2620 $count++;
2621 warn "Test1 f : $@";
2622 }
2623
2624 };
2625 $tests->{1} = $test1;
2626
2627 sub setup_zfs {
2628 #create VM zvol
2629 print "create zvol $vmdisk\n" if $verbose;
2630 run_command("zfs create -V${volsize}G $zpath\/$vmdisk");
2631
2632 print "create zvol $vmbase\n" if $verbose;
2633 run_command("zfs create -V${volsize}G $zpath\/$vmbase");
2634 run_command("zfs snapshot $zpath\/$vmbase$basesnap");
2635
2636 print "create linked clone $vmlinked\n" if $verbose;
2637 run_command("zfs clone $zpath\/$vmbase$basesnap $zpath\/$vmlinked");
2638
2639 #create CT subvol
2640 print "create subvol $ctdisk\n" if $verbose;
2641 run_command("zfs create -o refquota=${volsize}G $zpath\/$ctdisk");
2642
2643 print "create subvol $ctbase\n" if $verbose;
2644 run_command("zfs create -o refquota=${volsize}G $zpath\/$ctbase");
2645 run_command("zfs snapshot $zpath\/$ctbase$basesnap");
2646
2647 print "create linked clone $ctlinked\n" if $verbose;
2648 run_command("zfs clone $zpath\/$ctbase$basesnap $zpath\/$ctlinked -o refquota=${volsize}G");
2649
2650 my $vollist = [
2651 "$storagename:$vmdisk",
2652 "$storagename:$vmbase",
2653 "$storagename:$vmbase/$vmlinked",
2654 "$storagename:$ctdisk",
2655 "$storagename:$ctbase",
2656 "$storagename:$ctbase/$ctlinked",
2657 ];
2658
2659 PVE::Storage::activate_volumes($cfg, $vollist);
2660 }
2661
2662 sub cleanup_zfs {
2663
2664 print "destroy $pool\/$subvol\n" if $verbose;
2665 eval { run_command("zfs destroy $zpath -r"); };
2666 if ($@) {
2667 print "cleanup failed: $@\nretrying once\n" if $verbose;
2668 eval { run_command("zfs destroy $zpath -r"); };
2669 if ($@) {
2670 clean_up_zpool();
2671 setup_zpool();
2672 }
2673 }
2674 }
2675
2676 sub setup_zpool {
2677
2678 unlink 'zpool.img';
2679 eval {
2680 run_command("truncate -s 8G zpool.img");
2681 };
2682 if ($@) {
2683 clean_up_zpool();
2684 }
2685 my $pwd = cwd();
2686 eval {
2687 run_command("zpool create -m \/$mountpoint $subvol $pwd\/zpool.img");
2688 };
2689 if ($@) {
2690 clean_up_zpool();
2691 }
2692 }
2693
2694 sub clean_up_zpool {
2695
2696 eval {
2697 run_command("zpool destroy -f $subvol");
2698 };
2699 if ($@) {
2700 warn $@;}
2701 unlink 'zpool.img';
2702 }
2703
2704 sub volume_is_base {
2705 my ($cfg, $volid) = @_;
2706
2707 my (undef, undef, undef, undef, undef, $isBase, undef) = PVE::Storage::parse_volname($cfg, $volid);
2708
2709 return $isBase;
2710 }
2711
2712 if ($> != 0) { #EUID
2713 warn "not root, skipping zfs tests\n";
2714 exit 0;
2715 }
2716
2717 eval { run_command("zpool status"); };
2718 if ($@) {
2719 warn "zpool status failed, not running tests: $@\n";
2720 exit 0;
2721 }
2722
2723 setup_zpool();
2724
2725 my $time = time;
2726 print "Start tests for ZFSPoolPlugin\n";
2727
2728 $cfg = {'ids' => {
2729 $storagename => {
2730 'content' => {
2731 'images' => 1,
2732 'rootdir' => 1
2733 },
2734 'pool' => $subvol,
2735 'mountpoint' => "\/$mountpoint",
2736 'type' => 'zfspool'
2737 },
2738 },
2739 'order' => {'zfstank99' => 1,}
2740 };
2741
2742 $zpath = $subvol;
2743
2744 for (my $i = $start_test; $i <= $end_test; $i++) {
2745 setup_zfs();
2746
2747 eval {
2748 $tests->{$i}();
2749 };
2750 if (my $err = $@) {
2751 warn $err;
2752 $count++;
2753 }
2754 cleanup_zfs();
2755 }
2756
2757 clean_up_zpool();
2758
2759 $time = time - $time;
2760
2761 print "Stop tests for ZFSPoolPlugin\n";
2762 print "$count tests failed\n";
2763 print "Time: ${time}s\n";
2764
2765 exit -1 if $count > 0;