From b147c1a84b3d9d4544ad687d7aeff7aa3d75a58a Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 21 Apr 2015 16:01:57 +0100 Subject: [PATCH] Ensure that migration only occurs when unit can assure that mysql has granted it permissions to access the database --- hooks/cinder_hooks.py | 11 ++++++----- unit_tests/test_cinder_hooks.py | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hooks/cinder_hooks.py b/hooks/cinder_hooks.py index 7529a500..c6307c97 100755 --- a/hooks/cinder_hooks.py +++ b/hooks/cinder_hooks.py @@ -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') diff --git a/unit_tests/test_cinder_hooks.py b/unit_tests/test_cinder_hooks.py index 1a73675f..193c71dc 100644 --- a/unit_tests/test_cinder_hooks.py +++ b/unit_tests/test_cinder_hooks.py @@ -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'])