]> git.proxmox.com Git - pve-storage.git/blobdiff - test/disklist_test.pm
pbs: allow setting up a master key
[pve-storage.git] / test / disklist_test.pm
index b2bde4940c47851c17702707d102ceb380251e36..7f0e0be86e73ae8159c344eb60f1a587ca92acac 100644 (file)
@@ -52,9 +52,16 @@ sub mocked_run_command {
        } elsif ($cmd->[0] =~ m/pvs/i) {
            # simulate lvs output
            @$outputlines = split(/\n/, read_test_file('pvs'));
+       } elsif ($cmd->[0] =~ m/lvs/i) {
+           @$outputlines = split(/\n/, read_test_file('lvs'));
+       } elsif ($cmd->[0] =~ m/lsblk/i) {
+           my $content = read_test_file('lsblk');
+           if ($content eq '') {
+               $content = '{}';
+           }
+           @$outputlines = split(/\n/, $content);
        } else {
-           print "unexpected run_command call: '@$cmd', aborting\n";
-           die;
+           die "unexpected run_command call: '@$cmd', aborting\n";
        }
     } else {
        print "unexpected run_command call: '@$cmd', aborting\n";
@@ -80,6 +87,20 @@ sub mocked_get_sysdir_info {
     return &$originalsub($param);
 }
 
+sub mocked_get_sysdir_size {
+    my ($param) = @_;
+
+    my $originalsub = $diskmanage_module->original('get_sysdir_size');
+
+    $param =~ s|/sys/block|disk_tests/$testcasedir|;
+
+    return &$originalsub($param);
+}
+
+sub mocked_is_iscsi {
+    return 0;
+}
+
 sub mocked_dir_glob_foreach {
     my ($dir, $regex, $sub) = @_;
 
@@ -166,7 +187,29 @@ sub test_disk_list {
                $testcount++;
                ok(0,  "could not parse expected smart for '$disk'\n");
            }
+           my $disk_tmp = {};
+
+           # test single disk parameter
+           $disk_tmp = PVE::Diskmanage::get_disks($disk);
+           warn $@ if $@;
+           $testcount++;
+           print Dumper $disk_tmp if $print;
+           is_deeply($disk_tmp->{$disk}, $expected_disk_list->{$disk}, "disk $disk should be the same");
+
+
+           # test wrong parameter
+           eval {
+               PVE::Diskmanage::get_disks( { test => 1 } );
+           };
+           my $err = $@;
+           $testcount++;
+           is_deeply($err, "disks is not a string or array reference\n", "error message should be the same");
+
        }
+           # test multi disk parameter
+           $disks = PVE::Diskmanage::get_disks( [ keys %$disks ] );
+           $testcount++;
+           is_deeply($disks, $expected_disk_list, 'disk list should be the same');
 
        done_testing($testcount);
     };
@@ -186,6 +229,10 @@ $diskmanage_module->mock('dir_glob_foreach' => \&mocked_dir_glob_foreach);
 print("\tMocked dir_glob_foreach\n");
 $diskmanage_module->mock('get_sysdir_info' => \&mocked_get_sysdir_info);
 print("\tMocked get_sysdir_info\n");
+$diskmanage_module->mock('get_sysdir_size' => \&mocked_get_sysdir_size);
+print("\tMocked get_sysdir_size\n");
+$diskmanage_module->mock('is_iscsi' => \&mocked_is_iscsi);
+print("\tMocked is_iscsi\n");
 $diskmanage_module->mock('assert_blockdev' => sub { return 1; });
 print("\tMocked assert_blockdev\n");
 $diskmanage_module->mock('dir_is_empty' => sub {
@@ -197,6 +244,8 @@ $diskmanage_module->mock('dir_is_empty' => sub {
        return 1;
     });
 print("\tMocked dir_is_empty\n");
+$diskmanage_module->mock('check_bin' => sub { return 1; });
+print("\tMocked check_bin\n");
 my $tools_module= new Test::MockModule('PVE::ProcFSTools', no_auto => 1);
 $tools_module->mock('parse_proc_mounts' => \&mocked_parse_proc_mounts);
 print("\tMocked parse_proc_mounts\n");