Skip to content

Commit f50cf3b

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 e302d1e commit f50cf3b

File tree

3 files changed

+78
-36
lines changed

3 files changed

+78
-36
lines changed

pkg/provisioner/ironic/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (f *ironicProvisionerFactory) init(havePreprovImgBuilder bool) error {
6161
"deployKernelURL", f.config.deployKernelURL,
6262
"deployRamdiskURL", f.config.deployRamdiskURL,
6363
"deployISOURL", f.config.deployISOURL,
64-
"liveISOForcePersistentBootDevice", f.config.liveISOForcePersistentBootDevice,
64+
"forcePersistentBootDevice", f.config.forcePersistentBootDevice,
6565
"CACertFile", tlsConf.TrustedCAFile,
6666
"ClientCertFile", tlsConf.ClientCertificateFile,
6767
"ClientPrivKeyFile", tlsConf.ClientPrivateKeyFile,
@@ -138,7 +138,7 @@ func loadConfigFromEnv(havePreprovImgBuilder bool) (ironicConfig, error) {
138138
if forcePersistentBootDevice != "Default" && forcePersistentBootDevice != "Always" && forcePersistentBootDevice != "Never" {
139139
return c, errors.New("invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE, must be one of Default, Always or Never")
140140
}
141-
c.liveISOForcePersistentBootDevice = forcePersistentBootDevice
141+
c.forcePersistentBootDevice = forcePersistentBootDevice
142142
}
143143

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

pkg/provisioner/ironic/factory_test.go

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ 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+
forcePersistentBootDevice string
18+
ironicCACertFile string
19+
ironicClientCertFile string
20+
ironicClientPrivateKeyFile string
21+
ironicInsecure string
22+
ironicSkipClientSANVerify string
2323

2424
origEnv map[string]string
2525
}
@@ -49,7 +49,7 @@ func (f *EnvFixture) SetUp() {
4949
f.replace("DEPLOY_KERNEL_URL", f.kernelURL)
5050
f.replace("DEPLOY_RAMDISK_URL", f.ramdiskURL)
5151
f.replace("DEPLOY_ISO_URL", f.isoURL)
52-
f.replace("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE", f.liveISOForcePersistentBootDevice)
52+
f.replace("LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE", f.forcePersistentBootDevice)
5353
f.replace("IRONIC_CACERT_FILE", f.ironicCACertFile)
5454
f.replace("IRONIC_CLIENT_CERT_FILE", f.ironicClientCertFile)
5555
f.replace("IRONIC_CLIENT_PRIVATE_KEY_FILE", f.ironicClientPrivateKeyFile)
@@ -61,7 +61,7 @@ func (f EnvFixture) VerifyConfig(t *testing.T, c ironicConfig, _ string) {
6161
assert.Equal(t, f.kernelURL, c.deployKernelURL)
6262
assert.Equal(t, f.ramdiskURL, c.deployRamdiskURL)
6363
assert.Equal(t, f.isoURL, c.deployISOURL)
64-
assert.Equal(t, f.liveISOForcePersistentBootDevice, c.liveISOForcePersistentBootDevice)
64+
assert.Equal(t, f.forcePersistentBootDevice, c.forcePersistentBootDevice)
6565
}
6666

6767
func (f EnvFixture) VerifyEndpoints(t *testing.T, ironic string) {
@@ -131,34 +131,71 @@ func TestLoadConfigFromEnv(t *testing.T) {
131131
expectedImgBuildError: "DEPLOY_RAMDISK_URL requires DEPLOY_KERNEL_URL to be set also",
132132
},
133133
{
134-
name: "Force Persistent Default",
134+
name: "ISO Force Persistent Default",
135135
env: EnvFixture{
136-
isoURL: "http://iso",
137-
liveISOForcePersistentBootDevice: "Default",
136+
isoURL: "http://iso",
137+
forcePersistentBootDevice: "Default",
138138
},
139139
forcePersistent: "Default",
140140
},
141141
{
142-
name: "Force Persistent Never",
142+
name: "ISO Force Persistent Never",
143143
env: EnvFixture{
144-
isoURL: "http://iso",
145-
liveISOForcePersistentBootDevice: "Never",
144+
isoURL: "http://iso",
145+
forcePersistentBootDevice: "Never",
146146
},
147147
forcePersistent: "Never",
148148
},
149149
{
150-
name: "Force Persistent Always",
150+
name: "ISO Force Persistent Always",
151151
env: EnvFixture{
152-
isoURL: "http://iso",
153-
liveISOForcePersistentBootDevice: "Always",
152+
isoURL: "http://iso",
153+
forcePersistentBootDevice: "Always",
154154
},
155155
forcePersistent: "Always",
156156
},
157157
{
158-
name: "Force Persistent Invalid",
158+
name: "ISO Force Persistent Invalid",
159159
env: EnvFixture{
160-
isoURL: "http://iso",
161-
liveISOForcePersistentBootDevice: "NotAValidOption",
160+
isoURL: "http://iso",
161+
forcePersistentBootDevice: "NotAValidOption",
162+
},
163+
expectedError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",
164+
expectedImgBuildError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",
165+
},
166+
{
167+
name: "kernel/ramdisk Force Persistent Default",
168+
env: EnvFixture{
169+
kernelURL: "http://kernel",
170+
ramdiskURL: "http://ramdisk",
171+
forcePersistentBootDevice: "Default",
172+
},
173+
forcePersistent: "Default",
174+
},
175+
{
176+
name: "kernel/ramdisk Force Persistent Never",
177+
env: EnvFixture{
178+
kernelURL: "http://kernel",
179+
ramdiskURL: "http://ramdisk",
180+
forcePersistentBootDevice: "Never",
181+
},
182+
forcePersistent: "Never",
183+
},
184+
{
185+
name: "kernel/ramdisk Force Persistent Always",
186+
env: EnvFixture{
187+
kernelURL: "http://kernel",
188+
ramdiskURL: "http://ramdisk",
189+
forcePersistentBootDevice: "Always",
190+
},
191+
forcePersistent: "Always",
192+
},
193+
{
194+
name: "kernel/ramdisk Force Persistent Invalid",
195+
env: EnvFixture{
196+
kernelURL: "http://kernel",
197+
ramdiskURL: "http://ramdisk",
198+
forcePersistentBootDevice: "NotAValidOption",
162199
},
163200
expectedError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",
164201
expectedImgBuildError: "invalid value for variable LIVE_ISO_FORCE_PERSISTENT_BOOT_DEVICE",

pkg/provisioner/ironic/ironic.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ 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+
forcePersistentBootDevice string
70+
maxBusyHosts int
71+
externalURL string
72+
provNetDisabled bool
7373
}
7474

7575
// Provisioner implements the provisioning.Provisioner interface
@@ -584,9 +584,9 @@ func (p *ironicProvisioner) setLiveIsoUpdateOptsForNode(ironicNode *nodes.Node,
584584
SetTopLevelOpt("deploy_interface", "ramdisk", ironicNode.DeployInterface)
585585

586586
driverOptValues := clients.UpdateOptsData{"force_persistent_boot_device": "Default"}
587-
if p.config.liveISOForcePersistentBootDevice != "" {
587+
if p.config.forcePersistentBootDevice != "" {
588588
driverOptValues = clients.UpdateOptsData{
589-
"force_persistent_boot_device": p.config.liveISOForcePersistentBootDevice,
589+
"force_persistent_boot_device": p.config.forcePersistentBootDevice,
590590
}
591591
}
592592
updater.SetDriverInfoOpts(driverOptValues, ironicNode)
@@ -625,6 +625,11 @@ func (p *ironicProvisioner) setDirectDeployUpdateOptsForNode(ironicNode *nodes.N
625625
driverOptValues := clients.UpdateOptsData{
626626
"force_persistent_boot_device": "Default",
627627
}
628+
if p.config.forcePersistentBootDevice != "" {
629+
driverOptValues = clients.UpdateOptsData{
630+
"force_persistent_boot_device": p.config.forcePersistentBootDevice,
631+
}
632+
}
628633
updater.SetDriverInfoOpts(driverOptValues, ironicNode)
629634
}
630635

0 commit comments

Comments
 (0)