From a8a25845a658bd8299f2924c0b8e3b6f893ee808 Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Thu, 19 Sep 2024 14:40:08 -0400 Subject: [PATCH 1/6] port to gofish/redfish v0.19.0 --- go.mod | 2 +- go.sum | 6 ++---- internal/redfishwrapper/firmware.go | 11 +++++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 855d5ba3..256f980f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c6c8301e..58a0ef34 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/redfishwrapper/firmware.go b/internal/redfishwrapper/firmware.go index 08ac4976..81c3f1a5 100644 --- a/internal/redfishwrapper/firmware.go +++ b/internal/redfishwrapper/firmware.go @@ -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") @@ -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") } From 8299d61c114a78ef3711698e11db6c81e74c71cb Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Thu, 19 Sep 2024 15:46:45 -0400 Subject: [PATCH 2/6] update toolchain, golangci-lint, fix linting issues --- client_test.go | 4 ++-- go.mod | 2 +- lint.mk | 2 +- providers/asrockrack/asrockrack_test.go | 14 +++++++------- providers/asrockrack/helpers.go | 6 +++--- providers/asrockrack/helpers_test.go | 14 +++++++------- providers/asrockrack/user_test.go | 6 +++--- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client_test.go b/client_test.go index 321a7e25..4b25deb1 100644 --- a/client_test.go +++ b/client_test.go @@ -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) } } diff --git a/go.mod b/go.mod index 256f980f..9466f20e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bmc-toolbox/bmclib/v2 -go 1.18 +go 1.23 require ( dario.cat/mergo v1.0.0 diff --git a/lint.mk b/lint.mk index d492cc70..09ba98fd 100644 --- a/lint.mk +++ b/lint.mk @@ -20,7 +20,7 @@ LINTERS := FIXERS := GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml -GOLANGCI_LINT_VERSION ?= v1.53.3 +GOLANGCI_LINT_VERSION ?= v1.61.0 GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) $(GOLANGCI_LINT_BIN): mkdir -p $(LINT_ROOT)/out/linters diff --git a/providers/asrockrack/asrockrack_test.go b/providers/asrockrack/asrockrack_test.go index 755207b7..ce9a1b3f 100644 --- a/providers/asrockrack/asrockrack_test.go +++ b/providers/asrockrack/asrockrack_test.go @@ -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) @@ -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() @@ -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()) } } diff --git a/providers/asrockrack/helpers.go b/providers/asrockrack/helpers.go index 503bda88..7f693451 100644 --- a/providers/asrockrack/helpers.go +++ b/providers/asrockrack/helpers.go @@ -558,7 +558,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 errors.Wrap(err, "logging in") } if statusCode == 401 { @@ -568,7 +568,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 errors.Wrap(err, "unmarshalling response payload") } return nil @@ -578,7 +578,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 errors.Wrap(err, "logging out") } if statusCode != http.StatusOK { diff --git a/providers/asrockrack/helpers_test.go b/providers/asrockrack/helpers_test.go index 83752b75..88d41452 100644 --- a/providers/asrockrack/helpers_test.go +++ b/providers/asrockrack/helpers_test.go @@ -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) @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/providers/asrockrack/user_test.go b/providers/asrockrack/user_test.go index dc4dd857..38d2a9b8 100644 --- a/providers/asrockrack/user_test.go +++ b/providers/asrockrack/user_test.go @@ -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()) @@ -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{ @@ -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{ From 7efea57286c895e5ead327da7c25e57a4e340f8b Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Fri, 20 Sep 2024 13:32:13 -0400 Subject: [PATCH 3/6] don't use errors.Wrap in new code --- providers/asrockrack/helpers.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/providers/asrockrack/helpers.go b/providers/asrockrack/helpers.go index 7f693451..c562e746 100644 --- a/providers/asrockrack/helpers.go +++ b/providers/asrockrack/helpers.go @@ -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 @@ -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() @@ -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 errors.Wrap(err, "logging in") + return fmt.Errorf("logging in: %w", err) } if statusCode == 401 { @@ -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 errors.Wrap(err, "unmarshalling response payload") + return fmt.Errorf("unmarshalling response payload: %w", err) } return nil @@ -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 errors.Wrap(err, "logging out") + return fmt.Errorf("logging out: %w", err) } if statusCode != http.StatusOK { From 30bb34322610c3c36fe3a8ce1691bc5f39742c03 Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Tue, 24 Sep 2024 11:11:32 -0400 Subject: [PATCH 4/6] stay on go 1.18 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9466f20e..256f980f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bmc-toolbox/bmclib/v2 -go 1.23 +go 1.18 require ( dario.cat/mergo v1.0.0 From 8c200565ed58326a3bf9332de8bd5e289bf7ff85 Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Tue, 24 Sep 2024 11:15:41 -0400 Subject: [PATCH 5/6] revert upgrade of golangci-lint --- lint.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lint.mk b/lint.mk index 09ba98fd..d492cc70 100644 --- a/lint.mk +++ b/lint.mk @@ -20,7 +20,7 @@ LINTERS := FIXERS := GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml -GOLANGCI_LINT_VERSION ?= v1.61.0 +GOLANGCI_LINT_VERSION ?= v1.53.3 GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) $(GOLANGCI_LINT_BIN): mkdir -p $(LINT_ROOT)/out/linters From efb62c2412729823b75f805e709dafc269e4b27c Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Tue, 24 Sep 2024 11:21:04 -0400 Subject: [PATCH 6/6] go 1.21 is required for redfish v0.19.0 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 256f980f..2370ec26 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bmc-toolbox/bmclib/v2 -go 1.18 +go 1.21 require ( dario.cat/mergo v1.0.0