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: I3e67d35324888522f6c138ebd74a2ea7f1a4ce05 Closes-Bug: 1803451
This commit is contained in:
parent
b1bfc915a6
commit
d3ca911e24
@ -46,6 +46,7 @@ from cinder_utils import (
|
||||
scrub_old_style_ceph,
|
||||
pause_unit_helper,
|
||||
resume_unit_helper,
|
||||
remove_old_packages,
|
||||
)
|
||||
|
||||
from cinder_contexts import ceph_config_file
|
||||
@ -589,10 +590,15 @@ def configure_https():
|
||||
@harden()
|
||||
def upgrade_charm():
|
||||
apt_install(determine_packages(), fatal=True)
|
||||
packages_removed = remove_old_packages()
|
||||
for rel_id in relation_ids('amqp'):
|
||||
amqp_joined(relation_id=rel_id)
|
||||
update_nrpe_config()
|
||||
scrub_old_style_ceph()
|
||||
if packages_removed:
|
||||
juju_log("Package purge detected, restarting services")
|
||||
for s in services():
|
||||
service_restart(s)
|
||||
|
||||
|
||||
@hooks.hook('storage-backend-relation-changed')
|
||||
|
@ -375,6 +375,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 service_enabled(service):
|
||||
'''Determine if a specific cinder service is enabled in
|
||||
charm configuration.
|
||||
@ -747,10 +759,7 @@ def do_openstack_upgrade(configs=None):
|
||||
reset_os_release()
|
||||
apt_install(determine_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()
|
||||
|
||||
# NOTE(hopem): must do this after packages have been upgraded so that
|
||||
# we ensure that correct configs are selected for the target release.
|
||||
|
@ -59,6 +59,7 @@ TO_PATCH = [
|
||||
'CLUSTER_RES',
|
||||
'ceph_config_file',
|
||||
'update_nrpe_config',
|
||||
'remove_old_packages',
|
||||
# charmhelpers.core.hookenv
|
||||
'config',
|
||||
'local_unit',
|
||||
@ -87,6 +88,7 @@ TO_PATCH = [
|
||||
'sync_db_with_multi_ipv6_addresses',
|
||||
'delete_keyring',
|
||||
'get_relation_ip',
|
||||
'services',
|
||||
]
|
||||
|
||||
|
||||
@ -119,11 +121,23 @@ class TestChangedHooks(CharmTestCase):
|
||||
@patch.object(hooks, 'scrub_old_style_ceph')
|
||||
@patch.object(hooks, 'amqp_joined')
|
||||
def test_upgrade_charm_no_amqp(self, _joined, _scrub_old_style_ceph):
|
||||
self.remove_old_packages.return_value = False
|
||||
self.relation_ids.return_value = []
|
||||
hooks.hooks.execute(['hooks/upgrade-charm'])
|
||||
_joined.assert_not_called()
|
||||
_scrub_old_style_ceph.assert_called_once_with()
|
||||
|
||||
@patch.object(hooks, 'scrub_old_style_ceph')
|
||||
@patch.object(hooks, 'amqp_joined')
|
||||
def test_upgrade_charm_purge(self, _joined, _scrub_old_style_ceph):
|
||||
self.remove_old_packages.return_value = True
|
||||
self.services.return_value = ['cinder-api']
|
||||
self.relation_ids.return_value = []
|
||||
hooks.hooks.execute(['hooks/upgrade-charm'])
|
||||
_joined.assert_not_called()
|
||||
_scrub_old_style_ceph.assert_called_once_with()
|
||||
self.service_restart.assert_called_once_with('cinder-api')
|
||||
|
||||
@patch.object(hooks, 'scrub_old_style_ceph')
|
||||
@patch.object(hooks, 'amqp_joined')
|
||||
def test_upgrade_charm_with_amqp(self, _joined, _scrub_old_style_ceph):
|
||||
|
Loading…
x
Reference in New Issue
Block a user