Ensure that migration only occurs when unit can assure that mysql has granted it permissions to access the database
This commit is contained in:
parent
8a9d1d2a69
commit
b147c1a84b
@ -195,11 +195,12 @@ def db_changed():
|
||||
# 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')
|
||||
if allowed_units and local_unit() not in allowed_units.split():
|
||||
juju_log('Allowed_units list provided and this unit not present')
|
||||
return
|
||||
juju_log('Cluster leader, performing db sync')
|
||||
migrate_database()
|
||||
if allowed_units and local_unit() in allowed_units.split():
|
||||
juju_log('Cluster leader, performing db sync')
|
||||
migrate_database()
|
||||
else:
|
||||
juju_log('allowed_units either not presented, or local unit '
|
||||
'not in acl list: %s' % allowed_units)
|
||||
|
||||
|
||||
@hooks.hook('pgsql-db-relation-changed')
|
||||
|
@ -244,6 +244,15 @@ class TestChangedHooks(CharmTestCase):
|
||||
hooks.hooks.execute(['hooks/shared-db-relation-changed'])
|
||||
self.assertFalse(self.migrate_database.called)
|
||||
|
||||
def test_db_changed_relation_db_missing_acls(self):
|
||||
'It does not migration when acl list is not present'
|
||||
self.relation_get.return_value = None
|
||||
self.local_unit.return_value = 'cinder/0'
|
||||
self.CONFIGS.complete_contexts.return_value = ['shared-db']
|
||||
self.eligible_leader.return_value = True
|
||||
hooks.hooks.execute(['hooks/shared-db-relation-changed'])
|
||||
self.assertFalse(self.migrate_database.called)
|
||||
|
||||
def test_pgsql_db_changed_relation_incomplete(self):
|
||||
'It does not write out cinder.conf with incomplete pgsql-db rel'
|
||||
hooks.hooks.execute(['hooks/pgsql-db-relation-changed'])
|
||||
|
Loading…
Reference in New Issue
Block a user