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