Skip to content

Commit 0d3977e

Browse files
committed
Allow setting force_persistent_boot_device: <value> for deploy_interface=direct using env
Signed-off-by: Marcel Fest <[email protected]>
1 parent 7085ea4 commit 0d3977e

File tree

3 files changed

+78
-25
lines changed

3 files changed

+78
-25
lines changed

pkg/provisioner/ironic/factory.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (f *ironicProvisionerFactory) init(havePreprovImgBuilder bool) error {
6262
"deployRamdiskURL", f.config.deployRamdiskURL,
6363
"deployISOURL", f.config.deployISOURL,
6464
"liveISOForcePersistentBootDevice", f.config.liveISOForcePersistentBootDevice,
65+
"kernelAndRamdiskForcePersistentBootDevice", f.config.kernelAndRamdiskForcePersistentBootDevice,
6566
"CACertFile", tlsConf.TrustedCAFile,
6667
"ClientCertFile", tlsConf.ClientCertificateFile,
6768
"ClientPrivKeyFile", tlsConf.ClientPrivateKeyFile,
@@ -134,11 +135,17 @@ func loadConfigFromEnv(havePreprovImgBuilder bool) (ironicConfig, error) {
134135
c.maxBusyHosts = value
135136
}
136137

137-
if forcePersistentBootDevice := os.Getenv("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE"); forcePersistentBootDevice != "" {
138-
if forcePersistentBootDevice != "Default" && forcePersistentBootDevice != "Always" && forcePersistentBootDevice != "Never" {
138+
if liveISOForcePersistentBootDevice := os.Getenv("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE"); liveISOForcePersistentBootDevice != "" {
139+
if liveISOForcePersistentBootDevice != "Default" && liveISOForcePersistentBootDevice != "Always" && liveISOForcePersistentBootDevice != "Never" {
139140
return c, errors.New("invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE, must be one of Default, Always or Never")
140141
}
141-
c.liveISOForcePersistentBootDevice = forcePersistentBootDevice
142+
c.liveISOForcePersistentBootDevice = liveISOForcePersistentBootDevice
143+
}
144+
if kernelAndRamdiskForcePersistentBootDevice := os.Getenv("KERNEL_AND_RAMDISK_FORCE_PERSISTENT_BOOT_DEVICE"); kernelAndRamdiskForcePersistentBootDevice != "" {
145+
if kernelAndRamdiskForcePersistentBootDevice != "Default" && kernelAndRamdiskForcePersistentBootDevice != "Always" && kernelAndRamdiskForcePersistentBootDevice != "Never" {
146+
return c, errors.New("invalid value for variable KERNEL_AND_RAMDISK_FORCE_PERSISTENT_BOOT_DEVICE, must be one of Default, Always or Never")
147+
}
148+
c.kernelAndRamdiskForcePersistentBootDevice = kernelAndRamdiskForcePersistentBootDevice
142149
}
143150

144151
c.externalURL = os.Getenv("IRONIC_EXTERNAL_URL_V6")

pkg/provisioner/ironic/factory_test.go

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import (
1010
)
1111

1212
type EnvFixture struct {
13-
ironicEndpoint string
14-
kernelURL string
15-
ramdiskURL string
16-
isoURL string
17-
liveISOForcePersistentBootDevice string
18-
ironicCACertFile string
19-
ironicClientCertFile string
20-
ironicClientPrivateKeyFile string
21-
ironicInsecure string
22-
ironicSkipClientSANVerify string
13+
ironicEndpoint string
14+
kernelURL string
15+
ramdiskURL string
16+
isoURL string
17+
liveISOForcePersistentBootDevice string
18+
kernelAndRamdiskForcePersistentBootDevice string
19+
ironicCACertFile string
20+
ironicClientCertFile string
21+
ironicClientPrivateKeyFile string
22+
ironicInsecure string
23+
ironicSkipClientSANVerify string
2324

2425
origEnv map[string]string
2526
}
@@ -50,6 +51,7 @@ func (f *EnvFixture) SetUp() {
5051
f.replace("DEPLOY_RAMDISK_URL", f.ramdiskURL)
5152
f.replace("DEPLOY_ISO_URL", f.isoURL)
5253
f.replace("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE", f.liveISOForcePersistentBootDevice)
54+
f.replace("KERNEL_AND_RAMDISK_FORCE_PERSISTENT_BOOT_DEVICE", f.kernelAndRamdiskForcePersistentBootDevice)
5355
f.replace("IRONIC_CACERT_FILE", f.ironicCACertFile)
5456
f.replace("IRONIC_CLIENT_CERT_FILE", f.ironicClientCertFile)
5557
f.replace("IRONIC_CLIENT_PRIVATE_KEY_FILE", f.ironicClientPrivateKeyFile)
@@ -62,6 +64,7 @@ func (f EnvFixture) VerifyConfig(t *testing.T, c ironicConfig, _ string) {
6264
assert.Equal(t, f.ramdiskURL, c.deployRamdiskURL)
6365
assert.Equal(t, f.isoURL, c.deployISOURL)
6466
assert.Equal(t, f.liveISOForcePersistentBootDevice, c.liveISOForcePersistentBootDevice)
67+
assert.Equal(t, f.kernelAndRamdiskForcePersistentBootDevice, c.kernelAndRamdiskForcePersistentBootDevice)
6568
}
6669

6770
func (f EnvFixture) VerifyEndpoints(t *testing.T, ironic string) {
@@ -131,38 +134,75 @@ func TestLoadConfigFromEnv(t *testing.T) {
131134
expectedImgBuildError: "DEPLOY_RAMDISK_URL requires DEPLOY_KERNEL_URL to be set also",
132135
},
133136
{
134-
name: "Force Persistent Default",
137+
name: "ISO Force Persistent Default",
135138
env: EnvFixture{
136139
isoURL: "http://iso",
137140
liveISOForcePersistentBootDevice: "Default",
138141
},
139142
forcePersistent: "Default",
140143
},
141144
{
142-
name: "Force Persistent Never",
145+
name: "ISO Force Persistent Never",
143146
env: EnvFixture{
144147
isoURL: "http://iso",
145148
liveISOForcePersistentBootDevice: "Never",
146149
},
147150
forcePersistent: "Never",
148151
},
149152
{
150-
name: "Force Persistent Always",
153+
name: "ISO Force Persistent Always",
151154
env: EnvFixture{
152155
isoURL: "http://iso",
153156
liveISOForcePersistentBootDevice: "Always",
154157
},
155158
forcePersistent: "Always",
156159
},
157160
{
158-
name: "Force Persistent Invalid",
161+
name: "ISO Force Persistent Invalid",
159162
env: EnvFixture{
160163
isoURL: "http://iso",
161164
liveISOForcePersistentBootDevice: "NotAValidOption",
162165
},
163166
expectedError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",
164167
expectedImgBuildError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",
165168
},
169+
{
170+
name: "kernel/ramdisk Force Persistent Default",
171+
env: EnvFixture{
172+
kernelURL: "http://kernel",
173+
ramdiskURL: "http://ramdisk",
174+
kernelAndRamdiskForcePersistentBootDevice: "Default",
175+
},
176+
forcePersistent: "Default",
177+
},
178+
{
179+
name: "kernel/ramdisk Force Persistent Never",
180+
env: EnvFixture{
181+
kernelURL: "http://kernel",
182+
ramdiskURL: "http://ramdisk",
183+
kernelAndRamdiskForcePersistentBootDevice: "Never",
184+
},
185+
forcePersistent: "Never",
186+
},
187+
{
188+
name: "kernel/ramdisk Force Persistent Always",
189+
env: EnvFixture{
190+
kernelURL: "http://kernel",
191+
ramdiskURL: "http://ramdisk",
192+
kernelAndRamdiskForcePersistentBootDevice: "Always",
193+
},
194+
forcePersistent: "Always",
195+
},
196+
{
197+
name: "kernel/ramdisk Force Persistent Invalid",
198+
env: EnvFixture{
199+
kernelURL: "http://kernel",
200+
ramdiskURL: "http://ramdisk",
201+
kernelAndRamdiskForcePersistentBootDevice: "NotAValidOption",
202+
},
203+
expectedError: "invalid value for variable KERNEL_AND_RAMDISK_FORCE_PERSISTENT_BOOT_DEVICE",
204+
expectedImgBuildError: "invalid value for variable KERNEL_AND_RAMDISK_FORCE_PERSISTENT_BOOT_DEVICE",
205+
},
166206
}
167207

168208
for _, tt := range []string{"", " (with img builder)"} {

pkg/provisioner/ironic/ironic.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ func NewMacAddressConflictError(address, node string) error {
6262
}
6363

6464
type ironicConfig struct {
65-
havePreprovImgBuilder bool
66-
deployKernelURL string
67-
deployRamdiskURL string
68-
deployISOURL string
69-
liveISOForcePersistentBootDevice string
70-
maxBusyHosts int
71-
externalURL string
72-
provNetDisabled bool
65+
havePreprovImgBuilder bool
66+
deployKernelURL string
67+
deployRamdiskURL string
68+
deployISOURL string
69+
liveISOForcePersistentBootDevice string
70+
kernelAndRamdiskForcePersistentBootDevice string
71+
maxBusyHosts int
72+
externalURL string
73+
provNetDisabled bool
7374
}
7475

7576
// Provisioner implements the provisioning.Provisioner interface
@@ -632,6 +633,11 @@ func (p *ironicProvisioner) setDirectDeployUpdateOptsForNode(ironicNode *nodes.N
632633
driverOptValues := clients.UpdateOptsData{
633634
"force_persistent_boot_device": "Default",
634635
}
636+
if p.config.kernelAndRamdiskForcePersistentBootDevice != "" {
637+
driverOptValues = clients.UpdateOptsData{
638+
"force_persistent_boot_device": p.config.kernelAndRamdiskForcePersistentBootDevice,
639+
}
640+
}
635641
updater.SetDriverInfoOpts(driverOptValues, ironicNode)
636642
}
637643

0 commit comments

Comments
 (0)