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