Skip to content

Commit

Permalink
outofband: power off the host if the provider indicates its required
Browse files Browse the repository at this point in the history
The powerOff would be skipped since the provider install parameter was
not being considered
  • Loading branch information
joelrebel committed Apr 30, 2024
1 parent 48844c5 commit ca5af94
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type Action struct {
// HostPowerCycled is set when the host has been power cycled for the action.
HostPowerCycled bool `json:"host_power_cycled"`

// HostPowerOffPreInstall is set when the firmware install provider indicates
// the host must be powered off before proceeding with the install step.
HostPowerOffPreInstall bool `json:"host_power_off_pre_install"`

// First is set to true when its the first action being executed
First bool `json:"first"`

Expand Down
5 changes: 5 additions & 0 deletions internal/outofband/action_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ func (h *handler) powerCycleServer(ctx context.Context) error {
}

func (h *handler) conditionalPowerOffDevice(_ context.Context) (bool, error) {
// The install provider indicated the host must be powered off
if h.action.HostPowerOffPreInstall {
return true, nil
}

// proceed to power off the device if this is the final action
if !h.action.Last {
return false, nil
Expand Down
1 change: 1 addition & 0 deletions internal/outofband/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (o *ActionHandler) ComposeAction(ctx context.Context, actionCtx *runner.Act
BMCResetPreInstall: bmcResetBeforeInstall,
BMCResetPostInstall: bmcResetPostInstall,
BMCResetOnInstallFailure: bmcResetOnInstallFailure,
HostPowerOffPreInstall: hostPowerOffRequired(required),
ForceInstall: actionCtx.Task.Parameters.ForceInstall,
Steps: steps,
First: actionCtx.First,
Expand Down
25 changes: 25 additions & 0 deletions internal/outofband/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestComposeAction(t *testing.T) {
expectForceInstall bool
expectBMCResetPostInstall bool
expectBMCResetOnInstallFailure bool
expectHostPowerOffPreInstall bool
expectErrContains string
}{
{
Expand Down Expand Up @@ -94,6 +95,23 @@ func TestComposeAction(t *testing.T) {
)
},
},
{
name: "test host power off pre-install",
expectHostPowerOffPreInstall: true,
mockSetup: func(actionCtx *runner.ActionHandlerContext, m *device.MockQueryor) {
actionCtx.First = true

actionCtx.DeviceQueryor = m
m.On("FirmwareInstallSteps", mock.Anything, "drive").Once().Return(
[]bconsts.FirmwareInstallStep{
bconsts.FirmwareInstallStepPowerOffHost,
bconsts.FirmwareInstallStepUploadInitiateInstall,
bconsts.FirmwareInstallStepInstallStatus,
},
nil,
)
},
},
{
name: "test bmc reset on install failure",
expectBMCResetOnInstallFailure: true,
Expand Down Expand Up @@ -179,6 +197,13 @@ func TestComposeAction(t *testing.T) {
assert.False(t, got.BMCResetOnInstallFailure)
}

// host power off required before install
if tc.expectHostPowerOffPreInstall {
assert.True(t, got.HostPowerOffPreInstall)
} else {
assert.False(t, got.HostPowerOffPreInstall)
}

// expect atleast 5 or more steps
assert.GreaterOrEqual(t, len(got.Steps), 5)
})
Expand Down
5 changes: 5 additions & 0 deletions internal/outofband/bmc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
"github.com/sirupsen/logrus"
)

// NOTE: the constants.FirmwareInstallStep type will be moved to the FirmwareInstallProperties struct type which will make this easier
func hostPowerOffRequired(steps []constants.FirmwareInstallStep) bool {
return slices.Contains(steps, constants.FirmwareInstallStepPowerOffHost)
}

// NOTE: the constants.FirmwareInstallStep type will be moved to the FirmwareInstallProperties struct type which will make this easier
func bmcResetParams(steps []constants.FirmwareInstallStep) (bmcResetOnInstallFailure, bmcResetPostInstall bool) {
for _, step := range steps {
Expand Down

0 comments on commit ca5af94

Please sign in to comment.