From 481eeb6aacf3e8edec08d56b756b1fd26b7d8921 Mon Sep 17 00:00:00 2001 From: Eddie Pavkovic Date: Sun, 25 Feb 2024 13:54:35 -0500 Subject: [PATCH 1/3] [Issue #1096] - Fix lint error for bug atl-22498 Signed-off-by: Eddie Pavkovic --- pkg/base/linuxutils/lsblk/lsblk.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/base/linuxutils/lsblk/lsblk.go b/pkg/base/linuxutils/lsblk/lsblk.go index ac49f0b94..604a60d96 100644 --- a/pkg/base/linuxutils/lsblk/lsblk.go +++ b/pkg/base/linuxutils/lsblk/lsblk.go @@ -1,5 +1,5 @@ /* -Copyright © 2020 Dell Inc. or its subsidiaries. All Rights Reserved. +Copyright © 2020-2024 Dell Inc. or its subsidiaries. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -161,7 +161,6 @@ func (l *LSBLK) GetBlockDevices(device string) ([]BlockDevice, error) { // Receives an instance of drivecrd.Drive struct // Returns drive's path based on provided drivecrd.Drive or error if something went wrong func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) { - device := "" // try to find it with lsblk lsblkOut, err := l.GetBlockDevices("") From dfacddf6f890d054e7d66e2cd9f3410e938cf1af Mon Sep 17 00:00:00 2001 From: Eddie Pavkovic Date: Sun, 25 Feb 2024 22:54:44 -0500 Subject: [PATCH 2/3] [Issue #1096] - Put code back that returned device if path set - to fix unit test Signed-off-by: Eddie Pavkovic --- pkg/base/linuxutils/lsblk/lsblk.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/base/linuxutils/lsblk/lsblk.go b/pkg/base/linuxutils/lsblk/lsblk.go index 604a60d96..346710538 100644 --- a/pkg/base/linuxutils/lsblk/lsblk.go +++ b/pkg/base/linuxutils/lsblk/lsblk.go @@ -161,7 +161,13 @@ func (l *LSBLK) GetBlockDevices(device string) ([]BlockDevice, error) { // Receives an instance of drivecrd.Drive struct // Returns drive's path based on provided drivecrd.Drive or error if something went wrong func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) { - device := "" + // device path might be already set by hwmgr + device := drive.Path + if device != "" { + return device, nil + } + + device = "" // try to find it with lsblk lsblkOut, err := l.GetBlockDevices("") if err != nil { From c0a1c502cf2e2a3d469984d33dc051c3b9c51429 Mon Sep 17 00:00:00 2001 From: Eddie Pavkovic Date: Mon, 26 Feb 2024 00:17:46 -0500 Subject: [PATCH 3/3] [ISSUE-1096] - Put back code from previous PR and removed invalid test case Signed-off-by: Eddie Pavkovic --- pkg/base/linuxutils/lsblk/lsblk.go | 8 +------- pkg/base/linuxutils/lsblk/lsblk_test.go | 10 +--------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/pkg/base/linuxutils/lsblk/lsblk.go b/pkg/base/linuxutils/lsblk/lsblk.go index 346710538..604a60d96 100644 --- a/pkg/base/linuxutils/lsblk/lsblk.go +++ b/pkg/base/linuxutils/lsblk/lsblk.go @@ -161,13 +161,7 @@ func (l *LSBLK) GetBlockDevices(device string) ([]BlockDevice, error) { // Receives an instance of drivecrd.Drive struct // Returns drive's path based on provided drivecrd.Drive or error if something went wrong func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) { - // device path might be already set by hwmgr - device := drive.Path - if device != "" { - return device, nil - } - - device = "" + device := "" // try to find it with lsblk lsblkOut, err := l.GetBlockDevices("") if err != nil { diff --git a/pkg/base/linuxutils/lsblk/lsblk_test.go b/pkg/base/linuxutils/lsblk/lsblk_test.go index 8af5a93d9..71f191ca1 100644 --- a/pkg/base/linuxutils/lsblk/lsblk_test.go +++ b/pkg/base/linuxutils/lsblk/lsblk_test.go @@ -84,14 +84,6 @@ func TestLSBLK_SearchDrivePath_Success(t *testing.T) { e := &mocks.GoMockExecutor{} l := NewLSBLK(testLogger) l.e = e - // path is in drive spec - dCR := testDriveCR - path := "/dev/sda" - dCR.Spec.Path = path - - res, err := l.SearchDrivePath(&dCR.Spec) - assert.Nil(t, err) - assert.Equal(t, path, res) // got from lsblk output e.On("RunCmd", allDevicesCmd).Return(mocks.LsblkTwoDevicesStr, "", nil) @@ -100,7 +92,7 @@ func TestLSBLK_SearchDrivePath_Success(t *testing.T) { d2CR := testDriveCR d2CR.Spec.SerialNumber = sn - res, err = l.SearchDrivePath(&d2CR.Spec) + res, err := l.SearchDrivePath(&d2CR.Spec) assert.Nil(t, err) assert.Equal(t, expectedDevice, res) }