Skip to content

Commit

Permalink
Trigger hook for upgrade series on build.
Browse files Browse the repository at this point in the history
  • Loading branch information
ExternalReality committed Jul 2, 2018
1 parent 380932f commit 254edfe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion worker/uniter/hook/hook.go
Expand Up @@ -48,7 +48,7 @@ func (hi Info) Validate() error {
}
fallthrough
case hooks.Install, hooks.Start, hooks.ConfigChanged, hooks.UpgradeCharm, hooks.Stop, hooks.RelationBroken,
hooks.CollectMetrics, hooks.MeterStatusChanged, hooks.UpdateStatus:
hooks.CollectMetrics, hooks.MeterStatusChanged, hooks.UpdateStatus, hooks.UpgradeSeriesPrepare:
return nil
case hooks.Action:
return fmt.Errorf("hooks.Kind Action is deprecated")
Expand Down
5 changes: 5 additions & 0 deletions worker/uniter/resolver.go
Expand Up @@ -278,6 +278,11 @@ func (s *uniterResolver) nextOp(
return opFactory.NewRunHook(hook.Info{Kind: hooks.ConfigChanged})
}

if localState.UpgradeSeriesStatus != remoteState.UpgradeSeriesStatus &&
remoteState.UpgradeSeriesStatus == "preparing" {
return opFactory.NewRunHook(hook.Info{Kind: hooks.UpgradeSeriesPrepare})
}

op, err := s.config.Relations.NextOp(localState, remoteState, opFactory)
if errors.Cause(err) != resolver.ErrNoOperation {
return op, err
Expand Down
4 changes: 4 additions & 0 deletions worker/uniter/resolver/interface.go
Expand Up @@ -98,4 +98,8 @@ type LocalState struct {
// Series is the current series running on the unit from remotestate.Snapshot
// for which a config-changed hook has been committed.
Series string

// UpgradeSeriesStatus is the current state of any currently running
// series upgrade or the empty string if no series upgrade has been started.
UpgradeSeriesStatus string
}
19 changes: 19 additions & 0 deletions worker/uniter/resolver_test.go
Expand Up @@ -126,6 +126,25 @@ func (s *resolverSuite) TestSeriesChanged(c *gc.C) {
c.Assert(op.String(), gc.Equals, "run config-changed hook")
}

func (s *resolverSuite) TestUpgradeSeriesStatusChanged(c *gc.C) {
localState := resolver.LocalState{
CharmModifiedVersion: s.charmModifiedVersion,
CharmURL: s.charmURL,
Series: s.charmURL.Series,
UpgradeSeriesStatus: "",
State: operation.State{
Kind: operation.Continue,
Installed: true,
Started: true,
},
}
s.remoteState.Series = s.charmURL.Series
s.remoteState.UpgradeSeriesStatus = "preparing"
op, err := s.resolver.NextOp(localState, s.remoteState, s.opFactory)
c.Assert(err, jc.ErrorIsNil)
c.Assert(op.String(), gc.Equals, "run upgrade-series-prepare hook")
}

func (s *resolverSuite) TestSeriesChangedBlank(c *gc.C) {
localState := resolver.LocalState{
CharmModifiedVersion: s.charmModifiedVersion,
Expand Down

0 comments on commit 254edfe

Please sign in to comment.