Skip to content

Commit

Permalink
Merge pull request juju#1685 from howbazaar/provisioner-debugging
Browse files Browse the repository at this point in the history
Some helpful logging.

utils.LoggedErrorStack checks to see if a feature flag is set, and if so, it logs out the error stack.  The function also passes through the error untouched.

This is very useful for those error returns that you as a developer really don't expect to fail, and when they do, you want to know why.  Since this is hidden behind a developer feature flag, it makes no difference to any existing or future live site.

(Review request: http://reviews.vapour.ws/r/1013/)
  • Loading branch information
jujubot committed Feb 26, 2015
2 parents 31ca67f + 3a9a033 commit 13c7ae1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions worker/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/juju/juju/environs/config"
"github.com/juju/juju/instance"
"github.com/juju/juju/state/watcher"
"github.com/juju/juju/utils"
"github.com/juju/juju/worker"
)

Expand Down Expand Up @@ -166,7 +167,7 @@ func NewEnvironProvisioner(st *apiprovisioner.State, agentConfig agent.Config) P
logger.Tracef("Starting environ provisioner for %q", p.agentConfig.Tag())
go func() {
defer p.tomb.Done()
p.tomb.Kill(p.loop())
p.tomb.Kill(errors.Cause(p.loop()))
}()
return p
}
Expand All @@ -175,21 +176,21 @@ func (p *environProvisioner) loop() error {
var environConfigChanges <-chan struct{}
environWatcher, err := p.st.WatchForEnvironConfigChanges()
if err != nil {
return err
return utils.LoggedErrorStack(errors.Trace(err))
}
environConfigChanges = environWatcher.Changes()
defer watcher.Stop(environWatcher, &p.tomb)

p.environ, err = worker.WaitForEnviron(environWatcher, p.st, p.tomb.Dying())
if err != nil {
return err
return utils.LoggedErrorStack(errors.Trace(err))
}
p.broker = p.environ

harvestMode := p.environ.Config().ProvisionerHarvestMode()
task, err := p.getStartTask(harvestMode)
if err != nil {
return err
return utils.LoggedErrorStack(errors.Trace(err))
}
defer watcher.Stop(task, &p.tomb)

Expand Down
4 changes: 2 additions & 2 deletions worker/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type stopper interface {

// stop stops a stopper.
func stop(c *gc.C, s stopper) {
c.Assert(s.Stop(), gc.IsNil)
c.Assert(s.Stop(), jc.ErrorIsNil)
}

func (s *CommonProvisionerSuite) startUnknownInstance(c *gc.C, id string) instance.Instance {
Expand Down Expand Up @@ -422,7 +422,7 @@ func (s *CommonProvisionerSuite) ensureAvailability(c *gc.C, n int) []*state.Mac

func (s *ProvisionerSuite) TestProvisionerStartStop(c *gc.C) {
p := s.newEnvironProvisioner(c)
c.Assert(p.Stop(), gc.IsNil)
c.Assert(p.Stop(), jc.ErrorIsNil)
}

func (s *ProvisionerSuite) TestSimple(c *gc.C) {
Expand Down

0 comments on commit 13c7ae1

Please sign in to comment.