Skip to content

Commit

Permalink
worker/uniter finalizeContext refactor for ActionFinish
Browse files Browse the repository at this point in the history
  • Loading branch information
binary132 committed Sep 3, 2014
1 parent 55e4e8a commit 38321ce
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions worker/uniter/context.go
Expand Up @@ -15,6 +15,7 @@ import (
"sync"
"time"

"github.com/juju/errors"
"github.com/juju/loggo"
utilexec "github.com/juju/utils/exec"
"github.com/juju/utils/proxy"
Expand Down Expand Up @@ -326,6 +327,42 @@ func (ctx *HookContext) finalizeContext(process string, err error) error {
}
rctx.ClearCache()
}
// If it was not an Action, just short-circuit to return err.
if ctx.actionTag == nil {
return err
}

// If the state handle was nil, we cannot call home and this will panic.
if ctx.state == nil {
return errors.New("action cannot call home, state handle undefined")
}

// Otherwise, set up for handling ActionFinish
message := ctx.actionResults.Message
results := ctx.actionResults.Results
status := params.ActionCompleted
if ctx.actionResults.Status == actionStatusFailed {
status = params.ActionFailed
}

if err != nil {
message = err.Error()
// If it was a missing hook error, the action implementation
// is missing, and that's a problem with the unit.
if IsMissingHookError(err) {
message = fmt.Sprintf("action failed (not implemented on unit %q)", ctx.UnitName())
}
status = params.ActionFailed
}

callErr := ctx.state.ActionFinish(*ctx.actionTag, status, results, message)
if callErr != nil {
if err != nil {
err = errors.Wrap(err, callErr)
} else {
err = callErr
}
}
return err
}

Expand Down

0 comments on commit 38321ce

Please sign in to comment.