From 905a95485261e7e07fe0ff85324028ee0caf5f5e Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Mon, 4 Dec 2023 15:52:10 +0100 Subject: [PATCH] providers/asrockrack: GetPowerState() return ErrBMCUpdating when the BMC is under and update --- providers/asrockrack/helpers.go | 6 ++++-- providers/asrockrack/power.go | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/providers/asrockrack/helpers.go b/providers/asrockrack/helpers.go index a550f253..3166614b 100644 --- a/providers/asrockrack/helpers.go +++ b/providers/asrockrack/helpers.go @@ -180,8 +180,10 @@ func (a *ASRockRack) createUpdateUser(ctx context.Context, account *UserAccount) } // 1 Set BMC to flash mode and prepare flash area -// at this point all logged in sessions are terminated -// and no logins are permitted +// +// with the BMC set in flash mode, no new logins are accepted +// and only a few endpoints can be queried with the existing session +// one of the few being the install progress/flash status endpoint. func (a *ASRockRack) setFlashMode(ctx context.Context) error { device := common.NewDevice() device.Metadata = map[string]string{} diff --git a/providers/asrockrack/power.go b/providers/asrockrack/power.go index d8a8efa1..b94f5a19 100644 --- a/providers/asrockrack/power.go +++ b/providers/asrockrack/power.go @@ -20,6 +20,30 @@ type power struct { func (a *ASRockRack) PowerStateGet(ctx context.Context) (state string, err error) { info, err := a.chassisStatusInfo(ctx) if err != nil { + if strings.Contains(err.Error(), "401") { + // during a BMC update, only the flash-progress endpoint can be queried + // and so we cannot determine server power status + // we don't return an error here because we don't want the bmclib client to retry another provider. + progress, err := a.flashProgress(ctx, "/api/maintenance/firmware/flash-progress") + if err == nil && progress.Action != "" { + a.log.V(2).WithValues( + "action", progress.Action, + "progress", progress.Progress, + "state", progress.State, + ).Info("bmc in flash mode, power status cannot be determined") + + return "", errors.Wrap( + bmclibErrs.ErrBMCUpdating, + fmt.Sprintf( + "action: %s, progress: %s, state: %d", + progress.Action, + progress.Progress, + progress.State, + ), + ) + } + } + return "", errors.Wrap(bmclibErrs.ErrPowerStatusRead, err.Error()) } @@ -105,7 +129,8 @@ func (a *ASRockRack) resetBMC(ctx context.Context) error { return err } - if statusCode != http.StatusOK { + // The E3C256D4ID BMC returns a 500 status error on the BMC reset request + if statusCode != http.StatusOK && statusCode != http.StatusInternalServerError { return fmt.Errorf("non 200 response: %d", statusCode) }