Purge dhcp packages when no longer required

This commit is contained in:
Liam Young 2015-09-12 09:58:58 +01:00
parent 8a01f1ee27
commit d87daa8805
3 changed files with 20 additions and 8 deletions

View File

@ -20,15 +20,12 @@ from charmhelpers.core.host import (
restart_on_change
)
from charmhelpers.fetch import (
apt_purge,
)
from charmhelpers.contrib.openstack.utils import (
os_requires_version,
)
from neutron_ovs_utils import (
DHCP_PACKAGES,
DVR_PACKAGES,
configure_ovs,
git_install,
@ -40,6 +37,7 @@ from neutron_ovs_utils import (
enable_nova_metadata,
enable_local_dhcp,
install_packages,
purge_packages,
)
hooks = Hooks()
@ -75,7 +73,7 @@ def neutron_plugin_api_changed():
if use_dvr():
install_packages()
else:
apt_purge(DVR_PACKAGES, fatal=True)
purge_packages(DVR_PACKAGES)
configure_ovs()
CONFIGS.write_all()
# If dvr setting has changed, need to pass that on
@ -87,6 +85,8 @@ def neutron_plugin_api_changed():
def neutron_plugin_joined(relation_id=None):
if enable_local_dhcp():
install_packages()
else:
purge_packages(DHCP_PACKAGES)
secret = get_shared_secret() if enable_nova_metadata() else None
rel_data = {
'metadata-shared-secret': secret,

View File

@ -45,6 +45,7 @@ from charmhelpers.core.templating import render
from charmhelpers.fetch import (
apt_install,
apt_purge,
apt_update,
filter_installed_packages,
)
@ -82,6 +83,7 @@ ML2_CONF = '%s/plugins/ml2/ml2_conf.ini' % NEUTRON_CONF_DIR
EXT_PORT_CONF = '/etc/init/ext-port.conf'
NEUTRON_METADATA_AGENT_CONF = "/etc/neutron/metadata_agent.ini"
DVR_PACKAGES = ['neutron-l3-agent']
DHCP_PACKAGES = ['neutron-metadata-agent', 'neutron-dhcp-agent']
PHY_NIC_MTU_CONF = '/etc/init/os-charm-phy-nic-mtu.conf'
TEMPLATES = 'templates/'
@ -140,6 +142,16 @@ def install_packages():
apt_install(filter_installed_packages(determine_packages()))
def purge_packages(pkg_list):
purge_pkgs = []
required_packages = determine_packages()
for pkg in pkg_list:
if pkg not in required_packages:
purge_pkgs.append(pkg)
if purge_pkgs:
apt_purge(purge_pkgs, fatal=True)
def determine_packages():
pkgs = []
plugin_pkgs = neutron_plugin_attribute('ovs', 'packages', 'neutron')
@ -148,7 +160,7 @@ def determine_packages():
if use_dvr():
pkgs.extend(DVR_PACKAGES)
if enable_local_dhcp():
pkgs.extend(['neutron-metadata-agent', 'neutron-dhcp-agent'])
pkgs.extend(DHCP_PACKAGES)
if git_install_requested():
pkgs.extend(BASE_GIT_PACKAGES)

View File

@ -19,7 +19,6 @@ utils.register_configs = _reg
utils.restart_map = _map
TO_PATCH = [
'apt_purge',
'config',
'CONFIGS',
'get_shared_secret',
@ -30,6 +29,7 @@ TO_PATCH = [
'configure_ovs',
'use_dvr',
'install_packages',
'purge_packages',
'enable_nova_metadata',
'enable_local_dhcp',
]
@ -137,7 +137,7 @@ class NeutronOVSHooksTests(CharmTestCase):
self.configure_ovs.assert_called_with()
self.assertTrue(self.CONFIGS.write_all.called)
_plugin_joined.assert_called_with(relation_id='rid')
self.apt_purge.assert_called_with(['neutron-l3-agent'], fatal=True)
self.purge_packages.assert_called_with(['neutron-l3-agent'])
@patch.object(hooks, 'git_install_requested')
def test_neutron_plugin_joined(self, git_requested):