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

port to gofish/redfish v0.19.0 #395

Merged
merged 6 commits into from
Sep 24, 2024
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
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ func TestOpenFiltered(t *testing.T) {
defer cl.Close(context.Background())
want := []string{"tester3", "tester1", "tester2"}
if diff := cmp.Diff(cl.GetMetadata().ProvidersAttempted, want); diff != "" {
t.Errorf(diff)
t.Errorf("diff: %s", diff)
}
want = []string{"tester1", "tester2", "tester3"}
if diff := cmp.Diff(registryNames(cl.Registry.Drivers), want); diff != "" {
t.Errorf(diff)
t.Errorf("diff: %s", diff)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bmc-toolbox/bmclib/v2

go 1.18
go 1.21

require (
dario.cat/mergo v1.0.0
Expand All @@ -17,7 +17,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/sirupsen/logrus v1.9.3
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91
github.com/stmcginnis/gofish v0.19.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230 h1:t95Grn2
github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230/go.mod h1:t2EzW1qybnPDQ3LR/GgeF0GOzHUXT5IVMLP2gkW1cmc=
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 h1:a0MBqYm44o0NcthLKCljZHe1mxlN6oahCQHHThnSwB4=
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22/go.mod h1:/B7V22rcz4860iDqstGvia/2+IYWXf3/JdQCVd/1D2A=
github.com/bmc-toolbox/common v0.0.0-20240805193945-ce25765471a7 h1:+NcnInwZxn25daBCb3d1y3x9QF23uob1ghdiimj2Dwo=
github.com/bmc-toolbox/common v0.0.0-20240805193945-ce25765471a7/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3 h1:/BjZSX/sphptIdxpYo4wxAQkgMLyMMgfdl48J9DKNeE=
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=
Expand Down Expand Up @@ -61,8 +59,8 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91 h1:WmABtU8y6kTgzoVUn3FWCQGAfyodve3uz3xno28BrRs=
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91/go.mod h1:BLDSFTp8pDlf/xDbLZa+F7f7eW0E/CHCboggsu8CznI=
github.com/stmcginnis/gofish v0.19.0 h1:fmxdRZ5WHfs+4ExArMYoeRfoh+SAxLELKtmoVplBkU4=
github.com/stmcginnis/gofish v0.19.0/go.mod h1:lq2jHj2t8Krg0Gx02ABk8MbK7Dz9jvWpO/TGnVksn00=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
11 changes: 9 additions & 2 deletions internal/redfishwrapper/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const (
multipartHttpUpload installMethod = "multipartUpload"
)

var (
// the URI for starting a firmware update via StartUpdate is defined in the Redfish Resource and
// Schema Guide (2024.1)
startUpdateURI = "redfish/v1/UpdateService/Actions/UpdateService.StartUpdate"
)

var (
errMultiPartPayload = errors.New("error preparing multipart payload")
errUpdateParams = errors.New("error in redfish UpdateParameters payload")
Expand Down Expand Up @@ -117,8 +123,9 @@ func (c *Client) StartUpdateForUploadedFirmware(ctx context.Context) (taskID str
return "", errors.Wrap(err, "error querying redfish update service")
}

// start update
resp, err := updateService.GetClient().PostWithHeaders(updateService.StartUpdateTarget, nil, nil)
// Start update the hard way. We do this to get back the task object from the response body so that
// we can parse the task id out of it.
resp, err := updateService.GetClient().PostWithHeaders(startUpdateURI, nil, nil)
if err != nil {
return "", errors.Wrap(err, "error querying redfish start update endpoint")
}
Expand Down
14 changes: 7 additions & 7 deletions providers/asrockrack/asrockrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestHttpLogin(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

assert.Equal(t, "l5L29IP7", aClient.loginSession.CSRFToken)
Expand All @@ -21,30 +21,30 @@ func TestHttpLogin(t *testing.T) {
func TestClose(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login setup: %s", err.Error())
}

err = aClient.httpsLogout(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("logout: %s", err.Error())
}
}

func TestFirwmwareUpdateBMC(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

upgradeFile := "/tmp/dummy-E3C246D4I-NL_L0.01.00.ima"
_, err = os.Create(upgradeFile)
if err != nil {
t.Errorf(err.Error())
t.Errorf("create file: %s", err.Error())
}

fh, err := os.Open(upgradeFile)
if err != nil {
t.Errorf(err.Error())
t.Errorf("file open: %s", err.Error())
}

defer fh.Close()
Expand All @@ -53,6 +53,6 @@ func TestFirwmwareUpdateBMC(t *testing.T) {

err = aClient.firmwareUploadBMC(ctx, fh)
if err != nil {
t.Errorf(err.Error())
t.Errorf("upload: %s", err.Error())
}
}
9 changes: 4 additions & 5 deletions providers/asrockrack/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/bmc-toolbox/bmclib/v2/constants"
brrs "github.com/bmc-toolbox/bmclib/v2/errors"
"github.com/bmc-toolbox/common"
"github.com/pkg/errors"
)

// API session setup response payload
Expand Down Expand Up @@ -229,7 +228,7 @@ func (a *ASRockRack) uploadFirmware(ctx context.Context, endpoint string, file *
var size int64
finfo, err := file.Stat()
if err != nil {
return errors.Wrap(err, "unable to determine file size")
return fmt.Errorf("unable to determine file size: %w", err)
}

size = finfo.Size()
Expand Down Expand Up @@ -558,7 +557,7 @@ func (a *ASRockRack) httpsLogin(ctx context.Context) error {

resp, statusCode, err := a.queryHTTPS(ctx, urlEndpoint, "POST", bytes.NewReader(payload), headers, 0)
if err != nil {
return fmt.Errorf("Error logging in: " + err.Error())
return fmt.Errorf("logging in: %w", err)
}

if statusCode == 401 {
Expand All @@ -568,7 +567,7 @@ func (a *ASRockRack) httpsLogin(ctx context.Context) error {
// Unmarshal login session
err = json.Unmarshal(resp, a.loginSession)
if err != nil {
return fmt.Errorf("error unmarshalling response payload: " + err.Error())
return fmt.Errorf("unmarshalling response payload: %w", err)
}

return nil
Expand All @@ -578,7 +577,7 @@ func (a *ASRockRack) httpsLogin(ctx context.Context) error {
func (a *ASRockRack) httpsLogout(ctx context.Context) error {
_, statusCode, err := a.queryHTTPS(ctx, "api/session", "DELETE", nil, nil, 0)
if err != nil {
return fmt.Errorf("Error logging out: " + err.Error())
return fmt.Errorf("logging out: %w", err)
}

if statusCode != http.StatusOK {
Expand Down
14 changes: 7 additions & 7 deletions providers/asrockrack/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func Test_FirmwareInfo(t *testing.T) {

err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

fwInfo, err := aClient.firmwareInfo(context.TODO())
if err != nil {
t.Error(err.Error())
t.Errorf("firmwareInfo: %s", err.Error())
}

assert.Equal(t, expected, fwInfo)
Expand All @@ -35,7 +35,7 @@ func Test_FirmwareInfo(t *testing.T) {
func TestInventoryInfo(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

inventory, err := aClient.inventoryInfoE3C246D41D(context.TODO())
Expand All @@ -50,7 +50,7 @@ func TestInventoryInfo(t *testing.T) {
func Test_fruInfo(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

frus, err := aClient.fruInfo(context.TODO())
Expand All @@ -64,7 +64,7 @@ func Test_fruInfo(t *testing.T) {
func Test_sensors(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

sensors, err := aClient.sensors(context.TODO())
Expand All @@ -83,7 +83,7 @@ func Test_biosPOSTCode(t *testing.T) {

err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

info, err := aClient.postCodeInfo(context.TODO())
Expand All @@ -102,7 +102,7 @@ func Test_chassisStatus(t *testing.T) {

err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

info, err := aClient.chassisStatusInfo(context.TODO())
Expand Down
6 changes: 3 additions & 3 deletions providers/asrockrack/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Test_UserRead(t *testing.T) {

err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

users, err := aClient.UserRead(context.TODO())
Expand Down Expand Up @@ -159,7 +159,7 @@ func Test_UserUpdate(t *testing.T) {
func Test_createUser(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

account := &UserAccount{
Expand Down Expand Up @@ -202,7 +202,7 @@ func Test_createUser(t *testing.T) {
func Test_userAccounts(t *testing.T) {
err := aClient.httpsLogin(context.TODO())
if err != nil {
t.Errorf(err.Error())
t.Errorf("login: %s", err.Error())
}

account0 := &UserAccount{
Expand Down
Loading