]> git.proxmox.com Git - pve-storage.git/commitdiff
fix tests when one has iscsi devices
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 7 Mar 2019 09:49:04 +0000 (10:49 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 7 Mar 2019 10:08:43 +0000 (11:08 +0100)
the test would read the real device and if one is an iscsi device
it would fail, move the test code to a sub and mock it in the tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Diskmanage.pm
test/disklist_test.pm

index 66b264a3333c6d85cdc48531ae16c3aea417a073..612bc3b6be8e9b899cb338d4515690a809502540 100644 (file)
@@ -371,6 +371,16 @@ sub dir_is_empty {
     return 1;
 }
 
+sub is_iscsi {
+    my ($sysdir) = @_;
+
+    if (-l $sysdir && readlink($sysdir) =~ m|host[^/]*/session[^/]*|) {
+       return 1;
+    }
+
+    return 0;
+}
+
 sub get_disks {
     my ($disk, $nosmart) = @_;
     my $disklist = {};
@@ -421,7 +431,7 @@ sub get_disks {
        my $sysdir = "/sys/block/$dev";
 
        # we do not want iscsi devices
-       return if -l $sysdir && readlink($sysdir) =~ m|host[^/]*/session[^/]*|;
+       return if is_iscsi($sysdir);
 
        my $sysdata = get_sysdir_info($sysdir);
        return if !defined($sysdata);
index b2bde4940c47851c17702707d102ceb380251e36..902563c1f04634fa3118ca0e212ee21ddd1561b8 100644 (file)
@@ -80,6 +80,10 @@ sub mocked_get_sysdir_info {
     return &$originalsub($param);
 }
 
+sub mocked_is_iscsi {
+    return 0;
+}
+
 sub mocked_dir_glob_foreach {
     my ($dir, $regex, $sub) = @_;
 
@@ -186,6 +190,8 @@ $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('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 {