diff --git a/src/lib/base_requires.py b/src/lib/base_requires.py index 6c8bb70..e8ea601 100644 --- a/src/lib/base_requires.py +++ b/src/lib/base_requires.py @@ -72,6 +72,16 @@ class CephRequires(reactive.Endpoint): 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')) diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index b975e80..922dec0 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -180,6 +180,16 @@ class TestCephClientRequires(unittest.TestCase): # 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([