Skip to content

Commit dfa21af

Browse files
authored
addition of rhcos to node prep for rosa support
1 parent effadb9 commit dfa21af

File tree

13 files changed

+416
-100
lines changed

13 files changed

+416
-100
lines changed

internal/nodeprep/instruction/instructions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ type Key struct {
2727
var instructionMap = map[Key]Instructions{}
2828

2929
func init() {
30-
instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = newAmznYumISCSI()
30+
instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = newRHELYumISCSI()
3131
instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroUbuntu, PkgMgr: nodeinfo.PkgMgrApt}] = newDebianAptISCSI()
32+
instructionMap[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroRhcos, PkgMgr: nodeinfo.PkgMgrNone}] = newRHCOSISCSI()
3233
instructionMap[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrYum}] = newYumISCSI()
3334
instructionMap[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrApt}] = newAptISCSI()
3435
}

internal/nodeprep/instruction/instructions_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestInstructions(t *testing.T) {
17-
AmznYumISCSI := newAmznYumISCSI()
17+
RHELYumISCSI := newRHELYumISCSI()
1818
DebianAptISCSI := newDebianAptISCSI()
1919
YumISCSI := newYumISCSI()
2020
AptISCSI := newAptISCSI()
@@ -24,7 +24,7 @@ func TestInstructions(t *testing.T) {
2424

2525
setDefaultInstructions := func() {
2626
scopedInstructions := map[Key]Instructions{}
27-
scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = AmznYumISCSI
27+
scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroAmzn, PkgMgr: nodeinfo.PkgMgrYum}] = RHELYumISCSI
2828
scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: nodeinfo.DistroUbuntu, PkgMgr: nodeinfo.PkgMgrApt}] = DebianAptISCSI
2929
scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrYum}] = YumISCSI
3030
scopedInstructions[Key{Protocol: protocol.ISCSI, Distro: "", PkgMgr: nodeinfo.PkgMgrApt}] = AptISCSI
@@ -98,7 +98,7 @@ func TestInstructions(t *testing.T) {
9898
HostSystem: amazonHostSystemResponse,
9999
Distro: nodeinfo.DistroAmzn,
100100
},
101-
expectedInstructions: []Instructions{AmznYumISCSI},
101+
expectedInstructions: []Instructions{RHELYumISCSI},
102102
setInstructions: setDefaultInstructions,
103103
assertError: assert.NoError,
104104
},
@@ -118,7 +118,7 @@ func TestInstructions(t *testing.T) {
118118
HostSystem: fooHostSystemResponse,
119119
Distro: fooDistro,
120120
},
121-
expectedInstructions: []Instructions{AmznYumISCSI},
121+
expectedInstructions: []Instructions{RHELYumISCSI},
122122
setInstructions: setDefaultInstructions,
123123
assertError: assert.NoError,
124124
},

internal/nodeprep/instruction/iscsi.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/netapp/trident/internal/nodeprep/packagemanager/yum"
99
"github.com/netapp/trident/internal/nodeprep/step"
1010
"github.com/netapp/trident/internal/nodeprep/systemmanager"
11-
"github.com/netapp/trident/internal/nodeprep/systemmanager/amzn"
1211
"github.com/netapp/trident/internal/nodeprep/systemmanager/debian"
12+
"github.com/netapp/trident/internal/nodeprep/systemmanager/rhel"
1313
)
1414

1515
type ISCSI struct {
@@ -20,12 +20,12 @@ func newDebianAptISCSI() (instruction Instructions) {
2020
return newISCSI(apt.New(), debian.New())
2121
}
2222

23-
func newAmznYumISCSI() (instruction Instructions) {
24-
return newISCSI(yum.New(), amzn.New())
23+
func newRHELYumISCSI() (instruction Instructions) {
24+
return newISCSI(yum.New(), rhel.New())
2525
}
2626

2727
func newYumISCSI() (instruction Instructions) {
28-
return newISCSI(yum.New(), amzn.New())
28+
return newISCSI(yum.New(), rhel.New())
2929
}
3030

3131
func newAptISCSI() (instruction Instructions) {
@@ -43,3 +43,14 @@ func newISCSI(packageManager packagemanager.PackageManager, systemManager system
4343
}
4444
return
4545
}
46+
47+
func newRHCOSISCSI() (instruction *ISCSI) {
48+
instruction = &ISCSI{}
49+
instruction.name = "RHCOS iscsi instructions"
50+
// ordering of steps matter here, multipath must be configured before installing iscsi tools to be idempotent
51+
instruction.steps = []step.Step{
52+
step.NewMultipathConfigureRHCOSStep(),
53+
step.NewEnableIscsiServices(rhel.New()),
54+
}
55+
return
56+
}

internal/nodeprep/mpathconfig/configuration.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111

1212
"github.com/hpe-storage/common-host-libs/mpathconfig"
13+
"github.com/spf13/afero"
1314

1415
. "github.com/netapp/trident/logging"
1516
"github.com/netapp/trident/utils/errors"
@@ -30,6 +31,7 @@ var _ MpathConfiguration = &Configuration{}
3031

3132
type Configuration struct {
3233
configuration *mpathconfig.Configuration
34+
osFs afero.Afero
3335
}
3436

3537
func (c *Configuration) GetRootSection() MpathConfigurationSection {
@@ -56,7 +58,7 @@ func (c *Configuration) PrintConf() []string {
5658
}
5759

5860
func (c *Configuration) SaveConfig(filePath string) error {
59-
f, err := os.Create(filePath)
61+
f, err := c.osFs.Create(filePath)
6062
if err != nil {
6163
return err
6264
}
@@ -80,14 +82,14 @@ func (c *Configuration) SaveConfig(filePath string) error {
8082
return err
8183
}
8284

83-
func New() (MpathConfiguration, error) {
84-
return NewFromFile(os.DevNull)
85+
func New(osFs afero.Afero) (MpathConfiguration, error) {
86+
return NewFromFile(osFs, os.DevNull)
8587
}
8688

87-
func NewFromFile(filename string) (MpathConfiguration, error) {
89+
func NewFromFile(osFs afero.Afero, filename string) (MpathConfiguration, error) {
8890
mpathCfg, err := mpathconfig.ParseConfig(filename)
8991
if err != nil {
9092
return nil, fmt.Errorf("error creating mpath config: %v", err)
9193
}
92-
return &Configuration{configuration: mpathCfg}, nil
94+
return &Configuration{configuration: mpathCfg, osFs: osFs}, nil
9395
}

internal/nodeprep/mpathconfig/configuration_test.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/spf13/afero"
910
"github.com/stretchr/testify/assert"
1011

1112
"github.com/netapp/trident/internal/nodeprep/mpathconfig"
1213
)
1314

1415
func TestNew(t *testing.T) {
15-
config, err := mpathconfig.New()
16+
fs := afero.NewMemMapFs()
17+
config, err := mpathconfig.New(afero.Afero{Fs: fs})
1618
assert.Nil(t, err)
1719
assert.NotNil(t, config)
1820
assert.IsType(t, &mpathconfig.Configuration{}, config)
@@ -38,9 +40,11 @@ func TestNewFromFile(t *testing.T) {
3840
},
3941
}
4042

43+
fs := afero.NewMemMapFs()
44+
4145
for name, params := range tests {
4246
t.Run(name, func(t *testing.T) {
43-
config, err := mpathconfig.NewFromFile(params.fileName)
47+
config, err := mpathconfig.NewFromFile(afero.Afero{Fs: fs}, params.fileName)
4448
if params.assertError != nil {
4549
params.assertError(t, err)
4650
}
@@ -52,7 +56,9 @@ func TestNewFromFile(t *testing.T) {
5256
}
5357

5458
func TestConfiguration_GetRootSection(t *testing.T) {
55-
config, err := mpathconfig.New()
59+
fs := afero.NewMemMapFs()
60+
61+
config, err := mpathconfig.New(afero.Afero{Fs: fs})
5662
assert.Nil(t, err)
5763
assert.NotNil(t, config)
5864

@@ -62,6 +68,9 @@ func TestConfiguration_GetRootSection(t *testing.T) {
6268
}
6369

6470
func TestConfiguration_GetSection(t *testing.T) {
71+
fs := afero.NewMemMapFs()
72+
os := afero.Afero{Fs: fs}
73+
6574
type parameters struct {
6675
getConfig func() mpathconfig.MpathConfiguration
6776
sectionName string
@@ -80,7 +89,7 @@ func TestConfiguration_GetSection(t *testing.T) {
8089
},
8190
"get default section from empty configuration": {
8291
getConfig: func() mpathconfig.MpathConfiguration {
83-
config, err := mpathconfig.New()
92+
config, err := mpathconfig.New(os)
8493
assert.Nil(t, err)
8594
return config
8695
},
@@ -90,7 +99,7 @@ func TestConfiguration_GetSection(t *testing.T) {
9099
},
91100
"get default section from configuration that has a default section": {
92101
getConfig: func() mpathconfig.MpathConfiguration {
93-
config, err := mpathconfig.New()
102+
config, err := mpathconfig.New(os)
94103
assert.Nil(t, err)
95104

96105
_, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName)
@@ -104,7 +113,7 @@ func TestConfiguration_GetSection(t *testing.T) {
104113
},
105114
"get invalid section from configuration that has a default section": {
106115
getConfig: func() mpathconfig.MpathConfiguration {
107-
config, err := mpathconfig.New()
116+
config, err := mpathconfig.New(os)
108117
assert.Nil(t, err)
109118

110119
_, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName)
@@ -134,6 +143,9 @@ func TestConfiguration_GetSection(t *testing.T) {
134143
}
135144

136145
func TestConfiguration_PrintConf(t *testing.T) {
146+
fs := afero.NewMemMapFs()
147+
os := afero.Afero{Fs: fs}
148+
137149
type parameters struct {
138150
getConfig func() mpathconfig.MpathConfiguration
139151
expectedOutput []string
@@ -148,15 +160,15 @@ func TestConfiguration_PrintConf(t *testing.T) {
148160
},
149161
"print empty configuration": {
150162
getConfig: func() mpathconfig.MpathConfiguration {
151-
config, err := mpathconfig.New()
163+
config, err := mpathconfig.New(os)
152164
assert.Nil(t, err)
153165
return config
154166
},
155167
expectedOutput: nil,
156168
},
157169
"print configuration with a default section": {
158170
getConfig: func() mpathconfig.MpathConfiguration {
159-
config, err := mpathconfig.New()
171+
config, err := mpathconfig.New(os)
160172
assert.Nil(t, err)
161173

162174
_, err = config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName)
@@ -178,7 +190,8 @@ func TestConfiguration_PrintConf(t *testing.T) {
178190
}
179191

180192
func TestConfiguration_SaveConfig(t *testing.T) {
181-
config, err := mpathconfig.New()
193+
fs := afero.NewMemMapFs()
194+
config, err := mpathconfig.New(afero.Afero{Fs: fs})
182195
assert.NoError(t, err)
183196
defaultSection, err := config.GetRootSection().AddSection(mpathconfig.DefaultsSectionName)
184197
assert.NoError(t, err)

0 commit comments

Comments
 (0)