Check if any HA units remain on departed

If there are still HA units in the relation when a single unit departs
re-evaluate state. If it is the last unit, unset all relation states.

Handle the case juju remove-relation and juju add-relation.

Change-Id: I92909d6203fc00d45d7d6edf0a981f9d759add53
Partial-Bug: #1800730
This commit is contained in:
David Ames 2018-11-16 11:43:35 -08:00
parent 59f2822e9c
commit efa7cb3d5a
1 changed files with 8 additions and 0 deletions

View File

@ -27,10 +27,18 @@ class MySQLSharedRequires(RelationBase):
@hook('{requires:mysql-shared}-relation-{broken,departed}')
def departed(self):
# Clear state
self.remove_state('{relation_name}.connected')
self.remove_state('{relation_name}.available')
self.remove_state('{relation_name}.available.access_network')
self.remove_state('{relation_name}.available.ssl')
# Check if this is the last unit
for conversation in self.conversations():
for rel_id in conversation.relation_ids:
if len(hookenv.related_units(rel_id)) > 0:
# This is not the last unit so reevaluate state
self.joined()
self.changed()
def configure(self, database, username, hostname=None, prefix=None):
"""