Skip to content

Commit

Permalink
NO-ISSUE: Remove unused RegisterInstalledOCPHost and its associated…
Browse files Browse the repository at this point in the history
… transition (#4412)

This function is not called, its purpose is not entirely clear at this
point, so it should be removed to simplify the state machine.
  • Loading branch information
omertuc authored Sep 28, 2022
1 parent bc737e0 commit a40422b
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 113 deletions.
8 changes: 0 additions & 8 deletions internal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type API interface {
// Register a new host
RegisterHost(ctx context.Context, h *models.Host, db *gorm.DB) error
UnRegisterHost(ctx context.Context, hostID, infraEnvID string) error
RegisterInstalledOCPHost(ctx context.Context, h *models.Host, db *gorm.DB) error
HandleInstallationFailure(ctx context.Context, h *models.Host) error
HandleMediaDisconnected(ctx context.Context, h *models.Host) error
HandleReclaimBootArtifactDownload(ctx context.Context, h *models.Host) error
Expand Down Expand Up @@ -234,13 +233,6 @@ func (m *Manager) RegisterHost(ctx context.Context, h *models.Host, db *gorm.DB)
})
}

func (m *Manager) RegisterInstalledOCPHost(ctx context.Context, h *models.Host, db *gorm.DB) error {
return m.sm.Run(TransitionTypeRegisterInstalledHost, newStateHost(h), &TransitionArgsRegisterInstalledHost{
ctx: ctx,
db: db,
})
}

func (m *Manager) HandleInstallationFailure(ctx context.Context, h *models.Host) error {
lastStatusUpdateTime := h.StatusUpdatedAt
err := m.sm.Run(TransitionTypeHostInstallationFailed, newStateHost(h), &TransitionArgsHostInstallationFailed{
Expand Down
14 changes: 0 additions & 14 deletions internal/host/mock_host_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions internal/host/mock_transition.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions internal/host/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const (
TransitionTypeResettingPendingUserAction = "ResettingPendingUserAction"
TransitionTypeRefresh = "RefreshHost"
TransitionTypeMediaDisconnect = "MediaDisconnect"
TransitionTypeRegisterInstalledHost = "RegisterInstalledHost"
TransitionTypeBindHost = "BindHost"
TransitionTypeUnbindHost = "UnbindHost"
TransitionTypeReclaimHost = "ReclaimHost"
Expand Down Expand Up @@ -110,16 +109,6 @@ func NewHostStateMachine(sm stateswitch.StateMachine, th TransitionHandler) stat
DestinationState: stateswitch.State(models.HostStatusError),
})

// Register host
sm.AddTransition(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterInstalledHost,
SourceStates: []stateswitch.State{
"",
},
DestinationState: stateswitch.State(models.HostStatusInstalled),
PostTransition: th.PostRegisterInstalledHost,
})

// Installation failure
sm.AddTransition(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostInstallationFailed,
Expand Down
28 changes: 0 additions & 28 deletions internal/host/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type TransitionHandler interface {
PostRegisterDuringInstallation(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostRegisterDuringReboot(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostRegisterHost(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostRegisterInstalledHost(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostResetHost(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostResettingPendingUserAction(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
PostUnbindHost(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error
Expand Down Expand Up @@ -201,33 +200,6 @@ func (th *transitionHandler) PostRegisterDuringReboot(sw stateswitch.StateSwitch
return th.updateTransitionHost(params.ctx, logutil.FromContext(params.ctx, th.log), params.db, sHost, strings.Join(messages, " "))
}

///////////////////////////////////////////////////////////////////////////
// Register Installed host
//////////////////////////////////////////////////////////////////////////

type TransitionArgsRegisterInstalledHost struct {
ctx context.Context
db *gorm.DB
}

func (th *transitionHandler) PostRegisterInstalledHost(sw stateswitch.StateSwitch, args stateswitch.TransitionArgs) error {
sHost, ok := sw.(*stateHost)
if !ok {
return errors.New("PostRegisterInstalledHost incompatible type of StateSwitch")
}
params, ok := args.(*TransitionArgsRegisterInstalledHost)
if !ok {
return errors.New("PostRegisterInstalledHost invalid argument")
}

log := logutil.FromContext(params.ctx, th.log)

sHost.host.StatusUpdatedAt = strfmt.DateTime(time.Now())
sHost.host.StatusInfo = swag.String(statusInfoDiscovering)
log.Infof("Register installed host %s cluster %s", sHost.host.ID.String(), sHost.host.ClusterID)
return params.db.Create(sHost.host).Error
}

////////////////////////////////////////////////////////////////////////////
// Media disconnected
////////////////////////////////////////////////////////////////////////////
Expand Down
38 changes: 0 additions & 38 deletions internal/host/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,44 +642,6 @@ var _ = Describe("HostInstallationFailed", func() {
})
})

var _ = Describe("RegisterInstalledOCPHost", func() {
var (
ctx = context.Background()
hapi API
db *gorm.DB
hostId, clusterId, infraEnvId strfmt.UUID
host models.Host
ctrl *gomock.Controller
mockMetric *metrics.MockAPI
mockEvents *eventsapi.MockHandler
dbName string
)

BeforeEach(func() {
db, dbName = common.PrepareTestDB()
ctrl = gomock.NewController(GinkgoT())
mockMetric = metrics.NewMockAPI(ctrl)
mockEvents = eventsapi.NewMockHandler(ctrl)
mockHwValidator := hardware.NewMockValidator(ctrl)
operatorsManager := operators.NewManager(common.GetTestLog(), nil, operators.Options{}, nil, nil)
hapi = NewManager(common.GetTestLog(), db, mockEvents, mockHwValidator, nil, createValidatorCfg(), mockMetric, defaultConfig, nil, operatorsManager, nil, false, nil)
hostId = strfmt.UUID(uuid.New().String())
clusterId = strfmt.UUID(uuid.New().String())
infraEnvId = strfmt.UUID(uuid.New().String())
host = hostutil.GenerateTestHost(hostId, infraEnvId, clusterId, "")
})

It("register_installed_host", func() {
Expect(hapi.RegisterInstalledOCPHost(ctx, &host, db)).ShouldNot(HaveOccurred())
h := hostutil.GetHostFromDB(hostId, infraEnvId, db)
Expect(swag.StringValue(h.Status)).Should(Equal(models.HostStatusInstalled))
})

AfterEach(func() {
common.DeleteTestDB(db, dbName)
})
})

var _ = Describe("Cancel host installation", func() {
var (
ctx = context.Background()
Expand Down

0 comments on commit a40422b

Please sign in to comment.