Purge old packages on upgrade-charm

On charm upgrade the charm may switch to py3 packages. If so, ensure
the old py2 packages are purged. If the purge occurs then restart
services.

Change-Id: I23812e518d5d0ba64dff33ac8d704b8b0f829b7e
Closes-Bug: 1803451
This commit is contained in:
Liam Young 2018-11-15 13:57:21 +00:00
parent d394a61682
commit 8cde93e515
3 changed files with 34 additions and 4 deletions

View File

@ -80,6 +80,7 @@ from ceilometer_utils import (
reload_systemd,
pause_unit_helper,
resume_unit_helper,
remove_old_packages,
)
from ceilometer_contexts import CEILOMETER_PORT
from charmhelpers.contrib.openstack.ip import (
@ -262,6 +263,11 @@ def install_event_pipeline_setting():
@harden()
def upgrade_charm():
install()
packages_removed = remove_old_packages()
if packages_removed and not is_unit_paused_set():
log("Package purge detected, restarting services", "INFO")
for s in services():
service_restart(s)
update_nrpe_config()
any_changed()
for rid in relation_ids('cluster'):

View File

@ -380,10 +380,7 @@ def do_openstack_upgrade(configs):
options=dpkg_opts,
fatal=True)
installed_packages = filter_missing_packages(determine_purge_packages())
if installed_packages:
apt_purge(installed_packages, fatal=True)
apt_autoremove(purge=True, fatal=True)
remove_old_packages()
# set CONFIGS to load templates from new release
configs.set_release(openstack_release=new_os_rel)
@ -448,6 +445,18 @@ def determine_purge_packages():
return []
def remove_old_packages():
'''Purge any packages that need ot be removed.
:returns: bool Whether packages were removed.
'''
installed_packages = filter_missing_packages(determine_purge_packages())
if installed_packages:
apt_purge(installed_packages, fatal=True)
apt_autoremove(purge=True, fatal=True)
return bool(installed_packages)
def get_shared_secret():
"""
Returns the current shared secret for the ceilometer node. If the shared

View File

@ -71,6 +71,8 @@ TO_PATCH = [
'get_relation_ip',
'is_clustered',
'get_os_codename_install_source',
'services',
'remove_old_packages',
]
@ -151,10 +153,23 @@ class CeilometerHooksTest(CharmTestCase):
@patch.object(hooks, 'install')
@patch.object(hooks, 'any_changed')
def test_upgrade_charm(self, changed, install, mock_config):
self.remove_old_packages.return_value = False
hooks.hooks.execute(['hooks/upgrade-charm'])
self.assertTrue(changed.called)
self.assertTrue(install.called)
@patch('charmhelpers.core.hookenv.config')
@patch.object(hooks, 'install')
@patch.object(hooks, 'any_changed')
def test_upgrade_charm_purge(self, changed, install, mock_config):
self.remove_old_packages.return_value = True
self.services.return_value = ['ceilometer-important-service']
hooks.hooks.execute(['hooks/upgrade-charm'])
self.assertTrue(changed.called)
self.assertTrue(install.called)
self.service_restart.assert_called_once_with(
'ceilometer-important-service')
@patch.object(hooks, 'any_changed')
@patch('charmhelpers.core.hookenv.config')
@patch.object(hooks, 'cluster_joined')