-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
R=john.meinel, niemeyer CC= https://codereview.appspot.com/6814055
- Loading branch information
Showing
6 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"launchpad.net/gnuflag" | ||
"launchpad.net/juju-core/cmd" | ||
"launchpad.net/juju-core/juju" | ||
"launchpad.net/juju-core/state" | ||
) | ||
|
||
// ResolvedCommand marks a unit in an error state as ready to continue. | ||
type ResolvedCommand struct { | ||
EnvName string | ||
UnitName string | ||
Retry bool | ||
} | ||
|
||
func (c *ResolvedCommand) Info() *cmd.Info { | ||
return &cmd.Info{"resolved", "<unit>", "marks unit errors resolved", ""} | ||
} | ||
|
||
func (c *ResolvedCommand) Init(f *gnuflag.FlagSet, args []string) error { | ||
addEnvironFlags(&c.EnvName, f) | ||
f.BoolVar(&c.Retry, "r", false, "re-execute failed hooks") | ||
f.BoolVar(&c.Retry, "retry", false, "") | ||
if err := f.Parse(true, args); err != nil { | ||
return err | ||
} | ||
args = f.Args() | ||
if len(args) > 0 { | ||
c.UnitName = args[0] | ||
if !state.IsUnitName(c.UnitName) { | ||
return fmt.Errorf("invalid unit name %q", c.UnitName) | ||
} | ||
args = args[1:] | ||
} else { | ||
return fmt.Errorf("no unit specified") | ||
} | ||
return cmd.CheckEmpty(args) | ||
} | ||
|
||
func (c *ResolvedCommand) Run(_ *cmd.Context) error { | ||
conn, err := juju.NewConnFromName(c.EnvName) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
unit, err := conn.State.Unit(c.UnitName) | ||
if err != nil { | ||
return err | ||
} | ||
return conn.Resolved(unit, c.Retry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
. "launchpad.net/gocheck" | ||
"launchpad.net/juju-core/cmd" | ||
"launchpad.net/juju-core/state" | ||
"launchpad.net/juju-core/testing" | ||
) | ||
|
||
type ResolvedSuite struct { | ||
repoSuite | ||
} | ||
|
||
var _ = Suite(&ResolvedSuite{}) | ||
|
||
func runResolved(c *C, args []string) error { | ||
com := &ResolvedCommand{} | ||
if err := com.Init(newFlagSet(), args); err != nil { | ||
return err | ||
} | ||
return com.Run(&cmd.Context{c.MkDir(), &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}}) | ||
} | ||
|
||
var resolvedTests = []struct { | ||
args []string | ||
err string | ||
unit string | ||
mode state.ResolvedMode | ||
}{ | ||
{ | ||
err: `no unit specified`, | ||
}, { | ||
args: []string{"jeremy-fisher"}, | ||
err: `invalid unit name "jeremy-fisher"`, | ||
}, { | ||
args: []string{"jeremy-fisher/99"}, | ||
err: `unit "jeremy-fisher/99" not found`, | ||
}, { | ||
args: []string{"dummy/0"}, | ||
err: `unit "dummy/0" is not in an error state`, | ||
unit: "dummy/0", | ||
mode: state.ResolvedNone, | ||
}, { | ||
args: []string{"dummy/1", "--retry"}, | ||
err: `unit "dummy/1" is not in an error state`, | ||
unit: "dummy/1", | ||
mode: state.ResolvedNone, | ||
}, { | ||
args: []string{"dummy/2"}, | ||
unit: "dummy/2", | ||
mode: state.ResolvedNoHooks, | ||
}, { | ||
args: []string{"dummy/2", "--retry"}, | ||
err: `cannot set resolved mode for unit "dummy/2": already resolved`, | ||
unit: "dummy/2", | ||
mode: state.ResolvedNoHooks, | ||
}, { | ||
args: []string{"dummy/3", "--retry"}, | ||
unit: "dummy/3", | ||
mode: state.ResolvedRetryHooks, | ||
}, { | ||
args: []string{"dummy/3"}, | ||
err: `cannot set resolved mode for unit "dummy/3": already resolved`, | ||
unit: "dummy/3", | ||
mode: state.ResolvedRetryHooks, | ||
}, { | ||
args: []string{"dummy/4", "roflcopter"}, | ||
err: `unrecognized args: \["roflcopter"\]`, | ||
}, | ||
} | ||
|
||
func (s *ResolvedSuite) TestResolved(c *C) { | ||
testing.Charms.BundlePath(s.seriesPath, "series", "dummy") | ||
err := runDeploy(c, "-n", "5", "local:dummy", "dummy") | ||
c.Assert(err, IsNil) | ||
|
||
for _, name := range []string{"dummy/2", "dummy/3", "dummy/4"} { | ||
u, err := s.State.Unit(name) | ||
c.Assert(err, IsNil) | ||
err = u.SetStatus(state.UnitError, "lol borken") | ||
c.Assert(err, IsNil) | ||
} | ||
|
||
for i, t := range resolvedTests { | ||
c.Logf("test %d: %v", i, t.args) | ||
err := runResolved(c, t.args) | ||
if t.err != "" { | ||
c.Assert(err, ErrorMatches, t.err) | ||
} else { | ||
c.Assert(err, IsNil) | ||
} | ||
if t.unit != "" { | ||
unit, err := s.State.Unit(t.unit) | ||
c.Assert(err, IsNil) | ||
c.Assert(unit.Resolved(), Equals, t.mode) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters