Skip to content

Commit

Permalink
Make sure to switch the deployment logs on and off.
Browse files Browse the repository at this point in the history
In some states deployment logger was not switched on and off
correctly. This one makes sure we are logging only the data
while the device update is in progress.

Changelog: None

Signed-off-by: Marcin Pasinski <marcin.pasinski@mender.io>
(cherry picked from commit 08f45d8)
  • Loading branch information
pasinskim authored and kacf committed Sep 27, 2017
1 parent 6151826 commit d75771e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ type IdleState struct {
}

func (i *IdleState) Handle(ctx *StateContext, c Controller) (State, bool) {
// stop deployment logging
DeploymentLogger.Disable()

// check if client is authorized
if c.IsAuthorized() {
return checkWaitState, false
Expand Down Expand Up @@ -394,6 +397,9 @@ type AuthorizeState struct {
}

func (a *AuthorizeState) Handle(ctx *StateContext, c Controller) (State, bool) {
// stop deployment logging
DeploymentLogger.Disable()

log.Debugf("handle authorize state")
if err := c.Authorize(); err != nil {
log.Errorf("authorize failed: %v", err)
Expand Down Expand Up @@ -658,6 +664,11 @@ func NewUpdateInstallState(update client.UpdateResponse) State {
}

func (is *UpdateInstallState) Handle(ctx *StateContext, c Controller) (State, bool) {
// start deployment logging
if err := DeploymentLogger.Enable(is.Update().ID); err != nil {
return NewUpdateStatusReportState(is.Update(), client.StatusFailure), false
}

merr := c.ReportUpdateStatus(is.Update(), client.StatusInstalling)
if merr != nil && merr.IsFatal() {
return NewUpdateErrorState(NewTransientError(merr), is.Update()), false
Expand Down Expand Up @@ -828,6 +839,9 @@ func NewErrorState(err menderError) State {
}

func (e *ErrorState) Handle(ctx *StateContext, c Controller) (State, bool) {
// stop deployment logging
DeploymentLogger.Disable()

log.Infof("handling error state, current error: %v", e.cause.Error())
// decide if error is transient, exit for now
if e.cause.IsFatal() {
Expand Down Expand Up @@ -1035,6 +1049,10 @@ func NewReportErrorState(update client.UpdateResponse, status string) State {
}

func (res *ReportErrorState) Handle(ctx *StateContext, c Controller) (State, bool) {
// start deployment logging; no error checking
// we can do nothing here; either we will have the logs or not...
DeploymentLogger.Enable(res.Update().ID)

log.Errorf("handling report error state with status: %v", res.updateStatus)

switch res.updateStatus {
Expand Down Expand Up @@ -1118,6 +1136,10 @@ func NewAfterRebootState(update client.UpdateResponse) State {

func (rs *AfterRebootState) Handle(ctx *StateContext,
c Controller) (State, bool) {
// start deployment logging; no error checking
// we can do nothing here; either we will have the logs or not...
DeploymentLogger.Enable(rs.Update().ID)

// this state is needed to satisfy ToReboot transition Leave() action
log.Debug("handling state after reboot")

Expand Down Expand Up @@ -1216,6 +1238,12 @@ func NewAfterRollbackRebootState(update client.UpdateResponse) State {

func (rs *AfterRollbackRebootState) Handle(ctx *StateContext,
c Controller) (State, bool) {
// start deployment logging
if err := DeploymentLogger.Enable(rs.Update().ID); err != nil {
// just log error; we need to reboot anyway
log.Errorf("failed to enable deployment logger: %s", err)
}

// this state is needed to satisfy ToRollbackReboot
// transition Leave() action
log.Debug("handling state after rollback reboot")
Expand Down

0 comments on commit d75771e

Please sign in to comment.