Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes lp#1597830 on develop: worker should not restart agent. #6696

Merged
merged 1 commit into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions worker/conv2state/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/juju/juju/api/machiner"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/cmd/jujud/util"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/watcher"
)
Expand All @@ -29,9 +30,9 @@ type converter struct {
machine machine
}

// Agent is an interface that can have its password set and be told to restart.
// Agent is an interface that exposes machine agent methods required for the
// conversion worker.
type Agent interface {
Restart() error
Tag() names.Tag
}

Expand Down Expand Up @@ -69,8 +70,8 @@ func (c *converter) SetUp() (watcher.NotifyWatcher, error) {
}

// Handle implements NotifyWatchHandler's Handle method. If the change means
// that the machine is now expected to manage the environment, we change its
// password (to set its password in mongo) and restart the agent.
// that the machine is now expected to manage the environment,
// we throw a fatal error to instigate agent restart.
func (c *converter) Handle(_ <-chan struct{}) error {
results, err := c.machine.Jobs()
if err != nil {
Expand All @@ -80,7 +81,7 @@ func (c *converter) Handle(_ <-chan struct{}) error {
return nil
}

return errors.Trace(c.agent.Restart())
return &util.FatalError{"bounce agent to pick up new jobs"}
}

// TearDown implements NotifyWatchHandler's TearDown method.
Expand Down
17 changes: 5 additions & 12 deletions worker/conv2state/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v2"

Expand Down Expand Up @@ -71,8 +70,9 @@ func (s Suite) TestHandle(c *gc.C) {
_, err := conv.SetUp()
c.Assert(err, gc.IsNil)
err = conv.Handle(nil)
c.Assert(err, gc.IsNil)
c.Assert(a.didRestart, jc.IsTrue)
// Since machine has multiwatcher.JobManageEnviron, we expect an error
// which will get agent to restart.
c.Assert(err.Error(), gc.Equals, "bounce agent to pick up new jobs")
}

func (s Suite) TestHandleNoManageEnviron(c *gc.C) {
Expand All @@ -87,7 +87,6 @@ func (s Suite) TestHandleNoManageEnviron(c *gc.C) {
c.Assert(err, gc.IsNil)
err = conv.Handle(nil)
c.Assert(err, gc.IsNil)
c.Assert(a.didRestart, jc.IsFalse)
}

func (Suite) TestHandleJobsError(c *gc.C) {
Expand All @@ -103,13 +102,11 @@ func (Suite) TestHandleJobsError(c *gc.C) {
c.Assert(err, gc.IsNil)
err = conv.Handle(nil)
c.Assert(errors.Cause(err), gc.Equals, m.jobsErr)
c.Assert(a.didRestart, jc.IsFalse)
}

func (s Suite) TestHandleRestartError(c *gc.C) {
a := &fakeAgent{
tag: names.NewMachineTag("1"),
restartErr: errors.New("foo"),
tag: names.NewMachineTag("1"),
}
jobs := []multiwatcher.MachineJob{multiwatcher.JobHostUnits, multiwatcher.JobManageModel}
m := &fakeMachine{
Expand All @@ -120,9 +117,5 @@ func (s Suite) TestHandleRestartError(c *gc.C) {
_, err := conv.SetUp()
c.Assert(err, gc.IsNil)
err = conv.Handle(nil)
c.Assert(errors.Cause(err), gc.Equals, a.restartErr)

// We set this to true whenver the function is called, even though we're
// returning an error from it.
c.Assert(a.didRestart, jc.IsTrue)
c.Assert(err.Error(), gc.Equals, "bounce agent to pick up new jobs")
}
9 changes: 1 addition & 8 deletions worker/conv2state/fakes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ func (fakeWatcher) Wait() error {
}

type fakeAgent struct {
tag names.Tag
restartErr error
didRestart bool
}

func (f *fakeAgent) Restart() error {
f.didRestart = true
return f.restartErr
tag names.Tag
}

func (f fakeAgent) Tag() names.Tag {
Expand Down