Skip to content

Commit

Permalink
implement reactive.Endpoint.manage_flags to clear flags on departed hook
Browse files Browse the repository at this point in the history
Change-Id: Ie2e6d8ec460311fa4e63335f322aaae07dca5842
  • Loading branch information
addyess committed Nov 28, 2022
1 parent 3ca251f commit d9f3b53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/base_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def changed(self):
else:
log("incomplete request. broker_req not found")

def manage_flags(self):
"""
Set states corresponding to the data we have.
"""
reactive.toggle_flag(
self.expand_name("{endpoint_name}.connected"), self.is_joined
)
if not self.is_joined:
self.broken()

def broken(self):
reactive.clear_flag(
self.expand_name('{endpoint_name}.available'))
Expand Down
10 changes: 10 additions & 0 deletions unit_tests/test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ def test_date_changed_existing_broker_rq_incomplete(self):
# Side effect of asserting pools.available was not set.
self.set_flag.assert_called_once_with('some-relation.available')

def test_manage_flags(self):
self.cr.manage_flags()
self.clear_flag.assert_has_calls(
[
mock.call("some-relation.available"),
mock.call("some-relation.connected"),
mock.call("some-relation.pools.available"),
]
)

def test_broken(self):
self.cr.broken()
self.clear_flag.assert_has_calls([
Expand Down

0 comments on commit d9f3b53

Please sign in to comment.