From 52aaa41d875a4add7a535113e82e2459729c6829 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Tue, 11 Jul 2023 17:59:53 +0200 Subject: [PATCH] outofband/action_handlers: reset BMC based on task parameter --- internal/outofband/action_handlers.go | 19 +++++++++++++++---- internal/outofband/actions_test.go | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/outofband/action_handlers.go b/internal/outofband/action_handlers.go index c11deeaf..c7b8e366 100644 --- a/internal/outofband/action_handlers.go +++ b/internal/outofband/action_handlers.go @@ -452,15 +452,18 @@ func (h *actionHandler) resetBMC(a sw.StateSwitch, c sw.TransitionArgs) error { return err } - if !action.BMCPowerCycleRequired { + // proceed with reset only if these flags are set + if !action.BMCPowerCycleRequired && !tctx.Task.Parameters.ResetBMCBeforeInstall { return nil } tctx.Logger.WithFields( logrus.Fields{ - "component": action.Firmware.Component, - "bmc": tctx.Asset.BmcAddress, - }).Info("resetting BMC for firmware install") + "component": action.Firmware.Component, + "bmc": tctx.Asset.BmcAddress, + "task.Parameters.ResetBMCBeforeInstall": tctx.Task.Parameters.ResetBMCBeforeInstall, + "action.BMCPowerCycleRequired": action.BMCPowerCycleRequired, + }).Info("resetting BMC") if !tctx.Dryrun { if err := tctx.DeviceQueryor.ResetBMC(tctx.Ctx); err != nil { @@ -472,6 +475,14 @@ func (h *actionHandler) resetBMC(a sw.StateSwitch, c sw.TransitionArgs) error { } } + // skip install status poll if this was a preinstall BMC reset + if tctx.Task.Parameters.ResetBMCBeforeInstall { + // set this to false to prevent the rest of the actions from attempting a preInstall BMC reset. + tctx.Task.Parameters.ResetBMCBeforeInstall = false + + return nil + } + return h.pollFirmwareInstallStatus(a, c) } diff --git a/internal/outofband/actions_test.go b/internal/outofband/actions_test.go index d2a19c5f..cfc47674 100644 --- a/internal/outofband/actions_test.go +++ b/internal/outofband/actions_test.go @@ -57,7 +57,7 @@ func Test_NewActionStateMachine(t *testing.T) { // TODO(joel): at some point we'd want to test if the nodes and edges // in the transition rules match whats expected assert.Equal(t, transitionOrder(), m.TransitionOrder()) - assert.Len(t, transitionRules(), 10) + assert.Len(t, transitionRules(), 11) } func serverMux(t *testing.T, serveblob []byte) *http.ServeMux { @@ -208,6 +208,7 @@ func Test_ActionStateMachine_Run_Fails(t *testing.T) { transitionTypePowerOnDevice, transitionTypeCheckInstalledFirmware, transitionTypeDownloadFirmware, + transitionTypePreInstallResetBMC, transitionTypeInitiatingInstallFirmware, }