Backup glance registry configuration files on upgrade >= Stein

Glance Registry has been deprecated in Stein release.
Leftover configuration files can still be read and
configure wrong settings, breaking deployment.

Closes-Bug: 1979090
Change-Id: I54b72aef0fd49b036cf1783ef9887fa9243c93f8
This commit is contained in:
Guillaume Boutry 2023-02-13 09:12:47 +01:00
parent 96a2bb3af9
commit ef5d6de615
No known key found for this signature in database
GPG Key ID: E95E3326872E55DE
4 changed files with 36 additions and 0 deletions

View File

@ -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()

View File

@ -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))

View File

@ -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')

View File

@ -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