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