Skip to content

Commit

Permalink
Merge pull request #1789 from axw/lp1430049-state-isnotassigned-errcause
Browse files Browse the repository at this point in the history
state: use errors.Cause in IsNotAssigned

There was a change in PR 1707 that causes the
megawatcher to fail if the unit is not yet assigned to
a machine. The cause is that a call to errors.Cause was
removed in back-porting a fix from master, but
IsNotAssigned does not do this in 1.22 as it does on
master.

This branch changes IsNotAssigned to call errors.Cause.

Fixes https://bugs.launchpad.net/juju-core/+bug/1430049

(Review request: http://reviews.vapour.ws/r/1117/)
  • Loading branch information
jujubot committed Mar 10, 2015
2 parents 6053af7 + 396b5a5 commit c2d16fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion state/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ func (e *NotAssignedError) Error() string {

// IsNotAssigned verifies that err is an instance of NotAssignedError
func IsNotAssigned(err error) bool {
_, ok := err.(*NotAssignedError)
_, ok := errors.Cause(err).(*NotAssignedError)
return ok
}

Expand Down
10 changes: 5 additions & 5 deletions state/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,15 +1059,15 @@ func (s *UnitSuite) TestOpenedPorts(c *gc.C) {
// Verify ports can be opened and closed only when the unit has
// assigned machine.
err := s.unit.OpenPort("tcp", 10)
c.Assert(errors.Cause(err), jc.Satisfies, state.IsNotAssigned)
c.Assert(err, jc.Satisfies, state.IsNotAssigned)
err = s.unit.OpenPorts("tcp", 10, 20)
c.Assert(errors.Cause(err), jc.Satisfies, state.IsNotAssigned)
c.Assert(err, jc.Satisfies, state.IsNotAssigned)
err = s.unit.ClosePort("tcp", 10)
c.Assert(errors.Cause(err), jc.Satisfies, state.IsNotAssigned)
c.Assert(err, jc.Satisfies, state.IsNotAssigned)
err = s.unit.ClosePorts("tcp", 10, 20)
c.Assert(errors.Cause(err), jc.Satisfies, state.IsNotAssigned)
c.Assert(err, jc.Satisfies, state.IsNotAssigned)
open, err := s.unit.OpenedPorts()
c.Assert(errors.Cause(err), jc.Satisfies, state.IsNotAssigned)
c.Assert(err, jc.Satisfies, state.IsNotAssigned)
c.Assert(open, gc.HasLen, 0)

machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
Expand Down

0 comments on commit c2d16fc

Please sign in to comment.