From 49e446254c717f4f46dc68afc0f99cc7d74b4db9 Mon Sep 17 00:00:00 2001 From: Valentin Daviot Date: Wed, 4 Mar 2026 17:01:23 +0100 Subject: [PATCH 1/3] commandrunners: add path parameter Signed-off-by: Valentin Daviot --- pkg/implementation/commandrunner/lsblk.go | 9 +++++++-- pkg/implementation/commandrunner/lsblk_test.go | 2 +- pkg/implementation/commandrunner/mdadm.go | 9 +++++++-- pkg/implementation/commandrunner/mdadm_test.go | 2 +- pkg/implementation/commandrunner/smartctl.go | 9 +++++++-- pkg/implementation/commandrunner/smartctl_test.go | 2 +- pkg/implementation/commandrunner/ssacli.go | 9 +++++++-- pkg/implementation/commandrunner/udevadm.go | 9 +++++++-- pkg/implementation/commandrunner/udevadm_test.go | 2 +- tests/integration/main.go | 8 ++++---- 10 files changed, 43 insertions(+), 18 deletions(-) diff --git a/pkg/implementation/commandrunner/lsblk.go b/pkg/implementation/commandrunner/lsblk.go index 9d9bc9b..cd64c41 100644 --- a/pkg/implementation/commandrunner/lsblk.go +++ b/pkg/implementation/commandrunner/lsblk.go @@ -18,9 +18,14 @@ var ( LSBLKExecCommand = exec.Command ) -func NewLSBLK() *LSBLK { +func NewLSBLK(path *string) *LSBLK { + cliPath := LSBLKBinaryPath + if path != nil { + cliPath = *path + } + return &LSBLK{ - cliPath: LSBLKBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/lsblk_test.go b/pkg/implementation/commandrunner/lsblk_test.go index af11da6..edbad5c 100644 --- a/pkg/implementation/commandrunner/lsblk_test.go +++ b/pkg/implementation/commandrunner/lsblk_test.go @@ -15,7 +15,7 @@ func TestMockLSBLKRun(t *testing.T) { commandrunner.LSBLKExecCommand = mockedExecCommand - runner := commandrunner.NewLSBLK() + runner := commandrunner.NewLSBLK(nil) // Run the function output, err := runner.Run([]string{"mocked lsblk command"}) diff --git a/pkg/implementation/commandrunner/mdadm.go b/pkg/implementation/commandrunner/mdadm.go index caf97a4..fbbcf85 100644 --- a/pkg/implementation/commandrunner/mdadm.go +++ b/pkg/implementation/commandrunner/mdadm.go @@ -18,9 +18,14 @@ var ( MDADMExecCommand = exec.Command ) -func NewMDADM() *MDADM { +func NewMDADM(path *string) *MDADM { + cliPath := MDADMBinaryPath + if path != nil { + cliPath = *path + } + return &MDADM{ - cliPath: MDADMBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/mdadm_test.go b/pkg/implementation/commandrunner/mdadm_test.go index fce7a0b..4e451e3 100644 --- a/pkg/implementation/commandrunner/mdadm_test.go +++ b/pkg/implementation/commandrunner/mdadm_test.go @@ -15,7 +15,7 @@ func TestMockMDADMRun(t *testing.T) { commandrunner.MDADMExecCommand = mockedExecCommand - runner := commandrunner.NewMDADM() + runner := commandrunner.NewMDADM(nil) // Run the function & assert the results output, err := runner.Run([]string{"mocked mdadm command"}) diff --git a/pkg/implementation/commandrunner/smartctl.go b/pkg/implementation/commandrunner/smartctl.go index a922709..ebd6d6b 100644 --- a/pkg/implementation/commandrunner/smartctl.go +++ b/pkg/implementation/commandrunner/smartctl.go @@ -19,9 +19,14 @@ var ( SmartCTLExecCommand = exec.Command ) -func NewSmartCTL() *SmartCTL { +func NewSmartCTL(path *string) *SmartCTL { + cliPath := SmartCTLBinaryPath + if path != nil { + cliPath = *path + } + return &SmartCTL{ - cliPath: SmartCTLBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/smartctl_test.go b/pkg/implementation/commandrunner/smartctl_test.go index 2c12c23..a23ab7a 100644 --- a/pkg/implementation/commandrunner/smartctl_test.go +++ b/pkg/implementation/commandrunner/smartctl_test.go @@ -15,7 +15,7 @@ func TestMockSmartCTLRun(t *testing.T) { commandrunner.SmartCTLExecCommand = mockedExecCommand - runner := commandrunner.NewSmartCTL() + runner := commandrunner.NewSmartCTL(nil) // Run the function output, err := runner.Run([]string{"mocked smartctl command"}) diff --git a/pkg/implementation/commandrunner/ssacli.go b/pkg/implementation/commandrunner/ssacli.go index 2be828f..037a950 100644 --- a/pkg/implementation/commandrunner/ssacli.go +++ b/pkg/implementation/commandrunner/ssacli.go @@ -19,9 +19,14 @@ var ( SSACLIExecCommand = exec.Command ) -func NewSSACLI() *SSACLI { +func NewSSACLI(path *string) *SSACLI { + cliPath := SSACLIPath + if path != nil { + cliPath = *path + } + return &SSACLI{ - cliPath: SSACLIPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/udevadm.go b/pkg/implementation/commandrunner/udevadm.go index 83e6e4f..fdf4271 100644 --- a/pkg/implementation/commandrunner/udevadm.go +++ b/pkg/implementation/commandrunner/udevadm.go @@ -20,9 +20,14 @@ var ( UDevADMExecCommand = exec.Command ) -func NewUDevADM() *UDevADM { +func NewUDevADM(path *string) *UDevADM { + cliPath := UDevADMBinaryPath + if path != nil { + cliPath = *path + } + return &UDevADM{ - cliPath: UDevADMBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/udevadm_test.go b/pkg/implementation/commandrunner/udevadm_test.go index dcacca7..0f26837 100644 --- a/pkg/implementation/commandrunner/udevadm_test.go +++ b/pkg/implementation/commandrunner/udevadm_test.go @@ -15,7 +15,7 @@ func TestMockUDevADMRun(t *testing.T) { commandrunner.UDevADMExecCommand = mockedExecCommand - runner := commandrunner.NewUDevADM() + runner := commandrunner.NewUDevADM(nil) // Run the function output, err := runner.Run([]string{"mocked udevadm command"}) diff --git a/tests/integration/main.go b/tests/integration/main.go index 4e46e07..e61404c 100644 --- a/tests/integration/main.go +++ b/tests/integration/main.go @@ -17,10 +17,10 @@ import ( func main() { logger := zerolog.New(os.Stdout).With().Str("test_type", "integration").Logger() - uDevADMCommandRunner := commandrunner.NewUDevADM() - lsblkCommandRunner := commandrunner.NewLSBLK() - smartCTLCommandRunner := commandrunner.NewSmartCTL() - mdadmCommandRunner := commandrunner.NewMDADM() + uDevADMCommandRunner := commandrunner.NewUDevADM(nil) + lsblkCommandRunner := commandrunner.NewLSBLK(nil) + smartCTLCommandRunner := commandrunner.NewSmartCTL(nil) + mdadmCommandRunner := commandrunner.NewMDADM(nil) physicalDriveGetter := physicaldrivegetter.NewRHEL8( uDevADMCommandRunner, From f5df247ca00476ffbcee30e9e3695591adf49607 Mon Sep 17 00:00:00 2001 From: Valentin Daviot Date: Thu, 5 Mar 2026 16:23:40 +0100 Subject: [PATCH 2/3] review: address comments Signed-off-by: Valentin Daviot --- pkg/implementation/commandrunner/lsblk.go | 2 +- pkg/implementation/commandrunner/mdadm.go | 2 +- pkg/implementation/commandrunner/smartctl.go | 2 +- pkg/implementation/commandrunner/ssacli.go | 2 +- pkg/implementation/commandrunner/udevadm.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/implementation/commandrunner/lsblk.go b/pkg/implementation/commandrunner/lsblk.go index cd64c41..c0b6623 100644 --- a/pkg/implementation/commandrunner/lsblk.go +++ b/pkg/implementation/commandrunner/lsblk.go @@ -20,7 +20,7 @@ var ( func NewLSBLK(path *string) *LSBLK { cliPath := LSBLKBinaryPath - if path != nil { + if path != nil && *path != "" { cliPath = *path } diff --git a/pkg/implementation/commandrunner/mdadm.go b/pkg/implementation/commandrunner/mdadm.go index fbbcf85..6290ed6 100644 --- a/pkg/implementation/commandrunner/mdadm.go +++ b/pkg/implementation/commandrunner/mdadm.go @@ -20,7 +20,7 @@ var ( func NewMDADM(path *string) *MDADM { cliPath := MDADMBinaryPath - if path != nil { + if path != nil && *path != "" { cliPath = *path } diff --git a/pkg/implementation/commandrunner/smartctl.go b/pkg/implementation/commandrunner/smartctl.go index ebd6d6b..494288c 100644 --- a/pkg/implementation/commandrunner/smartctl.go +++ b/pkg/implementation/commandrunner/smartctl.go @@ -21,7 +21,7 @@ var ( func NewSmartCTL(path *string) *SmartCTL { cliPath := SmartCTLBinaryPath - if path != nil { + if path != nil && *path != "" { cliPath = *path } diff --git a/pkg/implementation/commandrunner/ssacli.go b/pkg/implementation/commandrunner/ssacli.go index 037a950..89dcab2 100644 --- a/pkg/implementation/commandrunner/ssacli.go +++ b/pkg/implementation/commandrunner/ssacli.go @@ -21,7 +21,7 @@ var ( func NewSSACLI(path *string) *SSACLI { cliPath := SSACLIPath - if path != nil { + if path != nil && *path != "" { cliPath = *path } diff --git a/pkg/implementation/commandrunner/udevadm.go b/pkg/implementation/commandrunner/udevadm.go index fdf4271..4273ab3 100644 --- a/pkg/implementation/commandrunner/udevadm.go +++ b/pkg/implementation/commandrunner/udevadm.go @@ -22,7 +22,7 @@ var ( func NewUDevADM(path *string) *UDevADM { cliPath := UDevADMBinaryPath - if path != nil { + if path != nil && *path != "" { cliPath = *path } From 2ca660bea35e8415539be181794aa60e0d7d744d Mon Sep 17 00:00:00 2001 From: Valentin Daviot Date: Thu, 5 Mar 2026 16:37:06 +0100 Subject: [PATCH 3/3] commandrunners: add missing test for ssacli implementation Signed-off-by: Valentin Daviot --- .../commandrunner/ssacli_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pkg/implementation/commandrunner/ssacli_test.go diff --git a/pkg/implementation/commandrunner/ssacli_test.go b/pkg/implementation/commandrunner/ssacli_test.go new file mode 100644 index 0000000..278cec2 --- /dev/null +++ b/pkg/implementation/commandrunner/ssacli_test.go @@ -0,0 +1,22 @@ +package commandrunner_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/scality/raidmgmt/pkg/implementation/commandrunner" +) + +func TestMockSSACLIRun(t *testing.T) { + originalCommand := commandrunner.SSACLIExecCommand + defer func() { commandrunner.SSACLIExecCommand = originalCommand }() + + commandrunner.SSACLIExecCommand = mockedExecCommand + + runner := commandrunner.NewSSACLI(nil) + + output, err := runner.Run([]string{"mocked ssacli command"}) + assert.NoError(t, err) + assert.Contains(t, string(output), "PASS") +}