From dfa21aff4f4f309ec6a8949fddee1721e632be80 Mon Sep 17 00:00:00 2001 From: Aaron Brown <45407858+brownaaron@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:01:05 -0700 Subject: [PATCH] addition of rhcos to node prep for rosa support --- internal/nodeprep/instruction/instructions.go | 3 +- .../nodeprep/instruction/instructions_test.go | 8 +- internal/nodeprep/instruction/iscsi.go | 19 ++- .../nodeprep/mpathconfig/configuration.go | 12 +- .../mpathconfig/configuration_test.go | 31 +++- internal/nodeprep/mpathconfig/section_test.go | 72 ++++---- internal/nodeprep/nodeinfo/node_info.go | 1 + .../nodeprep/step/configure_multipathd.go | 11 +- .../step/configure_multipathd_rhcos.go | 64 +++++++ .../step/configure_multipathd_rhcos_test.go | 157 ++++++++++++++++++ .../step/configure_multipathd_test.go | 68 +++++++- .../{amzn/amzn.go => rhel/rhel.go} | 12 +- .../{amzn/amzn_test.go => rhel/rhel_test.go} | 58 +++---- 13 files changed, 416 insertions(+), 100 deletions(-) create mode 100644 internal/nodeprep/step/configure_multipathd_rhcos.go create mode 100644 internal/nodeprep/step/configure_multipathd_rhcos_test.go rename internal/nodeprep/systemmanager/{amzn/amzn.go => rhel/rhel.go} (79%) rename internal/nodeprep/systemmanager/{amzn/amzn_test.go => rhel/rhel_test.go} (75%) diff --git a/internal/nodeprep/instruction/instructions.go b/internal/nodeprep/instruction/instructions.go index 35c4768fc..5c85a2545 100644 --- a/internal/nodeprep/instruction/instructions.go +++ b/internal/nodeprep/instruction/instructions.go @@ -27,8 +27,9 @@ type Key struct { var instructionMap = map[Key]Instructions{} func init() { - instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = newAmznYumISCSI() + instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = newRHELYumISCSI() instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroUbuntu, PkgMgr: nodeinfo.PkgMgrApt}] = newDebianAptISCSI() + instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroRhcos, PkgMgr: nodeinfo.PkgMgrNone}] = newRHCOSISCSI() instructionMap[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrYum}] = newYumISCSI() instructionMap[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrApt}] = newAptISCSI() } diff --git a/internal/nodeprep/instruction/instructions_test.go b/internal/nodeprep/instruction/instructions_test.go index eba7c8ef9..28a568b9c 100644 --- a/internal/nodeprep/instruction/instructions_test.go +++ b/internal/nodeprep/instruction/instructions_test.go @@ -14,7 +14,7 @@ import ( ) func TestInstructions(t *testing.T) { - AmznYumISCSI := newAmznYumISCSI() + RHELYumISCSI := newRHELYumISCSI() DebianAptISCSI := newDebianAptISCSI() YumISCSI := newYumISCSI() AptISCSI := newAptISCSI() @@ -24,7 +24,7 @@ func TestInstructions(t *testing.T) { setDefaultInstructions := func() { scopedInstructions := map[Key]Instructions{} - scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = AmznYumISCSI + scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = RHELYumISCSI scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroUbuntu, PkgMgr: nodeinfo.PkgMgrApt}] = DebianAptISCSI scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrYum}] = YumISCSI scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrApt}] = AptISCSI @@ -98,7 +98,7 @@ func TestInstructions(t *testing.T) { HostSystem: amazonHostSystemResponse, Distro: nodeinfo.DistroAmzn, }, - expectedInstructions: []Instructions{AmznYumISCSI}, + expectedInstructions: []Instructions{RHELYumISCSI}, setInstructions: setDefaultInstructions, assertError: assert.NoError, }, @@ -118,7 +118,7 @@ func TestInstructions(t *testing.T) { HostSystem: fooHostSystemResponse, Distro: fooDistro, }, - expectedInstructions: []Instructions{AmznYumISCSI}, + expectedInstructions: []Instructions{RHELYumISCSI}, setInstructions: setDefaultInstructions, assertError: assert.NoError, }, diff --git a/internal/nodeprep/instruction/iscsi.go b/internal/nodeprep/instruction/iscsi.go index a31cfb56a..3823d8af2 100644 --- a/internal/nodeprep/instruction/iscsi.go +++ b/internal/nodeprep/instruction/iscsi.go @@ -8,8 +8,8 @@ import ( "github.com/netapp/trident/internal/nodeprep/packagemanager/yum" "github.com/netapp/trident/internal/nodeprep/step" "github.com/netapp/trident/internal/nodeprep/systemmanager" - "github.com/netapp/trident/internal/nodeprep/systemmanager/amzn" "github.com/netapp/trident/internal/nodeprep/systemmanager/debian" + "github.com/netapp/trident/internal/nodeprep/systemmanager/rhel" ) type ISCSI struct { @@ -20,12 +20,12 @@ func newDebianAptISCSI() (instruction Instructions) { return newISCSI(apt.New(), debian.New()) } -func newAmznYumISCSI() (instruction Instructions) { - return newISCSI(yum.New(), amzn.New()) +func newRHELYumISCSI() (instruction Instructions) { + return newISCSI(yum.New(), rhel.New()) } func newYumISCSI() (instruction Instructions) { - return newISCSI(yum.New(), amzn.New()) + return newISCSI(yum.New(), rhel.New()) } func newAptISCSI() (instruction Instructions) { @@ -43,3 +43,14 @@ func newISCSI(packageManager packagemanager.PackageManager, systemManager system } return } + +func newRHCOSISCSI() (instruction *ISCSI) { + instruction = &ISCSI{} + instruction.name = "RHCOS iscsi instructions" + // ordering of steps matter here, multipath must be configured before installing iscsi tools to be idempotent + instruction.steps = []step.Step{ + step.NewMultipathConfigureRHCOSStep(), + step.NewEnableIscsiServices(rhel.New()), + } + return +} diff --git a/internal/nodeprep/mpathconfig/configuration.go b/internal/nodeprep/mpathconfig/configuration.go index d7a3ff174..770316cfa 100644 --- a/internal/nodeprep/mpathconfig/configuration.go +++ b/internal/nodeprep/mpathconfig/configuration.go @@ -10,6 +10,7 @@ import ( "os" "github.com/hpe-storage/common-host-libs/mpathconfig" + "github.com/spf13/afero" . "github.com/netapp/trident/logging" "github.com/netapp/trident/utils/errors" @@ -30,6 +31,7 @@ var _ MpathConfiguration = &Configuration{} type Configuration struct { configuration *mpathconfig.Configuration + osFs afero.Afero } func (c *Configuration) GetRootSection() MpathConfigurationSection { @@ -56,7 +58,7 @@ func (c *Configuration) PrintConf() []string { } func (c *Configuration) SaveConfig(filePath string) error { - f, err := os.Create(filePath) + f, err := c.osFs.Create(filePath) if err != nil { return err } @@ -80,14 +82,14 @@ func (c *Configuration) SaveConfig(filePath string) error { return err } -func New() (MpathConfiguration, error) { - return NewFromFile(os.DevNull) +func New(osFs afero.Afero) (MpathConfiguration, error) { + return NewFromFile(osFs, os.DevNull) } -func NewFromFile(filename string) (MpathConfiguration, error) { +func NewFromFile(osFs afero.Afero, filename string) (MpathConfiguration, error) { mpathCfg, err := mpathconfig.ParseConfig(filename) if err != nil { return nil, fmt.Errorf("error creating mpath config: %v", err) } - return &Configuration{configuration: mpathCfg}, nil + return &Configuration{configuration: mpathCfg, osFs: osFs}, nil } diff --git a/internal/nodeprep/mpathconfig/configuration_test.go b/internal/nodeprep/mpathconfig/configuration_test.go index 172ebd80f..f96999394 100644 --- a/internal/nodeprep/mpathconfig/configuration_test.go +++ b/internal/nodeprep/mpathconfig/configuration_test.go @@ -6,13 +6,15 @@ import ( "os" "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/netapp/trident/internal/nodeprep/mpathconfig" ) func TestNew(t *testing.T) { - config, err := mpathconfig.New() + fs := afero.NewMemMapFs() + config, err := mpathconfig.New(afero.Afero{Fs: fs}) assert.Nil(t, err) assert.NotNil(t, config) assert.IsType(t, &mpathconfig.Configuration{}, config) @@ -38,9 +40,11 @@ func TestNewFromFile(t *testing.T) { }, } + fs := afero.NewMemMapFs() + for name, params := range tests { t.Run(name, func(t *testing.T) { - config, err := mpathconfig.NewFromFile(params.fileName) + config, err := mpathconfig.NewFromFile(afero.Afero{Fs: fs}, params.fileName) if params.assertError != nil { params.assertError(t, err) } @@ -52,7 +56,9 @@ func TestNewFromFile(t *testing.T) { } func TestConfiguration_GetRootSection(t *testing.T) { - config, err := mpathconfig.New() + fs := afero.NewMemMapFs() + + config, err := mpathconfig.New(afero.Afero{Fs: fs}) assert.Nil(t, err) assert.NotNil(t, config) @@ -62,6 +68,9 @@ func TestConfiguration_GetRootSection(t *testing.T) { } func TestConfiguration_GetSection(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getConfig func() mpathconfig.MpathConfiguration sectionName string @@ -80,7 +89,7 @@ func TestConfiguration_GetSection(t *testing.T) { }, "get default section from empty configuration": { getConfig: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.Nil(t, err) return config }, @@ -90,7 +99,7 @@ func TestConfiguration_GetSection(t *testing.T) { }, "get default section from configuration that has a default section": { getConfig: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.Nil(t, err) _, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) @@ -104,7 +113,7 @@ func TestConfiguration_GetSection(t *testing.T) { }, "get invalid section from configuration that has a default section": { getConfig: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.Nil(t, err) _, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) @@ -134,6 +143,9 @@ func TestConfiguration_GetSection(t *testing.T) { } func TestConfiguration_PrintConf(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getConfig func() mpathconfig.MpathConfiguration expectedOutput []string @@ -148,7 +160,7 @@ func TestConfiguration_PrintConf(t *testing.T) { }, "print empty configuration": { getConfig: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.Nil(t, err) return config }, @@ -156,7 +168,7 @@ func TestConfiguration_PrintConf(t *testing.T) { }, "print configuration with a default section": { getConfig: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.Nil(t, err) _, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) @@ -178,7 +190,8 @@ func TestConfiguration_PrintConf(t *testing.T) { } func TestConfiguration_SaveConfig(t *testing.T) { - config, err := mpathconfig.New() + fs := afero.NewMemMapFs() + config, err := mpathconfig.New(afero.Afero{Fs: fs}) assert.NoError(t, err) defaultSection, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) assert.NoError(t, err) diff --git a/internal/nodeprep/mpathconfig/section_test.go b/internal/nodeprep/mpathconfig/section_test.go index 221b64d7a..1c75bd91f 100644 --- a/internal/nodeprep/mpathconfig/section_test.go +++ b/internal/nodeprep/mpathconfig/section_test.go @@ -5,12 +5,16 @@ package mpathconfig_test import ( "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/netapp/trident/internal/nodeprep/mpathconfig" ) func TestSection_AddSection(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getParentSection func() mpathconfig.MpathConfigurationSection sectionName string @@ -21,7 +25,7 @@ func TestSection_AddSection(t *testing.T) { tests := map[string]parameters{ "Add defaults section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -31,7 +35,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add blacklist section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -41,7 +45,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add blacklist exceptions section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -51,7 +55,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add devices section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -61,7 +65,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add multipaths section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -71,7 +75,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add overrides section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -81,7 +85,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add device section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -91,7 +95,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add multipath section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -101,7 +105,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add foo section to root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -111,7 +115,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add section to defaults section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) defaultsSection, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) assert.NoError(t, err) @@ -123,7 +127,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add section to overrides section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) defaultsSection, err := config.GetRootSection().AddSection(mpathconfig.OverridesSectionName) assert.NoError(t, err) @@ -135,7 +139,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add device section to blacklist section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) defaultsSection, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -147,7 +151,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add foo section to blacklist section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSection, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -159,7 +163,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add device section to blacklist exception section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistExceptionSection, err := config.GetRootSection().AddSection(mpathconfig. BlacklistExceptionsSectionName) @@ -172,7 +176,7 @@ func TestSection_AddSection(t *testing.T) { }, "Add foo section to blacklist exception section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistExceptionSection, err := config.GetRootSection().AddSection(mpathconfig. BlacklistExceptionsSectionName) @@ -200,6 +204,9 @@ func TestSection_AddSection(t *testing.T) { } func TestSection_GetDeviceSection(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { GetParentSection func() mpathconfig.MpathConfigurationSection Vendor string @@ -222,7 +229,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from root section": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -234,7 +241,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from empty section": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSectionName, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -248,7 +255,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from section that has a device section": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSectionName, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -267,7 +274,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from section that has a device section with different vendor": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSectionName, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -286,7 +293,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from section that has a device section with different product": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSectionName, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -305,7 +312,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from section that has a device section with different revision": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSectionName, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) assert.NoError(t, err) @@ -324,7 +331,7 @@ func TestSection_GetDeviceSection(t *testing.T) { }, "Get device section from section that has a multiple sections": { GetParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) blacklistSection, err := config.GetRootSection().AddSection(mpathconfig.BlacklistSectionName) @@ -364,6 +371,9 @@ func TestSection_GetDeviceSection(t *testing.T) { } func TestSection_HasProperty(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getParentSection func() mpathconfig.MpathConfigurationSection property string @@ -380,7 +390,7 @@ func TestSection_HasProperty(t *testing.T) { }, "Check if property exists in empty section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -389,7 +399,7 @@ func TestSection_HasProperty(t *testing.T) { }, "Check if property exists in section that has the property": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) section, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) assert.NoError(t, err) @@ -412,6 +422,9 @@ func TestSection_HasProperty(t *testing.T) { } func TestSection_GetProperty(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getParentSection func() mpathconfig.MpathConfigurationSection property string @@ -430,7 +443,7 @@ func TestSection_GetProperty(t *testing.T) { }, "Get property from empty section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -439,7 +452,7 @@ func TestSection_GetProperty(t *testing.T) { }, "Get property from section that has the property": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) section, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) assert.NoError(t, err) @@ -468,6 +481,9 @@ func TestSection_GetProperty(t *testing.T) { } func TestSection_SetProperty(t *testing.T) { + fs := afero.NewMemMapFs() + os := afero.Afero{Fs: fs} + type parameters struct { getParentSection func() mpathconfig.MpathConfigurationSection property string @@ -486,7 +502,7 @@ func TestSection_SetProperty(t *testing.T) { }, "Set property in root section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) return config.GetRootSection() }, @@ -496,7 +512,7 @@ func TestSection_SetProperty(t *testing.T) { }, "Set property in defaults section": { getParentSection: func() mpathconfig.MpathConfigurationSection { - config, err := mpathconfig.New() + config, err := mpathconfig.New(os) assert.NoError(t, err) defaultsSection, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName) assert.NoError(t, err) diff --git a/internal/nodeprep/nodeinfo/node_info.go b/internal/nodeprep/nodeinfo/node_info.go index 4a6544a62..358c43bb5 100644 --- a/internal/nodeprep/nodeinfo/node_info.go +++ b/internal/nodeprep/nodeinfo/node_info.go @@ -27,6 +27,7 @@ type ( const ( DistroUbuntu Distro = utils.Ubuntu DistroAmzn Distro = "amzn" + DistroRhcos Distro = "rhcos" DistroUnknown = "unknown" PkgMgrYum PkgMgr = "yum" diff --git a/internal/nodeprep/step/configure_multipathd.go b/internal/nodeprep/step/configure_multipathd.go index d8a5bf4dd..038a3fa2f 100644 --- a/internal/nodeprep/step/configure_multipathd.go +++ b/internal/nodeprep/step/configure_multipathd.go @@ -14,8 +14,8 @@ import ( ) type ( - NewConfiguration func() (mpathconfig.MpathConfiguration, error) - NewConfigurationFromFile func(filename string) (mpathconfig.MpathConfiguration, error) + NewConfiguration func(os afero.Afero) (mpathconfig.MpathConfiguration, error) + NewConfigurationFromFile func(os afero.Afero, filename string) (mpathconfig.MpathConfiguration, error) ) type MultipathConfigureStep struct { @@ -54,14 +54,15 @@ func NewMultipathConfigureStepDetailed(multipathConfigurationLocation string, ne func (c *MultipathConfigureStep) Apply(ctx context.Context) error { var mpathCfg mpathconfig.MpathConfiguration var err error - if c.packageManager.MultipathToolsInstalled(ctx) { + + if c.packageManager != nil && c.packageManager.MultipathToolsInstalled(ctx) { if !c.multipathConfigurationExists() { return fmt.Errorf("found multipath tools already installed but no configuration file found; customer" + " using multipathd with default configuration") } - mpathCfg, err = c.newConfigurationFromFile(c.multipathConfigurationLocation) + mpathCfg, err = c.newConfigurationFromFile(c.os, c.multipathConfigurationLocation) if err != nil { return err } @@ -71,7 +72,7 @@ func (c *MultipathConfigureStep) Apply(ctx context.Context) error { } } else { - mpathCfg, err = c.newConfiguration() + mpathCfg, err = c.newConfiguration(c.os) if err != nil { return err } diff --git a/internal/nodeprep/step/configure_multipathd_rhcos.go b/internal/nodeprep/step/configure_multipathd_rhcos.go new file mode 100644 index 000000000..bfd6c32f7 --- /dev/null +++ b/internal/nodeprep/step/configure_multipathd_rhcos.go @@ -0,0 +1,64 @@ +// Copyright 2024 NetApp, Inc. All Rights Reserved. + +package step + +import ( + "context" + + "github.com/spf13/afero" + + "github.com/netapp/trident/internal/nodeprep/mpathconfig" +) + +type MultipathConfigureRHCOSStep struct { + MultipathConfigureStep +} + +func NewMultipathConfigureRHCOSStep() *MultipathConfigureRHCOSStep { + return NewMultipathConfigureRHCOSStepDetailed( + mpathconfig.MultiPathConfigurationLocation, + mpathconfig.NewFromFile, + mpathconfig.New, + afero.Afero{Fs: afero.NewOsFs()}) +} + +func NewMultipathConfigureRHCOSStepDetailed(multipathConfigurationLocation string, newConfigurationFromFile NewConfigurationFromFile, + newConfiguration NewConfiguration, os afero.Afero, +) *MultipathConfigureRHCOSStep { + multipathConfigurationStep := &MultipathConfigureRHCOSStep{ + MultipathConfigureStep: *NewMultipathConfigureStepDetailed( + multipathConfigurationLocation, + newConfigurationFromFile, + newConfiguration, + nil, + os), + } + + return multipathConfigurationStep +} + +func (c *MultipathConfigureRHCOSStep) Apply(ctx context.Context) error { + var mpathCfg mpathconfig.MpathConfiguration + var err error + if c.multipathConfigurationExists() { + mpathCfg, err = c.newConfigurationFromFile(c.os, c.multipathConfigurationLocation) + if err != nil { + return err + } + + if err = c.UpdateConfiguration(mpathCfg); err != nil { + return err + } + } else { + mpathCfg, err = c.newConfiguration(c.os) + if err != nil { + return err + } + + if err = c.AddConfiguration(mpathCfg); err != nil { + return err + } + } + + return mpathCfg.SaveConfig(c.multipathConfigurationLocation) +} diff --git a/internal/nodeprep/step/configure_multipathd_rhcos_test.go b/internal/nodeprep/step/configure_multipathd_rhcos_test.go new file mode 100644 index 000000000..46a4224b2 --- /dev/null +++ b/internal/nodeprep/step/configure_multipathd_rhcos_test.go @@ -0,0 +1,157 @@ +// Copyright 2024 NetApp, Inc. All Rights Reserved. + +package step_test + +import ( + "context" + "os" + "testing" + + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + + "github.com/netapp/trident/config" + "github.com/netapp/trident/internal/nodeprep/mpathconfig" + "github.com/netapp/trident/internal/nodeprep/step" + "github.com/netapp/trident/mocks/mock_internal/mock_nodeprep/mock_mpathconfig" + "github.com/netapp/trident/utils/errors" +) + +func TestNewMultipathConfigureRHCOSStep(t *testing.T) { + assert.NotNil(t, step.NewMultipathConfigureRHCOSStep()) +} + +func TestNewMultipathConfigureStepRHCOSDetailed(t *testing.T) { + type parameters struct { + getFileSystem func() afero.Fs + } + + tests := map[string]parameters{ + "running outside the container": { + getFileSystem: func() afero.Fs { + return afero.NewMemMapFs() + }, + }, + "running inside the container": { + getFileSystem: func() afero.Fs { + fs := afero.NewMemMapFs() + _, err := fs.Create(config.NamespaceFile) + assert.NoError(t, err) + return fs + }, + }, + } + + for name, params := range tests { + t.Run(name, func(t *testing.T) { + mpathConfigStep := step.NewMultipathConfigureRHCOSStepDetailed(mpathconfig.MultiPathConfigurationLocation, nil, nil, + afero.Afero{Fs: params.getFileSystem()}) + assert.NotNil(t, mpathConfigStep) + }) + } +} + +func TestMultipathConfigureRHCOSStep_Apply(t *testing.T) { + fs := afero.NewMemMapFs() + osFs := afero.Afero{Fs: fs} + + type parameters struct { + mpathConfigLocation string + getMpathConfiguration func() mpathconfig.MpathConfiguration + configConstructorError error + assertError assert.ErrorAssertionFunc + } + + ctx := context.Background() + + tests := map[string]parameters{ + "multipath rhcos tools already installed and configuration file exists ": { + mpathConfigLocation: os.DevNull, + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mpathConfig, err := mpathconfig.New(osFs) + assert.NoError(t, err) + return mpathConfig + }, + assertError: assert.NoError, + }, + "multipath rhcos tools already installed and configuration file does not exist": { + mpathConfigLocation: os.DevNull, + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mpathConfig, err := mpathconfig.New(osFs) + assert.NoError(t, err) + return mpathConfig + }, + assertError: assert.NoError, + }, + "multipath rhcos tools installed and configuration exists: error getting config": { + mpathConfigLocation: os.DevNull, + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mpathConfig, err := mpathconfig.New(osFs) + assert.NoError(t, err) + return mpathConfig + }, + configConstructorError: errors.New("some error"), + assertError: assert.Error, + }, + "multipath rhcos tools installed and configuration exists: error updating config": { + mpathConfigLocation: os.DevNull, + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mockCtrl := gomock.NewController(t) + + section := mock_mpathconfig.NewMockMpathConfigurationSection(mockCtrl) + section.EXPECT().HasProperty("find_multipaths").Return(true) + section.EXPECT().GetProperty("find_multipaths").Return("", errors.New("some error")) + + mpathConfig := mock_mpathconfig.NewMockMpathConfiguration(mockCtrl) + mpathConfig.EXPECT().GetSection(mpathconfig.DefaultsSectionName).Return(section, nil) + return mpathConfig + }, + assertError: assert.Error, + }, + "multipath rhcos tools config does not exist: error adding config": { + mpathConfigLocation: "9d0010ae-479a-49c3-9460-16726606b458.conf", + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mockCtrl := gomock.NewController(t) + + section := mock_mpathconfig.NewMockMpathConfigurationSection(mockCtrl) + section.EXPECT().AddSection(mpathconfig.DefaultsSectionName).Return(nil, errors.New("some error")) + + mpathConfig := mock_mpathconfig.NewMockMpathConfiguration(mockCtrl) + mpathConfig.EXPECT().GetRootSection().Return(section) + return mpathConfig + }, + assertError: assert.Error, + }, + "multipath rhcos tools config does not exist: error constructing config": { + mpathConfigLocation: "9d0010ae-479a-49c3-9460-16726606b458.conf", + getMpathConfiguration: func() mpathconfig.MpathConfiguration { + mockCtrl := gomock.NewController(t) + mpathConfig := mock_mpathconfig.NewMockMpathConfiguration(mockCtrl) + return mpathConfig + }, + configConstructorError: errors.New("some error"), + assertError: assert.Error, + }, + } + + for name, params := range tests { + t.Run(name, func(t *testing.T) { + configConstructors := mockMpathConfigConstructor{ + config: params.getMpathConfiguration(), + err: params.configConstructorError, + } + + _, err := fs.Create(os.DevNull) + assert.NoError(t, err) + configurator := step.NewMultipathConfigureRHCOSStepDetailed(params.mpathConfigLocation, + configConstructors.NewFromFile, configConstructors.New, + osFs) + + err = configurator.Apply(ctx) + if params.assertError != nil { + params.assertError(t, err) + } + }) + } +} diff --git a/internal/nodeprep/step/configure_multipathd_test.go b/internal/nodeprep/step/configure_multipathd_test.go index eacd80af3..6f7684c2e 100644 --- a/internal/nodeprep/step/configure_multipathd_test.go +++ b/internal/nodeprep/step/configure_multipathd_test.go @@ -92,6 +92,34 @@ func TestMultipathConfigureStep_AddConfiguration(t *testing.T) { }, assertError: assert.NoError, }, + "happy path no package manager": { + getConfiguration: func() mpathconfig.MpathConfiguration { + mockCtrl := gomock.NewController(t) + section := mock_mpathconfig.NewMockMpathConfigurationSection(mockCtrl) + + section.EXPECT().AddSection(mpathconfig.DefaultsSectionName).Return(section, nil) + section.EXPECT().SetProperty("find_multipaths", "no").Return(nil) + + section.EXPECT().AddSection(mpathconfig.BlacklistSectionName).Return(section, nil) + section.EXPECT().AddSection(mpathconfig.DeviceSectionName).Return(section, nil) + section.EXPECT().SetProperty("vendor", ".*").Return(nil) + section.EXPECT().SetProperty("product", ".*").Return(nil) + + section.EXPECT().AddSection(mpathconfig.BlacklistExceptionsSectionName).Return(section, nil) + section.EXPECT().AddSection(mpathconfig.DeviceSectionName).Return(section, nil) + section.EXPECT().SetProperty("vendor", "NETAPP").Return(nil) + section.EXPECT().SetProperty("product", "LUN").Return(nil) + + mpathConfig := mock_mpathconfig.NewMockMpathConfiguration(mockCtrl) + mpathConfig.EXPECT().GetRootSection().Return(section).Times(3) + + return mpathConfig + }, + getPackageManager: func() packagemanager.PackageManager { + return nil + }, + assertError: assert.NoError, + }, "default section creation returns an error": { getConfiguration: func() mpathconfig.MpathConfiguration { mockCtrl := gomock.NewController(t) @@ -383,6 +411,26 @@ func TestMultipathConfigureStep_UpdateConfiguration(t *testing.T) { }, assertError: assert.NoError, }, + "required configuration is already present and no package manager": { + getConfiguration: func() mpathconfig.MpathConfiguration { + mockCtrl := gomock.NewController(t) + section := mock_mpathconfig.NewMockMpathConfigurationSection(mockCtrl) + section.EXPECT().HasProperty("find_multipaths").Return(true) + section.EXPECT().GetProperty("find_multipaths").Return("no", nil) + + section.EXPECT().GetDeviceSection("NETAPP", "LUN", "").Return(section, nil) + + mpathConfig := mock_mpathconfig.NewMockMpathConfiguration(mockCtrl) + mpathConfig.EXPECT().GetSection(mpathconfig.DefaultsSectionName).Return(section, nil) + mpathConfig.EXPECT().GetSection(mpathconfig.BlacklistExceptionsSectionName).Return(section, nil) + + return mpathConfig + }, + getPackageManager: func() packagemanager.PackageManager { + return nil + }, + assertError: assert.NoError, + }, "get property 'find_multipaths' from the defaults section returns an error": { getConfiguration: func() mpathconfig.MpathConfiguration { mockCtrl := gomock.NewController(t) @@ -667,6 +715,9 @@ func TestMultipathConfigureStep_UpdateConfiguration(t *testing.T) { } func TestMultipathConfigureStep_Apply(t *testing.T) { + fs := afero.NewMemMapFs() + osFs := afero.Afero{Fs: fs} + type parameters struct { mpathConfigLocation string getMpathConfiguration func() mpathconfig.MpathConfiguration @@ -681,7 +732,7 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { "multipath tools already installed and configuration file exists": { mpathConfigLocation: os.DevNull, getMpathConfiguration: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(osFs) assert.NoError(t, err) return config }, @@ -696,7 +747,7 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { "multipath tools installed and configuration exists: error getting config": { mpathConfigLocation: os.DevNull, getMpathConfiguration: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(osFs) assert.NoError(t, err) return config }, @@ -733,7 +784,7 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { "multipath tools already installed and configuration does not exist": { mpathConfigLocation: "9d0010ae-479a-49c3-9460-16726606b458.conf", getMpathConfiguration: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(osFs) assert.NoError(t, err) return config }, @@ -748,7 +799,7 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { "multipath tools does not exist": { mpathConfigLocation: os.DevNull, getMpathConfiguration: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(osFs) assert.NoError(t, err) return config }, @@ -763,7 +814,7 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { "multipath tools does not exist: error getting config": { mpathConfigLocation: os.DevNull, getMpathConfiguration: func() mpathconfig.MpathConfiguration { - config, err := mpathconfig.New() + config, err := mpathconfig.New(osFs) assert.NoError(t, err) return config }, @@ -805,12 +856,11 @@ func TestMultipathConfigureStep_Apply(t *testing.T) { err: params.configConstructorError, } - fs := afero.NewMemMapFs() _, err := fs.Create(os.DevNull) assert.NoError(t, err) configurator := step.NewMultipathConfigureStepDetailed(params.mpathConfigLocation, configConstructors.NewFromFile, configConstructors.New, params.getPackageManager(), - afero.Afero{Fs: fs}) + osFs) err = configurator.Apply(ctx) if params.assertError != nil { @@ -826,10 +876,10 @@ type mockMpathConfigConstructor struct { err error } -func (m *mockMpathConfigConstructor) New() (mpathconfig.MpathConfiguration, error) { +func (m *mockMpathConfigConstructor) New(_ afero.Afero) (mpathconfig.MpathConfiguration, error) { return m.config, m.err } -func (m *mockMpathConfigConstructor) NewFromFile(_ string) (mpathconfig.MpathConfiguration, error) { +func (m *mockMpathConfigConstructor) NewFromFile(_ afero.Afero, _ string) (mpathconfig.MpathConfiguration, error) { return m.config, m.err } diff --git a/internal/nodeprep/systemmanager/amzn/amzn.go b/internal/nodeprep/systemmanager/rhel/rhel.go similarity index 79% rename from internal/nodeprep/systemmanager/amzn/amzn.go rename to internal/nodeprep/systemmanager/rhel/rhel.go index 42d5af67c..55e87f67c 100644 --- a/internal/nodeprep/systemmanager/amzn/amzn.go +++ b/internal/nodeprep/systemmanager/rhel/rhel.go @@ -1,6 +1,6 @@ // Copyright 2024 NetApp, Inc. All Rights Reserved. -package amzn +package rhel import ( "context" @@ -20,21 +20,21 @@ const ( defaultLogCommandOutput = true ) -type Amzn struct { +type RHEL struct { *systemctl.Systemctl } -func New() *Amzn { +func New() *RHEL { return NewDetailed(systemctl.NewSystemctlDetailed(exec.NewCommand(), defaultCommandTimeout, defaultLogCommandOutput)) } -func NewDetailed(systemctl *systemctl.Systemctl) *Amzn { - return &Amzn{ +func NewDetailed(systemctl *systemctl.Systemctl) *RHEL { + return &RHEL{ Systemctl: systemctl, } } -func (a *Amzn) EnableIscsiServices(ctx context.Context) error { +func (a *RHEL) EnableIscsiServices(ctx context.Context) error { if err := a.EnableServiceWithValidation(ctx, ServiceIscsid); err != nil { return err } diff --git a/internal/nodeprep/systemmanager/amzn/amzn_test.go b/internal/nodeprep/systemmanager/rhel/rhel_test.go similarity index 75% rename from internal/nodeprep/systemmanager/amzn/amzn_test.go rename to internal/nodeprep/systemmanager/rhel/rhel_test.go index f341e1d9a..5d2a46b79 100644 --- a/internal/nodeprep/systemmanager/amzn/amzn_test.go +++ b/internal/nodeprep/systemmanager/rhel/rhel_test.go @@ -1,6 +1,6 @@ // Copyright 2024 NetApp, Inc. All Rights Reserved. -package amzn_test +package rhel_test import ( "context" @@ -10,24 +10,24 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" - "github.com/netapp/trident/internal/nodeprep/systemmanager/amzn" + "github.com/netapp/trident/internal/nodeprep/systemmanager/rhel" "github.com/netapp/trident/internal/nodeprep/systemmanager/systemctl" "github.com/netapp/trident/mocks/mock_utils/mock_exec" ) func TestNew(t *testing.T) { - amznClient := amzn.New() - assert.NotNil(t, amznClient) + RHELClient := rhel.New() + assert.NotNil(t, RHELClient) } func TestNewDetailed(t *testing.T) { ctrl := gomock.NewController(t) command := mock_exec.NewMockCommand(ctrl) - amznClient := amzn.NewDetailed(systemctl.NewSystemctlDetailed(command, 1*time.Second, true)) - assert.NotNil(t, amznClient) + RHELClient := rhel.NewDetailed(systemctl.NewSystemctlDetailed(command, 1*time.Second, true)) + assert.NotNil(t, RHELClient) } -func TestAmzn_EnableIscsiServices(t *testing.T) { +func TestRHEL_EnableIscsiServices(t *testing.T) { type parameters struct { getCommand func(controller *gomock.Controller) *mock_exec.MockCommand assertError assert.ErrorAssertionFunc @@ -43,7 +43,7 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, assert.AnError) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, assert.AnError) return command }, assertError: assert.Error, @@ -52,9 +52,9 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return(nil, assert.AnError) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return(nil, assert.AnError) return command }, assertError: assert.Error, @@ -63,9 +63,9 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateInactive), nil) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateInactive), nil) return command }, assertError: assert.Error, @@ -74,11 +74,11 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceMultipathd).Return(nil, assert.AnError) + logCommandOutput, "enable", "--now", rhel.ServiceMultipathd).Return(nil, assert.AnError) return command }, assertError: assert.Error, @@ -87,13 +87,13 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceMultipathd).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceMultipathd).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceMultipathd, "--property=ActiveState").Return(nil, assert.AnError) + logCommandOutput, "show", rhel.ServiceMultipathd, "--property=ActiveState").Return(nil, assert.AnError) return command }, assertError: assert.Error, @@ -102,13 +102,13 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceMultipathd).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceMultipathd).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceMultipathd, "--property=ActiveState").Return([]byte(activeStateInactive), nil) + logCommandOutput, "show", rhel.ServiceMultipathd, "--property=ActiveState").Return([]byte(activeStateInactive), nil) return command }, assertError: assert.Error, @@ -117,13 +117,13 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { getCommand: func(controller *gomock.Controller) *mock_exec.MockCommand { command := mock_exec.NewMockCommand(controller) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceIscsid).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceIscsid).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) + logCommandOutput, "show", rhel.ServiceIscsid, "--property=ActiveState").Return([]byte(activeStateActive), nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "enable", "--now", amzn.ServiceMultipathd).Return(nil, nil) + logCommandOutput, "enable", "--now", rhel.ServiceMultipathd).Return(nil, nil) command.EXPECT().ExecuteWithTimeout(context.TODO(), "systemctl", commandTimeout, - logCommandOutput, "show", amzn.ServiceMultipathd, "--property=ActiveState").Return([]byte(activeStateActive), nil) + logCommandOutput, "show", rhel.ServiceMultipathd, "--property=ActiveState").Return([]byte(activeStateActive), nil) return command }, assertError: assert.NoError, @@ -134,8 +134,8 @@ func TestAmzn_EnableIscsiServices(t *testing.T) { t.Run(name, func(t *testing.T) { ctrl := gomock.NewController(t) - amznClient := amzn.NewDetailed(systemctl.NewSystemctlDetailed(params.getCommand(ctrl), commandTimeout, logCommandOutput)) - err := amznClient.EnableIscsiServices(context.TODO()) + RHELClient := rhel.NewDetailed(systemctl.NewSystemctlDetailed(params.getCommand(ctrl), commandTimeout, logCommandOutput)) + err := RHELClient.EnableIscsiServices(context.TODO()) if params.assertError(t, err) { params.assertError(t, err) }