Skip to content

Commit

Permalink
Make active=True the default.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Dec 15, 2023
1 parent 8d98923 commit ce1e108
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def __getitem__(self, relation_name: str) -> List['Relation']:
if rid == self._broken_relation_id:
continue
relation = Relation(relation_name, rid, is_peer,
self._our_unit, self._backend, self._cache, True)
self._our_unit, self._backend, self._cache)
relation_list.append(relation)
return relation_list

Expand All @@ -861,7 +861,7 @@ def _get_unique(self, relation_name: str, relation_id: Optional[int] = None):
# The relation may be dead, but it is not forgotten.
is_peer = relation_name in self._peers
return Relation(relation_name, relation_id, is_peer,
self._our_unit, self._backend, self._cache, False)
self._our_unit, self._backend, self._cache, active=False)
relations = self[relation_name]
num_related = len(relations)
self._backend._validate_relation_access(
Expand Down Expand Up @@ -1474,7 +1474,7 @@ class Relation:

def __init__(
self, relation_name: str, relation_id: int, is_peer: bool, our_unit: Unit,
backend: '_ModelBackend', cache: '_ModelCache', active: bool):
backend: '_ModelBackend', cache: '_ModelCache', active: bool = True):
self.name = relation_name
self.id = relation_id
self.app: Optional[Application] = None
Expand Down
15 changes: 6 additions & 9 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3398,16 +3398,16 @@ def test_grant(self):
meta = ops.CharmMeta()
cache = ops.model._ModelCache(meta, backend)
unit = ops.Unit('test', meta, backend, cache)
rel123 = ops.Relation('test', 123, True, unit, backend, cache, True)
rel234 = ops.Relation('test', 234, True, unit, backend, cache, True)
rel123 = ops.Relation('test', 123, True, unit, backend, cache)
rel234 = ops.Relation('test', 234, True, unit, backend, cache)
secret.grant(rel123)
unit = ops.Unit('app/0', meta, backend, cache)
secret.grant(rel234, unit=unit)

# If secret doesn't have an ID, we'll run secret-info-get to fetch it
secret = self.make_secret(label='y')
self.assertIsNone(secret.id)
rel345 = ops.Relation('test', 345, True, unit, backend, cache, True)
rel345 = ops.Relation('test', 345, True, unit, backend, cache)
secret.grant(rel345)
self.assertEqual(secret.id, 'secret:z')

Expand All @@ -3428,19 +3428,16 @@ def test_revoke(self):

secret = self.make_secret(id='x')
unit = ops.Unit('test', ops.CharmMeta(), self.model._backend, self.model._cache)
rel123 = ops.Relation('test', 123, True, unit, self.model._backend, self.model._cache,
True)
rel234 = ops.Relation('test', 234, True, unit, self.model._backend, self.model._cache,
True)
rel123 = ops.Relation('test', 123, True, unit, self.model._backend, self.model._cache,)
rel234 = ops.Relation('test', 234, True, unit, self.model._backend, self.model._cache)
secret.revoke(rel123)
unit = ops.Unit('app/0', ops.CharmMeta(), self.model._backend, self.model._cache)
secret.revoke(rel234, unit=unit)

# If secret doesn't have an ID, we'll run secret-info-get to fetch it
secret = self.make_secret(label='y')
self.assertIsNone(secret.id)
rel345 = ops.Relation('test', 345, True, unit, self.model._backend, self.model._cache,
True)
rel345 = ops.Relation('test', 345, True, unit, self.model._backend, self.model._cache)
secret.revoke(rel345)
self.assertEqual(secret.id, 'secret:z')

Expand Down

0 comments on commit ce1e108

Please sign in to comment.