Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e3c256d4i support #357

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) 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")

Check warning on line 71 in providers/asrockrack/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/asrockrack/firmware.go#L71

Added line #L71 was not covered by tests
}

// 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"

Check warning on line 86 in providers/asrockrack/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/asrockrack/firmware.go#L86

Added line #L86 was not covered by tests
}
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 @@
switch progress.State {
case 0:
return constants.FirmwareInstallRunning, nil
case 1: // "Flashing To be done"
return constants.FirmwareInstallQueued, nil

Check warning on line 164 in providers/asrockrack/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/asrockrack/firmware.go#L163-L164

Added lines #L163 - L164 were not covered by tests
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 @@
"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 @@
// 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}

Check warning on line 193 in providers/asrockrack/helpers.go

View check run for this annotation

Codecov / codecov/patch

providers/asrockrack/helpers.go#L193

Added line #L193 was not covered by tests
}

payload, err := json.Marshal(pConfig)
if err != nil {
return err

Check warning on line 198 in providers/asrockrack/helpers.go

View check run for this annotation

Codecov / codecov/patch

providers/asrockrack/helpers.go#L198

Added line #L198 was not covered by tests
}

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