Restore original paste files if glance-common
re-installation does not restore them. Implemented a unit test function for the above scenario. Call apt_update from upgrade_charm(). Closes-Bug: #2042792 Change-Id: I57c5fa293b421483b0879f24ddac260e47c7cbef
This commit is contained in:
parent
ad0097b5e6
commit
59efce8bc8
|
@ -487,6 +487,7 @@ def cluster_changed():
|
||||||
@harden()
|
@harden()
|
||||||
def upgrade_charm():
|
def upgrade_charm():
|
||||||
resolve_CONFIGS()
|
resolve_CONFIGS()
|
||||||
|
apt_update()
|
||||||
apt_install(filter_installed_packages(determine_packages()), fatal=True)
|
apt_install(filter_installed_packages(determine_packages()), fatal=True)
|
||||||
packages_removed = remove_old_packages()
|
packages_removed = remove_old_packages()
|
||||||
backup_deprecated_configurations()
|
backup_deprecated_configurations()
|
||||||
|
|
|
@ -636,7 +636,7 @@ def reinstall_paste_ini(force_reinstall=False):
|
||||||
for paste_file in [GLANCE_REGISTRY_PASTE,
|
for paste_file in [GLANCE_REGISTRY_PASTE,
|
||||||
GLANCE_API_PASTE]:
|
GLANCE_API_PASTE]:
|
||||||
if os.path.exists(paste_file):
|
if os.path.exists(paste_file):
|
||||||
os.remove(paste_file)
|
os.replace(paste_file, f'{paste_file}.charm.upgrade')
|
||||||
# glance-registry is deprecated at queens but still
|
# glance-registry is deprecated at queens but still
|
||||||
# installed.
|
# installed.
|
||||||
if cmp_release < 'rocky':
|
if cmp_release < 'rocky':
|
||||||
|
@ -647,6 +647,15 @@ def reinstall_paste_ini(force_reinstall=False):
|
||||||
apt_install(packages=pkg_list,
|
apt_install(packages=pkg_list,
|
||||||
options=REINSTALL_OPTIONS,
|
options=REINSTALL_OPTIONS,
|
||||||
fatal=True)
|
fatal=True)
|
||||||
|
# LP: #2042792 Restore original paste files
|
||||||
|
for paste_file in [GLANCE_REGISTRY_PASTE,
|
||||||
|
GLANCE_API_PASTE]:
|
||||||
|
if not os.path.exists(paste_file):
|
||||||
|
if os.path.exists(f'{paste_file}.charm.upgrade'):
|
||||||
|
os.replace(f'{paste_file}.charm.upgrade', paste_file)
|
||||||
|
else:
|
||||||
|
if os.path.exists(f'{paste_file}.charm.upgrade'):
|
||||||
|
os.remove(f'{paste_file}.charm.upgrade')
|
||||||
db.set(PASTE_INI_MARKER, True)
|
db.set(PASTE_INI_MARKER, True)
|
||||||
db.flush()
|
db.flush()
|
||||||
|
|
||||||
|
|
|
@ -369,10 +369,6 @@ class TestGlanceUtils(CharmTestCase):
|
||||||
call(utils.GLANCE_REGISTRY_PASTE),
|
call(utils.GLANCE_REGISTRY_PASTE),
|
||||||
call(utils.GLANCE_API_PASTE),
|
call(utils.GLANCE_API_PASTE),
|
||||||
])
|
])
|
||||||
_os.remove.assert_has_calls([
|
|
||||||
call(utils.GLANCE_REGISTRY_PASTE),
|
|
||||||
call(utils.GLANCE_API_PASTE),
|
|
||||||
])
|
|
||||||
self.assertTrue(test_kv.get(utils.PASTE_INI_MARKER))
|
self.assertTrue(test_kv.get(utils.PASTE_INI_MARKER))
|
||||||
self.assertTrue(test_kv.flushed)
|
self.assertTrue(test_kv.flushed)
|
||||||
|
|
||||||
|
@ -439,6 +435,32 @@ class TestGlanceUtils(CharmTestCase):
|
||||||
utils.reinstall_paste_ini()
|
utils.reinstall_paste_ini()
|
||||||
self.assertTrue(self.apt_install.called)
|
self.assertTrue(self.apt_install.called)
|
||||||
|
|
||||||
|
@patch.object(utils, 'os_release')
|
||||||
|
@patch.object(utils, 'os')
|
||||||
|
@patch.object(utils, 'kv')
|
||||||
|
def test_reinstall_paste_ini_rocky_restore(self, kv, _os, mock_os_release):
|
||||||
|
"""Ensure that paste.ini files are restored"""
|
||||||
|
mock_os_release.return_value = 'rocky'
|
||||||
|
_os.path.exists.return_value = True
|
||||||
|
test_kv = SimpleKV()
|
||||||
|
test_kv.set(utils.PASTE_INI_MARKER, False)
|
||||||
|
kv.return_value = test_kv
|
||||||
|
|
||||||
|
self.apt_install.reset_mock()
|
||||||
|
utils.reinstall_paste_ini()
|
||||||
|
|
||||||
|
self.apt_install.assert_called_with(
|
||||||
|
packages=['glance-common'],
|
||||||
|
options=utils.REINSTALL_OPTIONS,
|
||||||
|
fatal=True
|
||||||
|
)
|
||||||
|
reg_paste_backup = f'{utils.GLANCE_REGISTRY_PASTE}.charm.upgrade'
|
||||||
|
api_paste_backup = f'{utils.GLANCE_API_PASTE}.charm.upgrade'
|
||||||
|
_os.remove.assert_has_calls([
|
||||||
|
call(reg_paste_backup),
|
||||||
|
call(api_paste_backup),
|
||||||
|
])
|
||||||
|
|
||||||
def _test_is_api_ready(self, tgt):
|
def _test_is_api_ready(self, tgt):
|
||||||
fake_config = MagicMock()
|
fake_config = MagicMock()
|
||||||
with patch.object(utils, 'incomplete_relation_data') as ird:
|
with patch.object(utils, 'incomplete_relation_data') as ird:
|
||||||
|
|
Loading…
Reference in New Issue