diff --git a/hooks/glance_relations.py b/hooks/glance_relations.py index 4f7051e6..97a71d02 100755 --- a/hooks/glance_relations.py +++ b/hooks/glance_relations.py @@ -35,6 +35,7 @@ from subprocess import ( ) from glance_utils import ( + backup_deprecated_configurations, do_openstack_upgrade, migrate_database, register_configs, @@ -488,6 +489,7 @@ def upgrade_charm(): resolve_CONFIGS() apt_install(filter_installed_packages(determine_packages()), fatal=True) packages_removed = remove_old_packages() + backup_deprecated_configurations() reinstall_paste_ini(force_reinstall=packages_removed) configure_https() update_nrpe_config() diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index ef663e5a..d1f5a02d 100644 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -651,6 +651,22 @@ def reinstall_paste_ini(force_reinstall=False): db.flush() +def backup_deprecated_configurations(): + """Backup deprecated configurations + + Do not keep deprecated configurations files as they + can create configuration issues. + + See LP#1979090""" + release = os_release('glance-common') + cmp_release = CompareOpenStackReleases(release) + + # Glance registry removed in S release + if cmp_release >= "stein": + if os.path.exists(GLANCE_REGISTRY_CONF): + os.rename(GLANCE_REGISTRY_CONF, GLANCE_REGISTRY_CONF + ".old") + + def is_api_ready(configs): return (not incomplete_relation_data(configs, REQUIRED_INTERFACES)) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 09569617..eac5f884 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -98,6 +98,7 @@ TO_PATCH = [ 'determine_packages', 'remove_old_packages', 'services', + 'backup_deprecated_configurations', # other 'call', 'check_call', @@ -571,6 +572,7 @@ class GlanceRelationTests(CharmTestCase): self.assertTrue(self.reinstall_paste_ini.called) self.assertTrue(mock_update_image_location_policy.called) self.assertTrue(self.remove_old_packages.called) + self.assertTrue(self.backup_deprecated_configurations.called) @patch.object(relations, 'update_image_location_policy') @patch.object(relations, 'CONFIGS') diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index 8eb56540..bcacc0af 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -142,6 +142,12 @@ class TestGlanceUtils(CharmTestCase): ) configs.register.assert_has_calls(calls, any_order=True) + def test_register_configs_stein(self): + self.os_release.return_value = 'stein' + self.relation_ids.return_value = False + configs = utils.register_configs() + self.assertNotIn(utils.GLANCE_REGISTRY_CONF, configs.templates) + def test_restart_map_rocky(self): self.enable_memcache.return_value = True self.config.side_effect = None @@ -261,6 +267,16 @@ class TestGlanceUtils(CharmTestCase): configs.set_release.assert_called_with(openstack_release='rocky') self.assertTrue(migrate.called) + @patch('os.rename') + @patch('os.path.exists') + @patch.object(utils, 'migrate_database') + def test_openstack_backup_stein(self, migrate, exists, rename): + exists.return_value = True + self.os_release.return_value = 'stein' + utils.backup_deprecated_configurations() + rename.assert_called_with(utils.GLANCE_REGISTRY_CONF, + utils.GLANCE_REGISTRY_CONF + '.old') + @patch.object(utils, 'migrate_database') def test_openstack_upgrade_not_leader(self, migrate): self.config.side_effect = None