Skip to content

Commit

Permalink
Merge pull request metal3-io#1100 from tliu2021/bios_configuration
Browse files Browse the repository at this point in the history
Check for empty HFS status settings
  • Loading branch information
metal3-io-bot authored Apr 4, 2022
2 parents 1bf9684 + b503d60 commit 4701d17
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
5 changes: 5 additions & 0 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,11 @@ func (r *BareMetalHostReconciler) getHostFirmwareSettings(info *reconcileInfo) (
// Check if there are settings in the Spec that are different than the Status
if meta.IsStatusConditionTrue(hfs.Status.Conditions, string(metal3v1alpha1.FirmwareSettingsChangeDetected)) {

// Check if the status settings have been populated
if len(hfs.Status.Settings) == 0 {
return false, nil, errors.New("host firmware status settings not available")
}

if meta.IsStatusConditionTrue(hfs.Status.Conditions, string(metal3v1alpha1.FirmwareSettingsValid)) {
info.log.Info("hostFirmwareSettings indicating ChangeDetected", "namespacename", info.request.NamespacedName)
return true, hfs, nil
Expand Down
55 changes: 55 additions & 0 deletions controllers/metal3.io/baremetalhost_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2736,9 +2736,64 @@ func TestHFSTransitionToPreparing(t *testing.T) {
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
Settings: metal3v1alpha1.SettingsMap{
"ProcVirtualization": "Enabled",
"SecureBoot": "Enabled",
},
}

r.Update(goctx.TODO(), hfs)

waitForProvisioningState(t, r, host, metal3v1alpha1.StatePreparing)
}

// TestHFSEmptyStatusSettings ensures that BMH does not move to the next state
// when a user provides the BIOS settings on a hardware server that does not
// have the required license to configure BIOS
func TestHFSEmptyStatusSettings(t *testing.T) {
host := newDefaultHost(t)
host.Spec.Online = true
host.Spec.ConsumerRef = &corev1.ObjectReference{}
host.Spec.ExternallyProvisioned = false
r := newTestReconciler(host)

waitForProvisioningState(t, r, host, metal3v1alpha1.StatePreparing)

// Update HFS so host will go through cleaning
hfs := &metal3v1alpha1.HostFirmwareSettings{}
key := client.ObjectKey{
Namespace: host.ObjectMeta.Namespace, Name: host.ObjectMeta.Name}
if err := r.Get(goctx.TODO(), key, hfs); err != nil {
t.Fatal(err)
}

hfs.Status = metal3v1alpha1.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
}

r.Update(goctx.TODO(), hfs)

tryReconcile(t, r, host,
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
return host.Status.Provisioning.State == metal3v1alpha1.StatePreparing
},
)

// Clear the change, it will no longer be blocked
hfs.Status = metal3v1alpha1.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "False", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
}

r.Update(goctx.TODO(), hfs)
tryReconcile(t, r, host,
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
return host.Status.Provisioning.State == metal3v1alpha1.StateAvailable
},
)
}
7 changes: 5 additions & 2 deletions controllers/metal3.io/hostfirmwaresettings_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,11 @@ func (r *HostFirmwareSettingsReconciler) updateStatus(info *rInfo, settings meta
dirty = true
}
} else {
for _, error := range errors {
info.publishEvent("ValidationFailed", fmt.Sprintf("Invalid BIOS setting: %v", error))
// If the status settings are empty, don't raise events
if len(newStatus.Settings) != 0 {
for _, error := range errors {
info.publishEvent("ValidationFailed", fmt.Sprintf("Invalid BIOS setting: %v", error))
}
}
reason = reasonConfigurationError
if setCondition(generation, &newStatus, info, metal3v1alpha1.FirmwareSettingsValid, metav1.ConditionFalse, reason, "Invalid BIOS setting") {
Expand Down

0 comments on commit 4701d17

Please sign in to comment.