py3: handle shared subordinate dependencies on upgrade

Switch to marking non-leaf python-* packages as automatically
installed so that they will be purged once the last remaining
package that depends on them that was manually installed is
removed.

Change-Id: If821cb511a2fdb65ac3e8ad8db88a00770864d42
Closes-Bug: 1802400
This commit is contained in:
Corey Bryant 2018-11-08 21:33:14 -05:00 committed by James Page
parent ff96014044
commit d9430f9bd2
2 changed files with 18 additions and 2 deletions

View File

@ -43,6 +43,7 @@ from charmhelpers.fetch import (
apt_upgrade,
apt_purge,
apt_autoremove,
apt_mark,
filter_missing_packages,
)
@ -61,6 +62,10 @@ PY3_PACKAGES = [
'python3-memcache',
]
HELD_PACKAGES = [
'python-memcache',
]
VERSION_PACKAGE = 'ceilometer-common'
NOVA_CONF = "/etc/nova/nova.conf"
@ -147,7 +152,6 @@ def determine_purge_packages():
if release >= 'rocky':
pkgs = [p for p in CEILOMETER_AGENT_PACKAGES
if p.startswith('python-')]
pkgs.append('python-memcache')
return pkgs
return []
@ -159,11 +163,23 @@ def remove_old_packages():
'''
installed_packages = filter_missing_packages(determine_purge_packages())
if installed_packages:
apt_mark(filter_missing_packages(determine_held_packages()),
'auto')
apt_purge(installed_packages, fatal=True)
apt_autoremove(purge=True, fatal=True)
return bool(installed_packages)
def determine_held_packages():
'''Return a list of packages to mark as candidates for removal
for the current OS release'''
release = CompareOpenStackReleases(get_os_codename_package(
'ceilometer-common', fatal=False) or 'icehouse')
if release >= 'rocky':
return HELD_PACKAGES
return []
def restart_map():
'''
Determine the correct resource map to be passed to

View File

@ -134,7 +134,7 @@ class CeilometerUtilsTest(CharmTestCase):
self.get_os_codename_package.return_value = 'rocky'
self.assertEqual(utils.determine_purge_packages(),
[p for p in utils.CEILOMETER_AGENT_PACKAGES
if p.startswith('python-')] + ['python-memcache'])
if p.startswith('python-')])
def test_get_packages_queens(self):
self.get_os_codename_package.return_value = 'queens'