Skip to content

Commit

Permalink
Vc/fix action (#67)
Browse files Browse the repository at this point in the history
* fix the problem

* minor log and flow tweaks
  • Loading branch information
DoctorVin authored Aug 30, 2023
1 parent 354d169 commit aa6c0eb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
14 changes: 7 additions & 7 deletions internal/worker/task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ func (h *taskHandler) Run(t sw.StateSwitch, args sw.TransitionArgs) error {
return errors.Wrap(ErrSaveTask, ErrTaskTypeAssertion.Error())
}

tctx.Logger.Debug("running the plan")
tctx.Logger.WithField("plan.steps", len(tctx.ActionStateMachines)).Debug("running the plan")

// each actionSM (state machine) corresponds to a firmware to be installed
for _, actionSM := range tctx.ActionStateMachines {
for i, actionSM := range tctx.ActionStateMachines {
tctx.Logger.WithFields(logrus.Fields{
"statemachineID": actionSM.ActionID(),
"step": i,
}).Debug("state machine start")
startTS := time.Now()

Expand Down Expand Up @@ -261,7 +262,7 @@ func (h *taskHandler) planInstall(hCtx *sm.HandlerContext, task *model.Task, fir
hCtx.Logger.WithFields(logrus.Fields{
"condition.id": task.ID,
"requested.firmware.count": fmt.Sprintf("%d", len(firmwares)),
}).Info("checking against current inventory")
}).Debug("checking against current inventory")

toInstall := firmwares

Expand Down Expand Up @@ -306,7 +307,7 @@ func (h *taskHandler) planInstall(hCtx *sm.HandlerContext, task *model.Task, fir
InstallMethod: model.InstallMethodOutofband,

// Firmware is the firmware to be installed
Firmware: *firmwares[idx],
Firmware: *firmware,

// VerifyCurrentFirmware is disabled when ForceInstall is true.
VerifyCurrentFirmware: !task.Parameters.ForceInstall,
Expand All @@ -315,9 +316,8 @@ func (h *taskHandler) planInstall(hCtx *sm.HandlerContext, task *model.Task, fir
Final: final,
}

if err := newAction.SetState(model.StatePending); err != nil {
return nil, nil, err
}
//nolint:errcheck // SetState never returns an error
newAction.SetState(model.StatePending)

// create action thats added to the task
actions = append(actions, &newAction)
Expand Down
60 changes: 60 additions & 0 deletions internal/worker/task_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,63 @@ func TestRemoveFirmwareAlreadyAtDesiredVersion(t *testing.T) {
require.Equal(t, 1, len(got))
require.Equal(t, expected[0], got[0])
}

func TestPlanInstall(t *testing.T) {
t.Parallel()
fwSet := []*model.Firmware{
{
Version: "5.10.00.00",
URL: "https://downloads.dell.com/FOLDER06303849M/1/BMC_5_10_00_00.EXE",
FileName: "BMC_5_10_00_00.EXE",
Models: []string{"r6515"},
Checksum: "4189d3cb123a781d09a4f568bb686b23c6d8e6b82038eba8222b91c380a25281",
Component: "bmc",
},
{
Version: "2.19.6",
URL: "https://dl.dell.com/FOLDER08105057M/1/BIOS_C4FT0_WN64_2.19.6.EXE",
FileName: "BIOS_C4FT0_WN64_2.19.6.EXE",
Models: []string{"r6515"},
Checksum: "1ddcb3c3d0fc5925ef03a3dde768e9e245c579039dd958fc0f3a9c6368b6c5f4",
Component: "bios",
},
}
serverID := uuid.MustParse("fa125199-e9dd-47d4-8667-ce1d26f58c4a")
taskID := uuid.MustParse("05c3296d-be5d-473a-b90c-4ce66cfdec65")
ctx := &sm.HandlerContext{
Logger: logrus.NewEntry(logrus.New()),
Asset: &model.Asset{
ID: serverID,
Components: model.Components{
{
Slug: "BiOs",
FirmwareInstalled: "2.6.6",
},
{
Slug: "bmc",
FirmwareInstalled: "5.10.00.00",
},
},
},
Task: &model.Task{
ID: taskID,
},
WorkerID: registry.GetID("test-app"),
}

h := &taskHandler{}

taskParam := &model.Task{
ID: uuid.MustParse("95ccb1c5-d807-4078-bb22-facc3045a49a"),
Parameters: model.TaskParameters{
AssetID: serverID,
},
}

sms, actions, err := h.planInstall(ctx, taskParam, fwSet)
require.NoError(t, err)
require.Equal(t, 1, len(sms))
require.Equal(t, 1, len(actions))
require.True(t, actions[0].Final)
require.Equal(t, "bios", actions[0].Firmware.Component)
}

0 comments on commit aa6c0eb

Please sign in to comment.