diff --git a/providers/asrockrack/firmware.go b/providers/asrockrack/firmware.go index f1eb111b..12253907 100644 --- a/providers/asrockrack/firmware.go +++ b/providers/asrockrack/firmware.go @@ -63,7 +63,16 @@ func (a *ASRockRack) FirmwareInstallStatus(ctx context.Context, installVersion, func (a *ASRockRack) firmwareInstallBMC(ctx context.Context, reader io.Reader, fileSize int64) error { var err error + // 0. take the model so that we use a different endpoint on E3C256D4ID-NL + device := common.NewDevice() + device.Metadata = map[string]string{} + err = a.fruAttributes(ctx, &device) + if err != nil { + return errors.Wrap(err, "failed to get model in step 0/4") + } + // 1. set the device to flash mode - prepares the flash + // Beware: this locks some capabilities, e.g. the access to fruAttributes a.log.V(2).WithValues("step", "1/4").Info("set device to flash mode, takes a minute...") err = a.setFlashMode(ctx) if err != nil { @@ -71,8 +80,13 @@ func (a *ASRockRack) firmwareInstallBMC(ctx context.Context, reader io.Reader, f } // 2. upload firmware image file - a.log.V(2).WithValues("step", "2/4").Info("upload BMC firmware image") - err = a.uploadFirmware(ctx, "api/maintenance/firmware", reader, fileSize) + fwEndpoint := "api/maintenance/firmware" + // E3C256D4ID-NL calls a different endpoint for firmware upload + if strings.EqualFold(device.Model, "E3C256D4ID-NL") { + fwEndpoint = "api/maintenance/firmware/firmware" + } + a.log.V(2).WithValues("step", "2/4").Info("upload BMC firmware image to " + fwEndpoint) + err = a.uploadFirmware(ctx, fwEndpoint, reader, fileSize) if err != nil { return errors.Wrap(err, "failed in step 2/4 - upload BMC firmware image") } @@ -146,6 +160,8 @@ func (a *ASRockRack) firmwareUpdateStatus(ctx context.Context, component string, switch progress.State { case 0: return constants.FirmwareInstallRunning, nil + case 1: // "Flashing To be done" + return constants.FirmwareInstallQueued, nil case 2: return constants.FirmwareInstallComplete, nil default: diff --git a/providers/asrockrack/helpers.go b/providers/asrockrack/helpers.go index 3ff46bc5..6cf677a6 100644 --- a/providers/asrockrack/helpers.go +++ b/providers/asrockrack/helpers.go @@ -10,9 +10,11 @@ import ( "net/http" "net/http/httputil" "os" + "strings" "github.com/bmc-toolbox/bmclib/v2/constants" "github.com/bmc-toolbox/bmclib/v2/errors" + "github.com/bmc-toolbox/common" ) // API session setup response payload @@ -181,7 +183,23 @@ func (a *ASRockRack) createUpdateUser(ctx context.Context, account *UserAccount) // at this point all logged in sessions are terminated // and no logins are permitted func (a *ASRockRack) setFlashMode(ctx context.Context) error { - _, statusCode, err := a.queryHTTPS(ctx, "api/maintenance/flash", "PUT", nil, nil, 0) + device := common.NewDevice() + device.Metadata = map[string]string{} + _ = a.fruAttributes(ctx, &device) + + pConfig := &preserveConfig{} + // preserve config is needed by e3c256d4i + if strings.EqualFold(device.Model, "E3C256D4ID-NL") { + pConfig = &preserveConfig{PreserveConfig: 1} + } + + payload, err := json.Marshal(pConfig) + if err != nil { + return err + } + + headers := map[string]string{"Content-Type": "application/json"} + _, statusCode, err := a.queryHTTPS(ctx, "api/maintenance/flash", "PUT", bytes.NewReader(payload), headers, 0) if err != nil { return err } diff --git a/providers/asrockrack/mock_test.go b/providers/asrockrack/mock_test.go index 3a603480..091697ed 100644 --- a/providers/asrockrack/mock_test.go +++ b/providers/asrockrack/mock_test.go @@ -82,6 +82,7 @@ func mockASRockBMC() *httptest.Server { // fw update endpoints - in order of invocation handler.HandleFunc("/api/maintenance/flash", bmcFirmwareUpgrade) handler.HandleFunc("/api/maintenance/firmware", bmcFirmwareUpgrade) + handler.HandleFunc("/api/maintenance/firmware/firmware", bmcFirmwareUpgrade) handler.HandleFunc("/api/maintenance/firmware/verification", bmcFirmwareUpgrade) handler.HandleFunc("/api/maintenance/firmware/upgrade", bmcFirmwareUpgrade) handler.HandleFunc("/api/maintenance/firmware/flash-progress", bmcFirmwareUpgrade) @@ -211,7 +212,7 @@ func bmcFirmwareUpgrade(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) // 2. upload firmware - case "/api/maintenance/firmware": + case "/api/maintenance/firmware", "/api/maintenance/firmware/firmware": // validate flash mode set if !fwUpgradeState.FlashModeSet {