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: I2f5d95d9688c48e97fbb9b8b11a23d4b6250e016
Closes-Bug: 1803451
This commit is contained in:
Liam Young 2018-11-15 12:14:11 +00:00
parent 7626a55b4a
commit a42a2a8f3c
3 changed files with 32 additions and 4 deletions

View File

@ -42,6 +42,7 @@ from charmhelpers.core.hookenv import (
from charmhelpers.core.host import (
mkdir,
service_reload,
service_restart,
)
from charmhelpers.fetch import (
@ -86,6 +87,7 @@ from neutron_api_utils import (
check_local_db_actions_complete,
pause_unit_helper,
resume_unit_helper,
remove_old_packages,
)
from neutron_api_context import (
get_dns_domain,
@ -295,9 +297,14 @@ def config_changed():
apt_install(filter_installed_packages(
determine_packages(config('openstack-origin'))),
fatal=True)
packages_removed = remove_old_packages()
configure_https()
update_nrpe_config()
CONFIGS.write_all()
if packages_removed and not is_unit_paused_set():
log("Package purge detected, restarting services", "INFO")
for s in services():
service_restart(s)
for r_id in relation_ids('neutron-api'):
neutron_api_relation_joined(rid=r_id)
for r_id in relation_ids('neutron-plugin-api'):

View File

@ -427,6 +427,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 determine_ports():
'''Assemble a list of API ports for services we are managing'''
ports = []
@ -549,10 +561,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)

View File

@ -91,6 +91,9 @@ TO_PATCH = [
'get_relation_ip',
'update_dns_ha_resource_params',
'is_nsg_logging_enabled',
'remove_old_packages',
'services',
'service_restart',
]
NEUTRON_CONF_DIR = "/etc/neutron"
@ -222,6 +225,7 @@ class NeutronAPIHooksTests(CharmTestCase):
self._call_hook('config-changed')
def test_config_changed_with_openstack_upgrade_action(self):
self.remove_old_packages.return_value = False
self.openstack_upgrade_available.return_value = True
self.test_config.set('action-managed-upgrade', True)
@ -229,6 +233,14 @@ class NeutronAPIHooksTests(CharmTestCase):
self.assertFalse(self.do_openstack_upgrade.called)
def test_config_changed_with_purge(self):
self.remove_old_packages.return_value = True
self.services.return_value = ['neutron-server']
self.openstack_upgrade_available.return_value = False
self._call_hook('config-changed')
self.remove_old_packages.assert_called_once_with()
self.service_restart.assert_called_once_with('neutron-server')
def test_amqp_joined(self):
self._call_hook('amqp-relation-joined')
self.relation_set.assert_called_with(