Skip to content

Commit 52c90c8

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 52a6ad1 commit 52c90c8

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
@@ -101,6 +101,7 @@ func (f *ironicProvisionerFactory) init(havePreprovImgBuilder bool) error {
101101
"deployRamdiskURL", f.config.deployRamdiskURL,
102102
"deployISOURL", f.config.deployISOURL,
103103
"liveISOForcePersistentBootDevice", f.config.liveISOForcePersistentBootDevice,
104+
"directDeployForcePersistentBootDevice", f.config.directDeployForcePersistentBootDevice,
104105
"CACertFile", tlsConf.TrustedCAFile,
105106
"ClientCertFile", tlsConf.ClientCertificateFile,
106107
"ClientPrivKeyFile", tlsConf.ClientPrivateKeyFile,
@@ -197,11 +198,17 @@ func loadConfigFromEnv(havePreprovImgBuilder bool) (ironicConfig, error) {
197198
c.maxBusyHosts = value
198199
}
199200

200-
if forcePersistentBootDevice := os.Getenv("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE"); forcePersistentBootDevice != "" {
201-
if forcePersistentBootDevice != "Default" && forcePersistentBootDevice != "Always" && forcePersistentBootDevice != "Never" {
201+
if liveISOForcePersistentBootDevice := os.Getenv("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE"); liveISOForcePersistentBootDevice != "" {
202+
if liveISOForcePersistentBootDevice != "Default" && liveISOForcePersistentBootDevice != "Always" && liveISOForcePersistentBootDevice != "Never" {
202203
return c, errors.New("invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE, must be one of Default, Always or Never")
203204
}
204-
c.liveISOForcePersistentBootDevice = forcePersistentBootDevice
205+
c.liveISOForcePersistentBootDevice = liveISOForcePersistentBootDevice
206+
}
207+
if directDeployForcePersistentBootDevice := os.Getenv("DIRECT_DEPLOY_FORCE_PERSISTENT_BOOT_DEVICE"); directDeployForcePersistentBootDevice != "" {
208+
if directDeployForcePersistentBootDevice != "Default" && directDeployForcePersistentBootDevice != "Always" && directDeployForcePersistentBootDevice != "Never" {
209+
return c, errors.New("invalid value for variable DIRECT_DEPLOY_FORCE_PERSISTENT_BOOT_DEVICE, must be one of Default, Always or Never")
210+
}
211+
c.directDeployForcePersistentBootDevice = directDeployForcePersistentBootDevice
205212
}
206213

207214
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+
directDeployForcePersistentBootDevice 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("DIRECT_DEPLOY_FORCE_PERSISTENT_BOOT_DEVICE", f.directDeployForcePersistentBootDevice)
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.directDeployForcePersistentBootDevice, c.directDeployForcePersistentBootDevice)
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+
directDeployForcePersistentBootDevice: "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+
directDeployForcePersistentBootDevice: "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+
directDeployForcePersistentBootDevice: "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+
directDeployForcePersistentBootDevice: "NotAValidOption",
202+
},
203+
expectedError: "invalid value for variable DIRECT_DEPLOY_FORCE_PERSISTENT_BOOT_DEVICE",
204+
expectedImgBuildError: "invalid value for variable DIRECT_DEPLOY_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+
directDeployForcePersistentBootDevice 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.directDeployForcePersistentBootDevice != "" {
637+
driverOptValues = clients.UpdateOptsData{
638+
"force_persistent_boot_device": p.config.directDeployForcePersistentBootDevice,
639+
}
640+
}
635641
updater.SetDriverInfoOpts(driverOptValues, ironicNode)
636642
}
637643

0 commit comments

Comments
 (0)