From 6bc70fe3e7d497dc580f978f55008484116b309d Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Mon, 20 Nov 2023 15:33:33 +0100 Subject: [PATCH] providers/supermicro: return TaskState constant in FirmwareInstallStatus --- providers/supermicro/firmware.go | 2 +- providers/supermicro/supermicro.go | 2 +- providers/supermicro/x11.go | 2 +- providers/supermicro/x11_firmware_bios.go | 22 +++++++++---------- providers/supermicro/x11_firmware_bmc.go | 14 ++++++------ providers/supermicro/x11_firmware_bmc_test.go | 12 +++++----- providers/supermicro/x12.go | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/providers/supermicro/firmware.go b/providers/supermicro/firmware.go index b0540b04..e4a7c8ca 100644 --- a/providers/supermicro/firmware.go +++ b/providers/supermicro/firmware.go @@ -68,7 +68,7 @@ func (c *Client) FirmwareInstallUploaded(ctx context.Context, component, uploadT } // FirmwareTaskStatus returns the status of a firmware related task queued on the BMC. -func (c *Client) FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state, status string, err error) { +func (c *Client) FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state constants.TaskState, status string, err error) { if err := c.serviceClient.supportsFirmwareInstall(ctx, c.bmc.deviceModel()); err != nil { return "", "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, err.Error()) } diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index bb0e4818..47f167b9 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -104,7 +104,7 @@ type bmcQueryor interface { firmwareInstallSteps(component string) ([]constants.FirmwareInstallStep, error) firmwareUpload(ctx context.Context, component string, file *os.File) (taskID string, err error) firmwareInstallUploaded(ctx context.Context, component, uploadTaskID string) (installTaskID string, err error) - firmwareTaskStatus(ctx context.Context, component, taskID string) (state, status string, err error) + firmwareTaskStatus(ctx context.Context, component, taskID string) (state constants.TaskState, status string, err error) // query device model from the bmc queryDeviceModel(ctx context.Context) (model string, err error) // returns the device model, that was queried previously with queryDeviceModel diff --git a/providers/supermicro/x11.go b/providers/supermicro/x11.go index 705c29f2..08525e7a 100644 --- a/providers/supermicro/x11.go +++ b/providers/supermicro/x11.go @@ -131,7 +131,7 @@ func (c *x11) firmwareInstallUploaded(ctx context.Context, component, _ string) return "", errors.Wrap(bmclibErrs.ErrFirmwareInstallUploaded, "component unsupported: "+component) } -func (c *x11) firmwareTaskStatus(ctx context.Context, component, _ string) (state, status string, err error) { +func (c *x11) firmwareTaskStatus(ctx context.Context, component, _ string) (state constants.TaskState, status string, err error) { component = strings.ToUpper(component) switch component { diff --git a/providers/supermicro/x11_firmware_bios.go b/providers/supermicro/x11_firmware_bios.go index 255d43ee..0b989e2d 100644 --- a/providers/supermicro/x11_firmware_bios.go +++ b/providers/supermicro/x11_firmware_bios.go @@ -376,7 +376,7 @@ func (c *x11) setBIOSUpdateDone(ctx context.Context) error { } // statusBIOSFirmwareInstall returns the status of the firmware install process -func (c *x11) statusBIOSFirmwareInstall(ctx context.Context) (state, status string, err error) { +func (c *x11) statusBIOSFirmwareInstall(ctx context.Context) (state constants.TaskState, status string, err error) { payload := []byte(`fwtype=1&_`) headers := map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} @@ -393,7 +393,7 @@ func (c *x11) statusBIOSFirmwareInstall(ctx context.Context) (state, status stri // at the end of the install the BMC resets itself and the response is in HTML. if bytes.Contains(resp, []byte(``)) || !bytes.Contains(resp, []byte(``)) { // reopen session here, check firmware install status - return constants.FirmwareInstallUnknown, "session expired/unexpected response", bmclibErrs.ErrSessionExpired + return constants.Unknown, "session expired/unexpected response", bmclibErrs.ErrSessionExpired } // as long as the response is xml, the firmware install is running @@ -404,17 +404,17 @@ func (c *x11) statusBIOSFirmwareInstall(ctx context.Context) (state, status stri switch { // 1% indicates the file has been uploaded and the firmware install is not yet initiated case bytes.Contains(resp, []byte("0")) && bytes.Contains(resp, []byte("1")): - return constants.FirmwareInstallFailed, percent, bmclibErrs.ErrBMCColdResetRequired + return constants.Failed, percent, bmclibErrs.ErrBMCColdResetRequired // 0% along with the check on the component endpoint indicates theres no update in progress case (bytes.Contains(resp, []byte("0")) && bytes.Contains(resp, []byte("0"))): if err := c.checkComponentUpdateMisc(ctx, "postUpdate"); err != nil { if errors.Is(err, bmclibErrs.ErrHostPowercycleRequired) { - return constants.FirmwareInstallPowerCycleHost, percent, nil + return constants.PowerCycleHost, percent, nil } } - return constants.FirmwareInstallComplete, "all done!", nil + return constants.Complete, "all done!", nil // status 0 and 100% indicates the update is complete and requires a few post update calls case bytes.Contains(resp, []byte("0")) && bytes.Contains(resp, []byte("100")): @@ -427,22 +427,22 @@ func (c *x11) statusBIOSFirmwareInstall(ctx context.Context) (state, status stri // tells the BMC it can get out of the BIOS update mode if err := c.checkComponentUpdateMisc(ctx, "postUpdate"); err != nil { if errors.Is(err, bmclibErrs.ErrHostPowercycleRequired) { - return constants.FirmwareInstallPowerCycleHost, percent, nil + return constants.PowerCycleHost, percent, nil } - return constants.FirmwareInstallPowerCycleHost, percent, err + return constants.PowerCycleHost, percent, err } - return constants.FirmwareInstallPowerCycleHost, percent, nil + return constants.PowerCycleHost, percent, nil // status 8 and percent 0 indicates its initializing the update case bytes.Contains(resp, []byte("8")) && bytes.Contains(resp, []byte("0")): - return constants.FirmwareInstallRunning, percent, nil + return constants.Running, percent, nil // status 8 and any other percent value indicates its running case bytes.Contains(resp, []byte("8")) && bytes.Contains(resp, []byte("")): - return constants.FirmwareInstallRunning, percent, nil + return constants.Running, percent, nil } - return constants.FirmwareInstallUnknown, "", nil + return constants.Unknown, "", nil } diff --git a/providers/supermicro/x11_firmware_bmc.go b/providers/supermicro/x11_firmware_bmc.go index 39ec304a..246aa5e8 100644 --- a/providers/supermicro/x11_firmware_bmc.go +++ b/providers/supermicro/x11_firmware_bmc.go @@ -243,24 +243,24 @@ func (c *x11) initiateBMCFirmwareInstall(ctx context.Context) error { } // statusBMCFirmwareInstall returns the status of the firmware install process -func (c *x11) statusBMCFirmwareInstall(ctx context.Context) (state, status string, err error) { +func (c *x11) statusBMCFirmwareInstall(ctx context.Context) (state constants.TaskState, status string, err error) { payload := []byte(`fwtype=0&_`) headers := map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} resp, httpStatus, err := c.query(ctx, "cgi/upgrade_process.cgi", http.MethodPost, bytes.NewReader(payload), headers, 0) if err != nil { - return constants.FirmwareInstallUnknown, "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, err.Error()) + return constants.Unknown, "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, err.Error()) } if httpStatus != http.StatusOK { - return constants.FirmwareInstallUnknown, "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, "Unexpected http status code: "+strconv.Itoa(httpStatus)) + return constants.Unknown, "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, "Unexpected http status code: "+strconv.Itoa(httpStatus)) } // if theres html or no xml in the response, the session expired // at the end of the install the BMC resets itself and the response is in HTML. if bytes.Contains(resp, []byte(``)) || !bytes.Contains(resp, []byte(``)) { // reopen session here, check firmware install status - return constants.FirmwareInstallUnknown, "session expired/unexpected response", bmclibErrs.ErrSessionExpired + return constants.Unknown, "session expired/unexpected response", bmclibErrs.ErrSessionExpired } // as long as the response is xml, the firmware install is running @@ -274,12 +274,12 @@ func (c *x11) statusBMCFirmwareInstall(ctx context.Context) (state, status strin // // 0% indicates its either not running or complete case "0%", "100%": - return constants.FirmwareInstallComplete, percent, nil + return constants.Complete, percent, nil // until 2% its initializing case "1%", "2%": - return constants.FirmwareInstallInitializing, percent, nil + return constants.Initializing, percent, nil // any other percent value indicates its active default: - return constants.FirmwareInstallRunning, percent, nil + return constants.Running, percent, nil } } diff --git a/providers/supermicro/x11_firmware_bmc_test.go b/providers/supermicro/x11_firmware_bmc_test.go index b6b0ad13..9c7024f5 100644 --- a/providers/supermicro/x11_firmware_bmc_test.go +++ b/providers/supermicro/x11_firmware_bmc_test.go @@ -366,7 +366,7 @@ func TestX11InitiateBMCFirmwareInstall(t *testing.T) { func TestX11StatusBMCFirmwareInstall(t *testing.T) { testcases := []struct { name string - expectState string + expectState constants.TaskState expectStatus string errorContains string endpoint string @@ -374,7 +374,7 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) { }{ { "state complete 0", - constants.FirmwareInstallComplete, + constants.Complete, "0%", "", "/cgi/upgrade_process.cgi", @@ -399,7 +399,7 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) { }, { "state complete 100", - constants.FirmwareInstallComplete, + constants.Complete, "100%", "", "/cgi/upgrade_process.cgi", @@ -424,7 +424,7 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) { }, { "state initializing", - constants.FirmwareInstallInitializing, + constants.Initializing, "1%", "", "/cgi/upgrade_process.cgi", @@ -449,7 +449,7 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) { }, { "status running", - constants.FirmwareInstallRunning, + constants.Running, "95%", "", "/cgi/upgrade_process.cgi", @@ -474,7 +474,7 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) { }, { "status unknown", - constants.FirmwareInstallUnknown, + constants.Unknown, "", "session expired", "/cgi/upgrade_process.cgi", diff --git a/providers/supermicro/x12.go b/providers/supermicro/x12.go index e027d858..a48c0006 100644 --- a/providers/supermicro/x12.go +++ b/providers/supermicro/x12.go @@ -294,7 +294,7 @@ func (c *x12) firmwareInstallUploaded(ctx context.Context, component, uploadTask return c.redfish.StartUpdateForUploadedFirmware(ctx) } -func (c *x12) firmwareTaskStatus(ctx context.Context, component, taskID string) (state, status string, err error) { +func (c *x12) firmwareTaskStatus(ctx context.Context, component, taskID string) (state constants.TaskState, status string, err error) { if err = c.supportsInstall(component); err != nil { return "", "", errors.Wrap(brrs.ErrFirmwareTaskStatus, err.Error()) }