fix tests when one has iscsi devices

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>
This commit is contained in:
Dominik Csapak
2019-03-07 10:49:04 +01:00
committed by Thomas Lamprecht
parent 3add8714a9
commit eebcdb1119
2 changed files with 17 additions and 1 deletions

View 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);

View 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 {