From c1653c21136d0cb10a3b3ee41c6aeeacdb51c00a Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 23 Oct 2017 23:24:14 +0100 Subject: [PATCH] Ensure upgrade installs correct configs When we do an openstack upgrade we must ensure that release version dependant decisions are made at the right time. In this patch we ensure that we choose configs after the target release packages have been installed so as to be sure that e.g. when upgrading from Newton to Ocata the apache2 wsgi conf is installed for the cinder-api. Change-Id: I9414940535406c7c7491636839a328df1ac9235b Closes-Bug: 1726527 --- actions/openstack_upgrade.py | 3 +-- hooks/cinder_utils.py | 7 ++++++- unit_tests/test_cinder_utils.py | 14 ++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py index 7eb8ba56..4412a0ab 100755 --- a/actions/openstack_upgrade.py +++ b/actions/openstack_upgrade.py @@ -30,7 +30,6 @@ from charmhelpers.core.hookenv import ( from cinder_hooks import ( config_changed, - CONFIGS, ) from cinder_utils import ( @@ -48,7 +47,7 @@ def openstack_upgrade(): if (do_action_openstack_upgrade('cinder-common', do_openstack_upgrade, - CONFIGS)): + configs=None)): # tell any storage-backends we just upgraded for rid in relation_ids('storage-backend'): relation_set(relation_id=rid, diff --git a/hooks/cinder_utils.py b/hooks/cinder_utils.py index 8e88aae5..7920c3c8 100644 --- a/hooks/cinder_utils.py +++ b/hooks/cinder_utils.py @@ -733,7 +733,7 @@ def set_ceph_env_variables(service): out.write('env CEPH_ARGS="--id %s"\n' % service) -def do_openstack_upgrade(configs): +def do_openstack_upgrade(configs=None): """Perform an uprade of cinder. Takes care of upgrading packages, rewriting configs + database migration and potentially any other post-upgrade actions. @@ -756,6 +756,11 @@ def do_openstack_upgrade(configs): reset_os_release() apt_install(determine_packages(), fatal=True) + # NOTE(hopem): must do this after packages have been upgraded so that + # we ensure that correct configs are selected for the target release. + # See LP 1726527. + configs = register_configs() + # set CONFIGS to load templates from new release and regenerate config configs.set_release(openstack_release=new_os_rel) configs.write_all() diff --git a/unit_tests/test_cinder_utils.py b/unit_tests/test_cinder_utils.py index f3ebd00e..9c5b56d4 100644 --- a/unit_tests/test_cinder_utils.py +++ b/unit_tests/test_cinder_utils.py @@ -732,10 +732,12 @@ class TestCinderUtils(CharmTestCase): out.write('env CEPH_ARGS="--id %s"\n' % service) """ + @patch.object(cinder_utils, 'register_configs') @patch.object(cinder_utils, 'services') @patch.object(cinder_utils, 'migrate_database') @patch.object(cinder_utils, 'determine_packages') - def test_openstack_upgrade_leader(self, pkgs, migrate, services): + def test_openstack_upgrade_leader(self, pkgs, migrate, services, + mock_register_configs): pkgs.return_value = ['mypackage'] self.os_release.return_value = 'havana' self.config.side_effect = None @@ -743,8 +745,9 @@ class TestCinderUtils(CharmTestCase): services.return_value = ['cinder-api', 'cinder-volume'] self.is_elected_leader.return_value = True self.get_os_codename_install_source.return_value = 'havana' - configs = MagicMock() + configs = mock_register_configs.return_value cinder_utils.do_openstack_upgrade(configs) + self.assertTrue(mock_register_configs.called) self.assertTrue(configs.write_all.called) self.apt_upgrade.assert_called_with(options=DPKG_OPTIONS, fatal=True, dist=True) @@ -752,10 +755,12 @@ class TestCinderUtils(CharmTestCase): configs.set_release.assert_called_with(openstack_release='havana') self.assertTrue(migrate.called) + @patch.object(cinder_utils, 'register_configs') @patch.object(cinder_utils, 'services') @patch.object(cinder_utils, 'migrate_database') @patch.object(cinder_utils, 'determine_packages') - def test_openstack_upgrade_not_leader(self, pkgs, migrate, services): + def test_openstack_upgrade_not_leader(self, pkgs, migrate, services, + mock_register_configs): pkgs.return_value = ['mypackage'] self.os_release.return_value = 'havana' self.config.side_effect = None @@ -763,8 +768,9 @@ class TestCinderUtils(CharmTestCase): services.return_value = ['cinder-api', 'cinder-volume'] self.is_elected_leader.return_value = False self.get_os_codename_install_source.return_value = 'havana' - configs = MagicMock() + configs = mock_register_configs.return_value cinder_utils.do_openstack_upgrade(configs) + self.assertTrue(mock_register_configs.called) self.assertTrue(configs.write_all.called) self.apt_upgrade.assert_called_with(options=DPKG_OPTIONS, fatal=True, dist=True)