Skip to content

Commit

Permalink
outofband/action: state transition, publish handler renamed
Browse files Browse the repository at this point in the history
and purged unused ctx var
  • Loading branch information
joelrebel committed May 4, 2023
1 parent dd6e29c commit 0c75132
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions internal/outofband/actions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package outofband

import (
"context"

sw "github.com/filanov/stateswitch"
"github.com/metal-toolbox/flasher/internal/model"
sm "github.com/metal-toolbox/flasher/internal/statemachine"
Expand Down Expand Up @@ -61,8 +59,8 @@ func transitionOrder() []sw.TransitionType {
}
}

func NewActionStateMachine(ctx context.Context, actionID string) (*sm.ActionStateMachine, error) {
machine, err := sm.NewActionStateMachine(ctx, actionID, transitionOrder(), transitionRules())
func NewActionStateMachine(actionID string) (*sm.ActionStateMachine, error) {
machine, err := sm.NewActionStateMachine(actionID, transitionOrder(), transitionRules())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -149,7 +147,7 @@ func transitionRules() []sw.TransitionRule {
return []sw.TransitionRule{
{
TransitionType: transitionTypePowerOnDevice,
SourceStates: sw.States{model.StateQueued},
SourceStates: sw.States{model.StateActive},
DestinationState: statePoweredOnDevice,

// Condition for the transition, transition will be executed only if this function return true
Expand All @@ -163,7 +161,7 @@ func transitionRules() []sw.TransitionRule {
Transition: handler.powerOnDevice,

// PostTransition will be called if condition and transition are successful.
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Power on device",
Description: "Power on device - if its currently powered off.",
Expand All @@ -175,7 +173,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: stateCheckedCurrentFirmware,
Condition: nil,
Transition: handler.checkCurrentFirmware,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Check installed firmware",
Description: "Check firmware installed on component - if its equal - returns error, unless Task.Parameters.Force=true.",
Expand All @@ -187,7 +185,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: stateDownloadedFirmware,
Condition: nil,
Transition: handler.downloadFirmware,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Download and verify firmware",
Description: "Download and verify firmware file checksum.",
Expand All @@ -199,7 +197,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: stateInitiatedInstallFirmware,
Condition: nil,
Transition: handler.initiateInstallFirmware,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Initiate firmware install",
Description: "Initiate firmware install for component.",
Expand All @@ -211,7 +209,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: statePolledFirmwareInstallStatus,
Condition: nil,
Transition: handler.pollFirmwareInstallStatus,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Poll firmware install status",
Description: "Poll BMC with exponential backoff for firmware install status until firmware install status is in a finalized state (completed/powercyclehost/powercyclebmc/failed).",
Expand All @@ -223,7 +221,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: stateResetBMC,
Condition: nil,
Transition: handler.resetBMC,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Powercycle BMC",
Description: "Powercycle BMC - only when pollFirmwareInstallStatus() identifies a BMC reset is required.",
Expand All @@ -235,7 +233,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: stateResetDevice,
Condition: nil,
Transition: handler.resetDevice,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Powercycle Device",
Description: "Powercycle Device - only when pollFirmwareInstallStatus() identifies a Device power cycle is required.",
Expand All @@ -247,7 +245,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: statePoweredOffDevice,
Condition: nil,
Transition: handler.powerOffDevice,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Power off Device",
Description: "Powercycle Device - only if this is the final firmware (action statemachine) to be installed and the device was powered off earlier.",
Expand All @@ -260,7 +258,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: sm.StateActionSuccessful,
Condition: nil,
Transition: handler.actionSuccessful,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Success",
Description: "Firmware install on component completed successfully.",
Expand All @@ -271,7 +269,7 @@ func transitionRules() []sw.TransitionRule {
{
TransitionType: sm.TransitionTypeActionFailed,
SourceStates: sw.States{
model.StateQueued,
model.StatePending,
model.StateActive,
statePoweredOnDevice,
stateCheckedCurrentFirmware,
Expand All @@ -285,7 +283,7 @@ func transitionRules() []sw.TransitionRule {
DestinationState: sm.StateActionFailed,
Condition: nil,
Transition: handler.actionFailed,
PostTransition: handler.PersistState,
PostTransition: handler.PublishStatus,
Documentation: sw.TransitionRuleDoc{
Name: "Failed",
Description: "Firmware install on component failed.",
Expand Down

0 comments on commit 0c75132

Please sign in to comment.