Only run db migration once
This change follows the existing pattern that the keystone charm uses to only run db migration once. To ensure it only runs once a flag is placed in the leader db once it has run. Change-Id: Iaba10cc70f60faa33e00cc5d33e03626f54374f9
This commit is contained in:
parent
f3aafbb182
commit
fcde1b022b
|
@ -105,6 +105,7 @@ from charmhelpers.contrib.openstack.utils import (
|
|||
series_upgrade_prepare,
|
||||
series_upgrade_complete,
|
||||
CompareOpenStackReleases,
|
||||
is_db_initialised,
|
||||
)
|
||||
from charmhelpers.contrib.storage.linux.ceph import (
|
||||
send_request_if_needed,
|
||||
|
@ -222,8 +223,11 @@ def db_changed():
|
|||
cmd = ["glance-manage", "version_control", "0"]
|
||||
check_call(cmd)
|
||||
|
||||
juju_log('Cluster leader, performing db sync')
|
||||
migrate_database()
|
||||
if is_db_initialised():
|
||||
juju_log('Skipping DB sync, database already initialised')
|
||||
else:
|
||||
juju_log('Cluster leader, performing db sync')
|
||||
migrate_database()
|
||||
else:
|
||||
juju_log('allowed_units either not presented, or local unit '
|
||||
'not in acl list: {}'.format(allowed_units))
|
||||
|
|
|
@ -74,6 +74,7 @@ from charmhelpers.contrib.openstack.utils import (
|
|||
resume_unit,
|
||||
token_cache_pkgs,
|
||||
update_json_file,
|
||||
set_db_initialised,
|
||||
)
|
||||
|
||||
from charmhelpers.core.decorators import (
|
||||
|
@ -298,6 +299,7 @@ def migrate_database():
|
|||
'''
|
||||
cmd = ['glance-manage', 'db_sync']
|
||||
subprocess.check_call(cmd)
|
||||
set_db_initialised()
|
||||
|
||||
|
||||
def remove_old_packages():
|
||||
|
|
|
@ -74,6 +74,7 @@ TO_PATCH = [
|
|||
'service_restart',
|
||||
# charmhelpers.contrib.openstack.utils
|
||||
'configure_installation_source',
|
||||
'is_db_initialised',
|
||||
'os_release',
|
||||
'openstack_upgrade_available',
|
||||
# charmhelpers.contrib.openstack.policyd
|
||||
|
@ -150,6 +151,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_missing_relation_data(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = []
|
||||
relations.db_changed()
|
||||
|
@ -168,6 +170,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_allowed(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
self._shared_db_test(configs, 'glance/0')
|
||||
self.assertEqual([call('/etc/glance/glance-registry.conf'),
|
||||
call('/etc/glance/glance-api.conf')],
|
||||
|
@ -179,6 +182,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_not_allowed(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
self._shared_db_test(configs, 'glance/2')
|
||||
self.assertEqual([call('/etc/glance/glance-registry.conf'),
|
||||
call('/etc/glance/glance-api.conf')],
|
||||
|
@ -187,6 +191,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_no_acls(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
self._shared_db_test(configs, 'glance/2', None)
|
||||
self.assertEqual([call('/etc/glance/glance-registry.conf'),
|
||||
call('/etc/glance/glance-api.conf')],
|
||||
|
@ -196,6 +201,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
@patch.object(relations, 'image_service_joined')
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_image_service_joined(self, configs, imgsj):
|
||||
self.is_db_initialised.return_value = False
|
||||
rids = ['nova-cloud-controller:1', 'nova-compute:1']
|
||||
self.relation_ids.return_value = rids
|
||||
self._shared_db_test(configs, 'glance/2', None)
|
||||
|
@ -203,6 +209,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_with_essex_not_setting_version_control(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
self.os_release.return_value = "essex"
|
||||
self.call.return_value = 0
|
||||
self._shared_db_test(configs, 'glance/0')
|
||||
|
@ -215,6 +222,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||
|
||||
@patch.object(relations, 'CONFIGS')
|
||||
def test_db_changed_with_essex_setting_version_control(self, configs):
|
||||
self.is_db_initialised.return_value = False
|
||||
self.os_release.return_value = "essex"
|
||||
self.call.return_value = 1
|
||||
self._shared_db_test(configs, 'glance/0')
|
||||
|
|
|
@ -49,6 +49,7 @@ TO_PATCH = [
|
|||
'os_application_version_set',
|
||||
'enable_memcache',
|
||||
'token_cache_pkgs',
|
||||
'set_db_initialised',
|
||||
]
|
||||
|
||||
DPKG_OPTS = [
|
||||
|
@ -68,6 +69,7 @@ class TestGlanceUtils(CharmTestCase):
|
|||
"It migrates database with cinder-manage"
|
||||
utils.migrate_database()
|
||||
check_call.assert_called_with(['glance-manage', 'db_sync'])
|
||||
self.set_db_initialised.assert_called_once_with()
|
||||
|
||||
@patch('os.path.exists')
|
||||
def test_register_configs_apache(self, exists):
|
||||
|
|
Loading…
Reference in New Issue