From 1f6e29fbe2c6cabbdb082f5d8899520809f9b7ae Mon Sep 17 00:00:00 2001 From: "Erlon R. Cruz" Date: Sun, 9 May 2021 10:38:02 -0300 Subject: [PATCH] Adds Neutron OVS agent config to DHCP daemon The neutron-dhcp-agent might rely on options defined in openvswitch_agent.ini. By default this config file is not passed to neutron-dhcp-agent daemon, and therefore those options are not loaded and fall back for the default values and by that inhibits the desired behavior. Charm helpers' PR: https://github.com/juju/charm-helpers/pull/615 Depends-on: I39024855c3e42ee135b6ad5e7618a770219b6994 Closes-bug: #1832021 Change-Id: I134c8077ee52ccdb4e383109ecbea27ed1633fb8 --- hooks/charmhelpers/contrib/openstack/context.py | 6 ++++++ hooks/neutron_ovs_utils.py | 11 +++++++++-- templates/neutron-dhcp-agent | 11 +++++++++++ unit_tests/test_neutron_ovs_utils.py | 7 +++++-- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 templates/neutron-dhcp-agent diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index b67dafda..0ec935eb 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -2379,6 +2379,12 @@ class DHCPAgentContext(OSContextGenerator): ctxt['enable_metadata_network'] = True ctxt['enable_isolated_metadata'] = True + ctxt['append_ovs_config'] = False + cmp_release = CompareOpenStackReleases( + os_release('neutron-common', base='icehouse')) + if cmp_release >= 'queens' and config('enable-dpdk'): + ctxt['append_ovs_config'] = True + return ctxt @staticmethod diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index f086102f..02525c3b 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -147,6 +147,7 @@ PURGE_PACKAGES = [ PHY_NIC_MTU_CONF = '/etc/init/os-charm-phy-nic-mtu.conf' TEMPLATES = 'templates/' OVS_DEFAULT = '/etc/default/openvswitch-switch' +NEUTRON_DHCP_DEFAULT = '/etc/default/neutron-dhcp-agent' DPDK_INTERFACES = '/etc/dpdk/interfaces' NEUTRON_SRIOV_AGENT_CONF = os.path.join(NEUTRON_CONF_DIR, 'plugins/ml2/sriov_agent.ini') @@ -211,6 +212,10 @@ DHCP_RESOURCE_MAP = OrderedDict([ 'services': ['neutron-dhcp-agent'], 'contexts': [DHCPAgentContext()], }), + (NEUTRON_DHCP_DEFAULT, { + 'services': ['neutron-dhcp-agent'], + 'contexts': [DHCPAgentContext()], + }), ]) DVR_RESOURCE_MAP = OrderedDict([ (NEUTRON_L3_AGENT_CONF, { @@ -387,6 +392,8 @@ def resource_map(): """ drop_config = [] resource_map = deepcopy(BASE_RESOURCE_MAP) + # Remap any service names as required + _os_release = os_release('neutron-common', base='icehouse') if use_dvr(): resource_map.update(DVR_RESOURCE_MAP) resource_map.update(METADATA_RESOURCE_MAP) @@ -397,8 +404,8 @@ def resource_map(): resource_map.update(DHCP_RESOURCE_MAP) metadata_services = ['neutron-metadata-agent', 'neutron-dhcp-agent'] resource_map[NEUTRON_CONF]['services'] += metadata_services - # Remap any service names as required - _os_release = os_release('neutron-common', base='icehouse') + if use_dpdk() and CompareOpenStackReleases(_os_release) >= 'queens': + resource_map[OVS_CONF]['services'] += ['neutron-dhcp-agent'] if CompareOpenStackReleases(_os_release) >= 'mitaka': # ml2_conf.ini -> openvswitch_agent.ini drop_config.append(ML2_CONF) diff --git a/templates/neutron-dhcp-agent b/templates/neutron-dhcp-agent new file mode 100644 index 00000000..eaf647ce --- /dev/null +++ b/templates/neutron-dhcp-agent @@ -0,0 +1,11 @@ +# This is a POSIX shell fragment -*- sh -*- +############################################################################### +# [ WARNING ] +# Configuration file maintained by Juju. Local changes may be overwritten. +# Configuration managed by neutron-openvswitch charm +# Service restart triggered by remote application: {{ restart_trigger }} +# {{ restart_trigger_ovs }} +############################################################################### +{% if append_ovs_config -%} +DAEMON_ARGS="$DAEMON_ARGS --config-file=/etc/neutron/plugins/ml2/openvswitch_agent.ini" +{% endif -%} diff --git a/unit_tests/test_neutron_ovs_utils.py b/unit_tests/test_neutron_ovs_utils.py index a897fe53..d9f02077 100644 --- a/unit_tests/test_neutron_ovs_utils.py +++ b/unit_tests/test_neutron_ovs_utils.py @@ -569,10 +569,13 @@ class TestNeutronOVSUtils(CharmTestCase): @patch.object(nutils, 'use_l3ha') @patch.object(nutils, 'use_dpdk') @patch.object(nutils, 'use_dvr') - def test_restart_map(self, mock_use_dvr, mock_use_dpdk, mock_use_l3ha): + @patch.object(nutils, 'enable_local_dhcp') + def test_restart_map(self, mock_enable_local_dhcp, mock_use_dvr, + mock_use_dpdk, mock_use_l3ha): mock_use_dvr.return_value = False mock_use_l3ha.return_value = False mock_use_dpdk.return_value = False + mock_enable_local_dhcp.return_value = False self.os_release.return_value = "mitaka" self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} ML2CONF = "/etc/neutron/plugins/ml2/openvswitch_agent.ini" @@ -580,7 +583,7 @@ class TestNeutronOVSUtils(CharmTestCase): expect = OrderedDict([ (nutils.NEUTRON_CONF, ['neutron-openvswitch-agent']), (ML2CONF, ['neutron-openvswitch-agent']), - (nutils.OVS_DEFAULT, ['openvswitch-switch']), + (nutils.OVS_DEFAULT, ['openvswitch-switch']) ]) for item in _restart_map: self.assertTrue(item in _restart_map)