Deal with py2-py3 migration during charm upgrade
On charm upgrade the charm may switch to py3 packages. If so, ensure the old py2 packages are purged after any new packages have been installed. If packages where removed during the upgrade, then restart all services to pickup any py2->py3 switches. Change-Id: I8a17f679e85448680ab0b1f5ae362ef7a65b035c Closes-Bug: 1803451
This commit is contained in:
parent
614db19f8c
commit
2851aefeb5
@ -123,6 +123,7 @@ from keystone_utils import (
|
||||
key_write,
|
||||
pause_unit_helper,
|
||||
resume_unit_helper,
|
||||
remove_old_packages,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.hahelpers.cluster import (
|
||||
@ -707,6 +708,7 @@ def configure_https():
|
||||
def upgrade_charm():
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_install(filter_installed_packages(determine_packages()))
|
||||
packages_removed = remove_old_packages()
|
||||
|
||||
if run_in_apache():
|
||||
disable_unused_apache_sites()
|
||||
@ -718,6 +720,11 @@ def upgrade_charm():
|
||||
|
||||
update_nrpe_config()
|
||||
|
||||
if packages_removed:
|
||||
log("Package purge detected, restarting services", "INFO")
|
||||
for s in services():
|
||||
service_restart(s)
|
||||
|
||||
if is_elected_leader(CLUSTER_RES):
|
||||
log('Cluster leader - ensuring endpoint configuration is up to '
|
||||
'date', level=DEBUG)
|
||||
|
@ -647,6 +647,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 save_script_rc():
|
||||
env_vars = {'OPENSTACK_SERVICE_KEYSTONE': 'keystone',
|
||||
'OPENSTACK_PORT_ADMIN': determine_api_port(
|
||||
@ -680,10 +692,7 @@ def do_openstack_upgrade(configs):
|
||||
apt_install(packages=determine_packages(),
|
||||
options=dpkg_opts, fatal=True)
|
||||
|
||||
installed_pkgs = filter_missing_packages(determine_purge_packages())
|
||||
if installed_pkgs:
|
||||
apt_purge(installed_pkgs, fatal=True)
|
||||
apt_autoremove(purge=True, fatal=True)
|
||||
remove_old_packages()
|
||||
else:
|
||||
# TODO: Add support for upgrade from deb->snap
|
||||
# NOTE(thedac): Setting devmode until LP#1719636 is fixed
|
||||
|
@ -90,6 +90,8 @@ TO_PATCH = [
|
||||
'key_leader_set',
|
||||
'key_setup',
|
||||
'key_write',
|
||||
'remove_old_packages',
|
||||
'services',
|
||||
# other
|
||||
'check_call',
|
||||
'execd_preinstall',
|
||||
@ -700,11 +702,15 @@ class KeystoneRelationTests(CharmTestCase):
|
||||
mock_is_db_initialised.return_value = True
|
||||
mock_is_db_ready.return_value = True
|
||||
mock_relation_ids.return_value = []
|
||||
self.remove_old_packages.return_value = True
|
||||
self.services.return_value = ['apache2']
|
||||
|
||||
self.filter_installed_packages.return_value = []
|
||||
hooks.upgrade_charm()
|
||||
self.assertTrue(self.apt_install.called)
|
||||
self.assertTrue(update.called)
|
||||
self.remove_old_packages.assert_called_once_with()
|
||||
self.service_restart.assert_called_with('apache2')
|
||||
|
||||
@patch.object(hooks, 'update_all_identity_relation_units')
|
||||
@patch.object(hooks, 'is_db_initialised')
|
||||
|
Loading…
Reference in New Issue
Block a user