Skip to content

Commit

Permalink
Minor tweaks, first attempt of fixing the test.
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Anders <[email protected]>
  • Loading branch information
rhjanders committed Oct 16, 2024
1 parent 7eda476 commit 0f11a97
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
8 changes: 3 additions & 5 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,15 +1365,13 @@ func (r *BareMetalHostReconciler) checkServicing(prov provisioner.Provisioner, i
// (NOTE)janders: since Servicing is an opt-in feature that requires HostUpdatePolicy to be created and set to onReboot
// set below booleans to false by default and change to true based on policy settings

servicingData.LiveFirmwareSettingsAllowed = false
var LiveFirmwareSettingsAllowed bool

if hup != nil {
if hup.Spec.FirmwareSettings == metal3api.HostUpdatePolicyOnReboot {
servicingData.LiveFirmwareSettingsAllowed = true
}
LiveFirmwareSettingsAllowed = (hup.Spec.FirmwareSettings == metal3api.HostUpdatePolicyOnReboot)
}

if servicingData.LiveFirmwareSettingsAllowed {
if LiveFirmwareSettingsAllowed {
var hfs *metal3api.HostFirmwareSettings
var err error
dirty, hfs, err = r.getHostFirmwareSettings(info)
Expand Down
71 changes: 70 additions & 1 deletion controllers/metal3.io/baremetalhost_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/event"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -812,7 +813,75 @@ func TestRebootWithServicing(t *testing.T) {
}
host.Status.Provisioning.Image.URL = "foo"

r := newTestReconciler(host)
// HUP creation
hup := &metal3api.HostUpdatePolicy{
TypeMeta: metav1.TypeMeta{
Kind: "HostUpdatePolicy",
APIVersion: "metal3.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: host.Name,
Namespace: namespace,
},
Spec: metal3api.HostUpdatePolicySpec{
FirmwareSettings: metal3api.HostUpdatePolicyOnReboot,
FirmwareUpdates: metal3api.HostUpdatePolicyOnReboot,
},
}

// HFS creation
hfs := &metal3api.HostFirmwareSettings{
TypeMeta: metav1.TypeMeta{
Kind: "HostFirmwareSettings",
APIVersion: "metal3.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: host.ObjectMeta.Name,
Namespace: host.ObjectMeta.Namespace,
},
Status: metal3api.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
},
/*Spec: metal3api.HostFirmwareSettingsSpec{
Settings: metal3api.SettingsMap{
"ProcVirtualization": "Enabled",
"SecureBoot": "Enabled",
},
},*/
}

r := newTestReconciler(host, hup, hfs)

err := r.Update(context.TODO(), hup)
require.NoError(t, err)
fmt.Printf("janders-hup-debug: HostUpdatePolicy CR: %+v", hup)

err2 := r.Update(context.TODO(), hfs)
require.NoError(t, err2)
fmt.Printf("janders-hfs-debug: HostFirmwareSettings CR): %+v", hfs)

key := client.ObjectKey{
Namespace: host.ObjectMeta.Namespace, Name: host.ObjectMeta.Name}
if err := r.Get(context.TODO(), key, hfs); err != nil {
t.Fatal(err)
}
hfs.Status = metal3api.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
Settings: metal3api.SettingsMap{
"ProcVirtualization": "Enabled",
"SecureBoot": "Enabled",
},
}

errUpdateHFS := r.Update(context.TODO(), hfs)
assert.NoError(t, errUpdateHFS)
fmt.Printf("janders-hfs-debug: HostFirmwareSettings CR post-update): %+v", hfs)

tryReconcile(t, r, host,
func(host *metal3api.BareMetalHost, result reconcile.Result) bool {
Expand Down
8 changes: 3 additions & 5 deletions pkg/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ type PrepareData struct {
}

type ServicingData struct {
FirmwareConfig *metal3api.FirmwareConfig
TargetFirmwareSettings metal3api.DesiredSettingsMap
ActualFirmwareSettings metal3api.SettingsMap
LiveFirmwareUpdateAllowed bool
LiveFirmwareSettingsAllowed bool
FirmwareConfig *metal3api.FirmwareConfig
TargetFirmwareSettings metal3api.DesiredSettingsMap
ActualFirmwareSettings metal3api.SettingsMap
// TargetFirmwareComponents []metal3api.FirmwareUpdate
}

Expand Down

0 comments on commit 0f11a97

Please sign in to comment.