Fixup upgrades to ensure that only the leader attempts to migrate the database

This commit is contained in:
James Page 2015-06-29 12:33:36 +01:00
parent 89157b540e
commit 2d2e950e8f
2 changed files with 45 additions and 1 deletions

View File

@ -48,6 +48,7 @@ from charmhelpers.core.host import (
) )
from charmhelpers.core.templating import render from charmhelpers.core.templating import render
from charmhelpers.contrib.hahelpers.cluster import is_elected_leader
import neutron_api_context import neutron_api_context
@ -292,7 +293,7 @@ def do_openstack_upgrade(configs):
# set CONFIGS to load templates from new release # set CONFIGS to load templates from new release
configs.set_release(openstack_release=new_os_rel) configs.set_release(openstack_release=new_os_rel)
# Before kilo it's nova-cloud-controllers job # Before kilo it's nova-cloud-controllers job
if new_os_rel >= 'kilo': if is_elected_leader(CLUSTER_RES) and new_os_rel >= 'kilo':
stamp_neutron_database(cur_os_rel) stamp_neutron_database(cur_os_rel)
migrate_neutron_database() migrate_neutron_database()

View File

@ -33,6 +33,7 @@ TO_PATCH = [
'os_release', 'os_release',
'pip_install', 'pip_install',
'subprocess', 'subprocess',
'is_elected_leader',
] ]
openstack_origin_git = \ openstack_origin_git = \
@ -190,6 +191,7 @@ class TestNeutronAPIUtils(CharmTestCase):
def test_do_openstack_upgrade_juno(self, git_requested, def test_do_openstack_upgrade_juno(self, git_requested,
stamp_neutron_db, migrate_neutron_db): stamp_neutron_db, migrate_neutron_db):
git_requested.return_value = False git_requested.return_value = False
self.is_elected_leader.return_value = True
self.config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get
self.test_config.set('openstack-origin', 'cloud:trusty-juno') self.test_config.set('openstack-origin', 'cloud:trusty-juno')
self.os_release.return_value = 'icehouse' self.os_release.return_value = 'icehouse'
@ -227,6 +229,7 @@ class TestNeutronAPIUtils(CharmTestCase):
stamp_neutron_db, migrate_neutron_db, stamp_neutron_db, migrate_neutron_db,
gsrc): gsrc):
git_requested.return_value = False git_requested.return_value = False
self.is_elected_leader.return_value = True
self.os_release.return_value = 'juno' self.os_release.return_value = 'juno'
self.config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get
self.test_config.set('openstack-origin', 'cloud:trusty-kilo') self.test_config.set('openstack-origin', 'cloud:trusty-kilo')
@ -256,6 +259,46 @@ class TestNeutronAPIUtils(CharmTestCase):
stamp_neutron_db.assert_called_with('juno') stamp_neutron_db.assert_called_with('juno')
migrate_neutron_db.assert_called_with() migrate_neutron_db.assert_called_with()
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_install_source')
@patch.object(nutils, 'migrate_neutron_database')
@patch.object(nutils, 'stamp_neutron_database')
@patch.object(nutils, 'git_install_requested')
def test_do_openstack_upgrade_kilo_notleader(self, git_requested,
stamp_neutron_db,
migrate_neutron_db,
gsrc):
git_requested.return_value = False
self.is_elected_leader.return_value = False
self.os_release.return_value = 'juno'
self.config.side_effect = self.test_config.get
self.test_config.set('openstack-origin', 'cloud:trusty-kilo')
gsrc.return_value = 'kilo'
self.get_os_codename_install_source.return_value = 'kilo'
configs = MagicMock()
nutils.do_openstack_upgrade(configs)
self.os_release.assert_called_with('neutron-server')
self.log.assert_called()
self.configure_installation_source.assert_called_with(
'cloud:trusty-kilo'
)
self.apt_update.assert_called_with(fatal=True)
dpkg_opts = [
'--option', 'Dpkg::Options::=--force-confnew',
'--option', 'Dpkg::Options::=--force-confdef',
]
self.apt_upgrade.assert_called_with(options=dpkg_opts,
fatal=True,
dist=True)
pkgs = nutils.determine_packages()
pkgs.sort()
self.apt_install.assert_called_with(packages=pkgs,
options=dpkg_opts,
fatal=True)
configs.set_release.assert_called_with(openstack_release='kilo')
self.assertFalse(stamp_neutron_db.called)
self.assertFalse(migrate_neutron_db.called)
@patch.object(ncontext, 'IdentityServiceContext') @patch.object(ncontext, 'IdentityServiceContext')
@patch('neutronclient.v2_0.client.Client') @patch('neutronclient.v2_0.client.Client')
def test_get_neutron_client(self, nclient, IdentityServiceContext): def test_get_neutron_client(self, nclient, IdentityServiceContext):