[pve-devel] applied: [PATCH storage 2/2] fix tests when one has iscsi devices
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Mar 7 12:28:27 CET 2019
On 3/7/19 10:49 AM, Dominik Csapak wrote:
> 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
>
applied, but maybe it would additionally make sense to add some iSCSI
related tests ;-)
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> PVE/Diskmanage.pm | 12 +++++++++++-
> test/disklist_test.pm | 6 ++++++
> 2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
> index 66b264a..612bc3b 100644
> --- a/PVE/Diskmanage.pm
> +++ b/PVE/Diskmanage.pm
> @@ -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);
> diff --git a/test/disklist_test.pm b/test/disklist_test.pm
> index b2bde49..902563c 100644
> --- a/test/disklist_test.pm
> +++ b/test/disklist_test.pm
> @@ -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 {
>
More information about the pve-devel
mailing list