Skip to content

Commit

Permalink
addition of rhcos to node prep for rosa support
Browse files Browse the repository at this point in the history
  • Loading branch information
brownaaron authored Nov 14, 2024
1 parent effadb9 commit dfa21af
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 100 deletions.
3 changes: 2 additions & 1 deletion internal/nodeprep/instruction/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
8 changes: 4 additions & 4 deletions internal/nodeprep/instruction/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestInstructions(t *testing.T) {
AmznYumISCSI := newAmznYumISCSI()
RHELYumISCSI := newRHELYumISCSI()
DebianAptISCSI := newDebianAptISCSI()
YumISCSI := newYumISCSI()
AptISCSI := newAptISCSI()
Expand All @@ -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
Expand Down Expand Up @@ -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,
},
Expand All @@ -118,7 +118,7 @@ func TestInstructions(t *testing.T) {
HostSystem: fooHostSystemResponse,
Distro: fooDistro,
},
expectedInstructions: []Instructions{AmznYumISCSI},
expectedInstructions: []Instructions{RHELYumISCSI},
setInstructions: setDefaultInstructions,
assertError: assert.NoError,
},
Expand Down
19 changes: 15 additions & 4 deletions internal/nodeprep/instruction/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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
}
12 changes: 7 additions & 5 deletions internal/nodeprep/mpathconfig/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -30,6 +31,7 @@ var _ MpathConfiguration = &Configuration{}

type Configuration struct {
configuration *mpathconfig.Configuration
osFs afero.Afero
}

func (c *Configuration) GetRootSection() MpathConfigurationSection {
Expand All @@ -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
}
Expand All @@ -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
}
31 changes: 22 additions & 9 deletions internal/nodeprep/mpathconfig/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
},
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -148,15 +160,15 @@ 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
},
expectedOutput: nil,
},
"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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit dfa21af

Please sign in to comment.