Skip to content

Commit

Permalink
Merge pull request #357 from bmc-toolbox/fs-989-e3c256d4i-support
Browse files Browse the repository at this point in the history
e3c256d4i support
  • Loading branch information
ofaurax authored Oct 30, 2023
2 parents 153e11d + e63714c commit 25d7063
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
20 changes: 18 additions & 2 deletions providers/asrockrack/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,30 @@ 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 {
return errors.Wrap(err, "failed in step 1/4 - set device to flash mode")
}

// 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")
}
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion providers/asrockrack/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion providers/asrockrack/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 25d7063

Please sign in to comment.