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: I215223b41fb2ab6a31df101b5314e6b0859d8322
Closes-Bug: 1803451
This commit is contained in:
Liam Young 2018-11-15 14:12:22 +00:00
parent 604d3a18c8
commit ff96014044
2 changed files with 22 additions and 4 deletions

View File

@ -28,6 +28,9 @@ from charmhelpers.core.hookenv import (
status_set,
relation_ids,
)
from charmhelpers.core.host import (
service_restart
)
from charmhelpers.contrib.openstack.utils import (
pausable_restart_on_change as restart_on_change,
is_unit_paused_set,
@ -43,6 +46,7 @@ from ceilometer_utils import (
get_packages,
pause_unit_helper,
resume_unit_helper,
remove_old_packages,
)
from charmhelpers.contrib.charmsupport import nrpe
@ -81,6 +85,11 @@ def upgrade_charm():
apt_install(
filter_installed_packages(get_packages()),
fatal=True)
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)
# NOTE(jamespage): Ensure any changes to nova presented data are made
# during charm upgrades.
for rid in relation_ids('nova-ceilometer'):

View File

@ -152,6 +152,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 restart_map():
'''
Determine the correct resource map to be passed to
@ -213,10 +225,7 @@ def do_openstack_upgrade(configs):
# openstack-origin which would not be present in a subordinate.
apt_install(get_packages(), 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)