Wipe 'prefixes' key on relation departed
The prefix key is used to track requests that have been proxied to mysql-innodb-cluster. When a request for a username and password is made the prefix used is stored locally in a list *1. This list of prefixes is also used to check that requests are complete *2 However the list presists after a relation is removed. If the relation is added back the charm reads the old list of prefixes and will not raise the db-router.available flag because it thinks there is an oustanding request *3. *1 https://opendev.org/openstack/charm-interface-mysql-router/src/branch/master/requires.py#L61 *2 https://opendev.org/openstack/charm-interface-mysql-router/src/branch/master/requires.py#L151 *3 https://opendev.org/openstack/charm-interface-mysql-router/src/branch/master/requires.py#L20 Closes-Bug: #1972883 Change-Id: I8ce022a44db37ab83c03442c5f97a843521286d2
This commit is contained in:
parent
21586be61f
commit
77dc778e60
|
@ -41,12 +41,17 @@ class MySQLRouterRequires(reactive.RelationBase):
|
|||
self.remove_state('{relation_name}.proxy.available')
|
||||
self.remove_state('{relation_name}.available.ssl')
|
||||
# Check if this is the last unit
|
||||
last_unit = True
|
||||
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()
|
||||
last_unit = False
|
||||
if last_unit:
|
||||
# Bug #1972883
|
||||
self.set_local('prefixes', [])
|
||||
|
||||
def configure_db_router(self, username, hostname, prefix):
|
||||
"""
|
||||
|
|
|
@ -271,3 +271,15 @@ class TestMySQLRouterRequires(unittest.TestCase):
|
|||
_second = "secondprefix"
|
||||
self.mysql_router.set_prefix(_second)
|
||||
self.set_local.assert_called_once_with("prefixes", [_prefix, _second])
|
||||
|
||||
@mock.patch.object(requires.hookenv, 'related_units')
|
||||
def test_ly_departed(self, related_units):
|
||||
self._local_data = {"prefixes": ["myprefix"]}
|
||||
|
||||
related_units.return_value = ['unit/1']
|
||||
self.mysql_router.departed()
|
||||
self.assertFalse(self.set_local.called)
|
||||
|
||||
related_units.return_value = []
|
||||
self.mysql_router.departed()
|
||||
self.set_local.assert_called_once_with("prefixes", [])
|
||||
|
|
Loading…
Reference in New Issue