Skip to content

Commit

Permalink
add firmware validation client function (#271)
Browse files Browse the repository at this point in the history
* add firmware validation client function

* Update push-pr-lint.yaml
  • Loading branch information
DoctorVin authored Oct 17, 2024
1 parent efc6f71 commit 6b92281
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-pr-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
args: --config .golangci.yml --timeout 2m
version: v1.57.1
version: v1.61.0
skip-cache: true

- name: Test
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ linters:
# additional linters
- bodyclose
- gocritic
- goerr113
- err113
- goimports
- revive
- misspell
Expand All @@ -80,7 +80,6 @@ linters:
- nilerr
- reassign
- whitespace
- exportloopref
enable-all: false
disable-all: true

Expand Down
5 changes: 5 additions & 0 deletions pkg/api/v1/conditions/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func (c *Client) ServerBiosControl(ctx context.Context,
return c.post(ctx, path, params)
}

func (c *Client) ValidateFirmwareSet(ctx context.Context,
params *v1types.FirmwareValidationRequest) (*v1types.ServerResponse, error) {
return c.post(ctx, "validateFirmware", params)
}

func (c *Client) ServerConditionCreate(ctx context.Context, serverID uuid.UUID, conditionKind rctypes.Kind, conditionCreate v1types.ConditionCreate) (*v1types.ServerResponse, error) {
path := fmt.Sprintf("servers/%s/condition/%s", serverID.String(), conditionKind)

Expand Down
15 changes: 2 additions & 13 deletions pkg/api/v1/conditions/routes/firmware_validation_handlers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package routes

import (
"encoding/json"
"net/http"
"time"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -18,17 +16,8 @@ import (
v1types "github.com/metal-toolbox/conditionorc/pkg/api/v1/conditions/types"
)

type FirmwareValidationRequest struct {
ServerID uuid.UUID `json:"server_id" binding:"required,uuid4_rfc4122"`
FirmwareSetID uuid.UUID `json:"firmware_set_id" binding:"required,uuid4_rfc4122"`
}

func (fvr FirmwareValidationRequest) AsJSON() (json.RawMessage, error) {
return json.Marshal(fvr)
}

// this is where we compose all conditions to be executed during the firmware validation task
func firmwareValidationConditions(fvr FirmwareValidationRequest) *rctypes.ServerConditions {
func firmwareValidationConditions(fvr *v1types.FirmwareValidationRequest) *rctypes.ServerConditions {
createTime := time.Now()

fwParams := &rctypes.FirmwareInstallTaskParameters{
Expand Down Expand Up @@ -88,7 +77,7 @@ func (r *Routes) validateFirmware(c *gin.Context) (int, *v1types.ServerResponse)
otelCtx, span := otel.Tracer(pkgName).Start(c.Request.Context(), "Routes.validateFirmware")
defer span.End()

var fvr FirmwareValidationRequest
fvr := &v1types.FirmwareValidationRequest{}
if err := c.ShouldBindJSON(&fvr); err != nil {
r.logger.WithError(err).Warn("unmarshal firmware validation payload")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/google/uuid"
"github.com/metal-toolbox/conditionorc/internal/model"
"github.com/metal-toolbox/conditionorc/internal/store"
v1types "github.com/metal-toolbox/conditionorc/pkg/api/v1/conditions/types"
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestValidateFirmware(t *testing.T) {
_, fleetdb, _, server, err := setupTestServer(t)
require.NoError(t, err, "prerequisite setup")

fvr, err := FirmwareValidationRequest{
fvr, err := v1types.FirmwareValidationRequest{
ServerID: uuid.New(),
FirmwareSetID: uuid.New(),
}.AsJSON()
Expand All @@ -65,7 +66,7 @@ func TestValidateFirmware(t *testing.T) {
FacilityCode: "fc13",
}

fvr, err := FirmwareValidationRequest{
fvr, err := v1types.FirmwareValidationRequest{
ServerID: srv.ID,
FirmwareSetID: uuid.New(),
}.AsJSON()
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestValidateFirmware(t *testing.T) {
FacilityCode: "fc13",
}

fvr, err := FirmwareValidationRequest{
fvr, err := v1types.FirmwareValidationRequest{
ServerID: srv.ID,
FirmwareSetID: uuid.New(),
}.AsJSON()
Expand Down Expand Up @@ -133,7 +134,7 @@ func TestValidateFirmware(t *testing.T) {
FacilityCode: "fc13",
}

fvr, err := FirmwareValidationRequest{
fvr, err := v1types.FirmwareValidationRequest{
ServerID: srv.ID,
FirmwareSetID: uuid.New(),
}.AsJSON()
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/v1/conditions/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,12 @@ type ServerProvisionRequest struct {
NetworkConfiguration string `json:"NetworkConfiguration,omitempty"`
Tags []string `json:"Tags,omitempty"`
}

type FirmwareValidationRequest struct {
ServerID uuid.UUID `json:"server_id" binding:"required,uuid4_rfc4122"`
FirmwareSetID uuid.UUID `json:"firmware_set_id" binding:"required,uuid4_rfc4122"`
}

func (fvr FirmwareValidationRequest) AsJSON() (json.RawMessage, error) {
return json.Marshal(fvr)
}

0 comments on commit 6b92281

Please sign in to comment.