[gnuoy,r=james-page] Add fix for db sync race with remote MySQL ACLS.
This commit is contained in:
commit
b195b505cc
@ -14,6 +14,7 @@ from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
is_relation_made,
|
||||
log,
|
||||
local_unit,
|
||||
ERROR,
|
||||
relation_get,
|
||||
relation_ids,
|
||||
@ -141,6 +142,14 @@ def db_changed():
|
||||
else:
|
||||
CONFIGS.write(KEYSTONE_CONF)
|
||||
if eligible_leader(CLUSTER_RES):
|
||||
# Bugs 1353135 & 1187508. Dbs can appear to be ready before the
|
||||
# units acl entry has been added. So, if the db supports passing
|
||||
# a list of permitted units then check if we're in the list.
|
||||
allowed_units = relation_get('allowed_units')
|
||||
print "allowed_units:" + str(allowed_units)
|
||||
if allowed_units and local_unit() not in allowed_units.split():
|
||||
log('Allowed_units list provided and this unit not present')
|
||||
return
|
||||
migrate_database()
|
||||
ensure_initial_admin(config)
|
||||
# Ensure any existing service entries are updated in the
|
||||
|
@ -26,6 +26,7 @@ TO_PATCH = [
|
||||
'config',
|
||||
'is_relation_made',
|
||||
'log',
|
||||
'local_unit',
|
||||
'filter_installed_packages',
|
||||
'relation_ids',
|
||||
'relation_list',
|
||||
@ -138,7 +139,9 @@ class KeystoneRelationTests(CharmTestCase):
|
||||
'pgsql-db relation incomplete. Peer not ready?'
|
||||
)
|
||||
|
||||
def _shared_db_test(self, configs):
|
||||
def _shared_db_test(self, configs, unit_name):
|
||||
self.relation_get.return_value = 'keystone/0 keystone/3'
|
||||
self.local_unit.return_value = unit_name
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = ['shared-db']
|
||||
configs.write = MagicMock()
|
||||
@ -152,11 +155,11 @@ class KeystoneRelationTests(CharmTestCase):
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
@patch.object(hooks, 'identity_changed')
|
||||
def test_db_changed(self, identity_changed, configs):
|
||||
def test_db_changed_allowed(self, identity_changed, configs):
|
||||
self.relation_ids.return_value = ['identity-service:0']
|
||||
self.related_units.return_value = ['unit/0']
|
||||
|
||||
self._shared_db_test(configs)
|
||||
self._shared_db_test(configs, 'keystone/3')
|
||||
self.assertEquals([call('/etc/keystone/keystone.conf')],
|
||||
configs.write.call_args_list)
|
||||
self.migrate_database.assert_called_with()
|
||||
@ -165,6 +168,19 @@ class KeystoneRelationTests(CharmTestCase):
|
||||
relation_id='identity-service:0',
|
||||
remote_unit='unit/0')
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
@patch.object(hooks, 'identity_changed')
|
||||
def test_db_changed_not_allowed(self, identity_changed, configs):
|
||||
self.relation_ids.return_value = ['identity-service:0']
|
||||
self.related_units.return_value = ['unit/0']
|
||||
|
||||
self._shared_db_test(configs, 'keystone/2')
|
||||
self.assertEquals([call('/etc/keystone/keystone.conf')],
|
||||
configs.write.call_args_list)
|
||||
self.assertFalse(self.migrate_database.called)
|
||||
self.assertFalse(self.ensure_initial_admin.called)
|
||||
self.assertFalse(identity_changed.called)
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
@patch.object(hooks, 'identity_changed')
|
||||
def test_postgresql_db_changed(self, identity_changed, configs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user