Skip to content

Commit

Permalink
outofband: use rivets.Server instead of model.Asset
Browse files Browse the repository at this point in the history
This is based on the changes in the previous commit
  • Loading branch information
joelrebel committed Aug 15, 2024
1 parent a7f6d33 commit 8d2b1e2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
38 changes: 19 additions & 19 deletions internal/outofband/action_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (h *handler) serverPoweredOff(ctx context.Context) (bool, error) {
// init out of band device queryor - if one isn't already initialized
// this is done conditionally to enable tests to pass in a device queryor
if h.deviceQueryor == nil {
h.deviceQueryor = NewDeviceQueryor(ctx, h.task.Asset, h.logger)
h.deviceQueryor = NewDeviceQueryor(ctx, h.task.Server, h.logger)
}

if err := h.deviceQueryor.Open(ctx); err != nil {
Expand Down Expand Up @@ -181,7 +181,7 @@ func (h *handler) installedEqualsExpected(ctx context.Context, component, expect
return err
}

found := components.BySlugModel(component, models)
found := components.ByNameModel(component, models)
if found == nil {
h.logger.WithFields(
logrus.Fields{
Expand All @@ -201,22 +201,22 @@ func (h *handler) installedEqualsExpected(ctx context.Context, component, expect

h.logger.WithFields(
logrus.Fields{
"component": found.Slug,
"component": found.Name,
"vendor": found.Vendor,
"model": found.Model,
"serial": found.Serial,
"current": found.FirmwareInstalled,
"current": found.Firmware.Installed,
"expected": expectedFirmware,
}).Debug("component version check")

if strings.TrimSpace(found.FirmwareInstalled) == "" {
if strings.TrimSpace(found.Firmware.Installed) == "" {
return ErrInstalledVersionUnknown
}

if !strings.EqualFold(expectedFirmware, found.FirmwareInstalled) {
if !strings.EqualFold(expectedFirmware, found.Firmware.Installed) {
return errors.Wrap(
ErrInstalledFirmwareNotEqual,
fmt.Sprintf("expected: %s, current: %s", expectedFirmware, found.FirmwareInstalled),
fmt.Sprintf("expected: %s, current: %s", expectedFirmware, found.Firmware.Installed),
)
}

Expand Down Expand Up @@ -500,7 +500,7 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
logrus.Fields{
"component": h.action.Firmware.Component,
"version": h.action.Firmware.Version,
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"step": h.action.FirmwareInstallStep,
"installTask": installTask,
}).Info("polling BMC for firmware task status")
Expand Down Expand Up @@ -548,7 +548,7 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
case nil:
h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
}).Debug("Installed firmware matches expected.")

Expand All @@ -567,7 +567,7 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
attemptErrors = multierror.Append(attemptErrors, err)
h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
"elapsed": time.Since(startTS).String(),
"attempts": fmt.Sprintf("attempt %d/%d", attempts, maxPollStatusAttempts),
Expand All @@ -592,7 +592,7 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
"component": h.firmware.Component,
"update": h.firmware.FileName,
"version": h.firmware.Version,
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"elapsed": time.Since(startTS).String(),
"attempts": fmt.Sprintf("attempt %d/%d", attempts, maxPollStatusAttempts),
"taskState": state,
Expand Down Expand Up @@ -625,7 +625,7 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
if componentIsBMC(h.action.Firmware.Component) && installTask {
h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"delay": delayBMCReset.String(),
"taskState": state,
"bmcTaskID": h.action.BMCTaskID,
Expand Down Expand Up @@ -691,15 +691,15 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
if err := h.powerCycleBMC(ctx); err != nil {
h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
"err": err.Error(),
}).Debug("install failure required a BMC reset, reset returned error")
}

h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
}).Debug("BMC reset for failed BMC firmware install")
}
Expand All @@ -719,15 +719,15 @@ func (h *handler) pollFirmwareTaskStatus(ctx context.Context) error {
if errBmcReset := h.powerCycleBMC(ctx); errBmcReset != nil {
h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
"err": errBmcReset.Error(),
}).Debug("install success required a BMC reset, reset returned error")
}

h.logger.WithFields(
logrus.Fields{
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
"component": h.firmware.Component,
}).Debug("BMC reset for successful BMC firmware install")
}
Expand All @@ -747,7 +747,7 @@ func (h *handler) resetBMC(ctx context.Context) error {
h.logger.WithFields(
logrus.Fields{
"component": h.firmware.Component,
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
}).Info("resetting BMC, delay introduced: " + delayBMCReset.String())

err := h.powerCycleBMC(ctx)
Expand Down Expand Up @@ -778,7 +778,7 @@ func (h *handler) powerCycleServer(ctx context.Context) error {
h.logger.WithFields(
logrus.Fields{
"component": h.firmware.Component,
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
}).Info("resetting host for firmware install")

return h.deviceQueryor.SetPowerState(ctx, "cycle")
Expand Down Expand Up @@ -822,7 +822,7 @@ func (h *handler) powerOffServer(ctx context.Context) error {
h.logger.WithFields(
logrus.Fields{
"component": h.firmware.Component,
"bmc": h.task.Asset.BmcAddress,
"bmc": h.task.Server.BMCAddress,
}).Debug("powering off device")

if err := h.deviceQueryor.SetPowerState(ctx, "off"); err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/outofband/action_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/metal-toolbox/flasher/internal/model"
"github.com/metal-toolbox/flasher/internal/runner"
rctypes "github.com/metal-toolbox/rivets/condition"
rtypes "github.com/metal-toolbox/rivets/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion internal/outofband/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func initHandler(actionCtx *runner.ActionHandlerContext, queryor device.Queryor)
func (o *ActionHandler) ComposeAction(ctx context.Context, actionCtx *runner.ActionHandlerContext) (*model.Action, error) {
var deviceQueryor device.Queryor
if actionCtx.DeviceQueryor == nil {
deviceQueryor = NewDeviceQueryor(ctx, actionCtx.Task.Asset, actionCtx.Logger)
deviceQueryor = NewDeviceQueryor(ctx, actionCtx.Task.Server, actionCtx.Logger)
} else {
deviceQueryor = actionCtx.DeviceQueryor
}
Expand Down
5 changes: 3 additions & 2 deletions internal/outofband/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/metal-toolbox/flasher/internal/model"
"github.com/metal-toolbox/flasher/internal/runner"
rctypes "github.com/metal-toolbox/rivets/condition"
rtypes "github.com/metal-toolbox/rivets/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -19,8 +20,8 @@ func TestComposeAction(t *testing.T) {
return &runner.ActionHandlerContext{
TaskHandlerContext: &runner.TaskHandlerContext{
Task: &model.Task{
Parameters: rctypes.FirmwareInstallTaskParameters{},
Asset: &model.Asset{},
Parameters: &rctypes.FirmwareInstallTaskParameters{},
Server: &rtypes.Server{},
},
Logger: logrus.NewEntry(logrus.New()),
},
Expand Down
9 changes: 5 additions & 4 deletions internal/outofband/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/flasher/internal/device"
"github.com/metal-toolbox/flasher/internal/model"
"github.com/sirupsen/logrus"

rtypes "github.com/metal-toolbox/rivets/types"
)

var (
Expand Down Expand Up @@ -48,17 +49,17 @@ var (
ErrFirmwareInstallProvider = errors.New("firmware install provider not identified")
)

// bmc wraps the bmclib client and implements the bmcQueryor interface
// bmc wraps the bmclib client and implements the device.Queryor interface
type bmc struct {
client *bmclib.Client
logger *logrus.Entry
asset *model.Asset
asset *rtypes.Server
installProvider string
availableProviders []string
}

// NewDeviceQueryor returns a bmc queryor that implements the DeviceQueryor interface
func NewDeviceQueryor(ctx context.Context, asset *model.Asset, logger *logrus.Entry) device.Queryor {
func NewDeviceQueryor(ctx context.Context, asset *rtypes.Server, logger *logrus.Entry) device.Queryor {
return &bmc{
client: newBmclibv2Client(ctx, asset, logger),
logger: logger,
Expand Down
10 changes: 5 additions & 5 deletions internal/outofband/bmc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
logrusrv2 "github.com/bombsimon/logrusr/v2"
"github.com/hashicorp/go-multierror"
"github.com/jpillora/backoff"
rtypes "github.com/metal-toolbox/rivets/types"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"golang.org/x/exp/slices"
"golang.org/x/net/publicsuffix"

"github.com/metal-toolbox/flasher/internal/model"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -73,7 +73,7 @@ func newHTTPClient() *http.Client {
}

// newBmclibv2Client initializes a bmclib client with the given credentials
func newBmclibv2Client(_ context.Context, asset *model.Asset, l *logrus.Entry) *bmclib.Client {
func newBmclibv2Client(_ context.Context, asset *rtypes.Server, l *logrus.Entry) *bmclib.Client {
logger := logrus.New()
if l != nil {
logger.Formatter = l.Logger.Formatter
Expand All @@ -93,9 +93,9 @@ func newBmclibv2Client(_ context.Context, asset *model.Asset, l *logrus.Entry) *
logruslogr := logrusrv2.New(logger)

bmcClient := bmclib.NewClient(
asset.BmcAddress.String(),
asset.BmcUsername,
asset.BmcPassword,
asset.BMCAddress,
asset.BMCAddress,
asset.BMCPassword,
bmclib.WithLogger(logruslogr),
bmclib.WithHTTPClient(newHTTPClient()),
bmclib.WithPerProviderTimeout(loginTimeout),
Expand Down
5 changes: 3 additions & 2 deletions internal/outofband/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

bconsts "github.com/bmc-toolbox/bmclib/v2/constants"
rctypes "github.com/metal-toolbox/rivets/condition"
rtypes "github.com/metal-toolbox/rivets/types"
)

func GraphSteps(ctx context.Context, g *dot.Graph) error {
Expand All @@ -28,10 +29,10 @@ func GraphSteps(ctx context.Context, g *dot.Graph) error {
testActionCtx := &runner.ActionHandlerContext{
TaskHandlerContext: &runner.TaskHandlerContext{
Task: &model.Task{
Parameters: rctypes.FirmwareInstallTaskParameters{
Parameters: &rctypes.FirmwareInstallTaskParameters{
ResetBMCBeforeInstall: true,
},
Asset: &model.Asset{},
Server: &rtypes.Server{},
},
Logger: logrus.NewEntry(logrus.New()),
DeviceQueryor: m,
Expand Down

0 comments on commit 8d2b1e2

Please sign in to comment.