Skip to content

Commit

Permalink
chore: merge branch '3.5' into merge-3.5-20241016
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Oct 16, 2024
2 parents ed79eae + f3ab32c commit 3c6f0f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion worker/uniter/runner/context/contextfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/hex"
"fmt"

"github.com/juju/charm/v12"
"github.com/juju/charm/v12/hooks"
"github.com/juju/errors"
"github.com/juju/loggo"
Expand Down Expand Up @@ -376,7 +377,8 @@ func (f *contextFactory) getContextRelations() map[int]*ContextRelation {
// If there are no members and the relation is dying or suspended, a relation is broken.
rel := info.RelationUnit.Relation()
relationInactive := rel.Life() != life.Alive || rel.Suspended()
broken := relationInactive && len(memberNames) == 0
isPeer := info.RelationUnit.Endpoint().Role == charm.RolePeer
broken := !isPeer && relationInactive && len(memberNames) == 0
contextRelations[id] = NewContextRelation(relationUnit, cache, broken)
}
f.relationCaches = relationCaches
Expand Down
42 changes: 42 additions & 0 deletions worker/uniter/runner/context/contextfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,48 @@ func (s *ContextFactorySuite) TestRelationBrokenHookContext(c *gc.C) {
c.Assert(context.RelationBroken(ctx, 1), jc.IsTrue)
}

func (s *ContextFactorySuite) TestRelationIsPeerHookContext(c *gc.C) {
relCh := s.AddTestingCharm(c, "riak")
app := s.AddTestingApplication(c, "riak", relCh)
u, err := app.AddUnit(state.AddUnitParams{})
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = u.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
st := s.OpenAPIAs(c, u.Tag(), password)
uniterAPI, err := uniter.NewFromConnection(st)
c.Assert(err, jc.ErrorIsNil)

rels, err := app.Relations()
c.Assert(err, jc.ErrorIsNil)
var rel *state.Relation
for _, r := range rels {
if len(r.Endpoints()) == 1 {
rel = r
break
}
}
c.Assert(rel, gc.NotNil)
ru, err := rel.Unit(u)
c.Assert(err, jc.ErrorIsNil)
err = ru.EnterScope(map[string]interface{}{"relation-name": "riak"})
c.Assert(err, jc.ErrorIsNil)
apiRel, err := uniterAPI.Relation(rel.Tag().(names.RelationTag))
c.Assert(err, jc.ErrorIsNil)
apiRelUnit, err := apiRel.Unit(u.UnitTag())
c.Assert(err, jc.ErrorIsNil)
s.apiRelunits[rel.Id()] = apiRelUnit

hi := hook.Info{
Kind: hooks.RelationBroken,
RelationId: rel.Id(),
}
ctx, err := s.factory.HookContext(hi)
c.Assert(err, jc.ErrorIsNil)
c.Assert(context.RelationBroken(ctx, rel.Id()), jc.IsFalse)
}

// TestWorkloadHookContext verifies that each of the types of workload hook
// generate the correct event context.
func (s *ContextFactorySuite) TestWorkloadHookContext(c *gc.C) {
Expand Down

0 comments on commit 3c6f0f2

Please sign in to comment.