Adds l3_extension_plugins to L3AgentContext ctx

* get a list of l3 plugins to enable based on relation data coming from
  neutron-api;
* refactor adding fwaasv2 service plugins to the l3 agent to accommodate
  the l3_extension_plugins change.

See https://github.com/juju/charm-helpers/pull/370
See LP: #1842353

Change-Id: Ic3a8e302942ed331bc3d80223e123c13d61db3b2
Closes-Bug: #1842353
This commit is contained in:
Dmitrii Shcherbakov 2019-10-06 20:24:52 +03:00
parent b44bf586b8
commit 51c264c43f
4 changed files with 89 additions and 10 deletions

View File

@ -45,6 +45,10 @@ from charmhelpers.contrib.openstack.context import (
NeutronAPIContext,
parse_data_port_mappings
)
from charmhelpers.contrib.openstack.utils import (
os_release,
CompareOpenStackReleases,
)
import charmhelpers.contrib.openstack.utils as os_utils
from charmhelpers.core.unitdata import kv
@ -351,6 +355,22 @@ class L3AgentContext(OSContextGenerator):
NFG_LOG_BURST_LIMIT_MIN
)
cmp_os_release = CompareOpenStackReleases(os_release('neutron-common'))
l3_extension_plugins = neutron_api_settings.get(
'l3_extension_plugins', [])
# per Change-Id If1b332eb0f581e9acba111f79ba578a0b7081dd2
# only enable it for stein although fwaasv2 was added in Queens
is_stein = cmp_os_release >= 'stein'
if is_stein:
l3_extension_plugins.append('fwaas_v2')
if (is_stein and neutron_api_settings.get('enable_nfg_logging')):
l3_extension_plugins.append('fwaas_v2_log')
ctxt['l3_extension_plugins'] = ','.join(l3_extension_plugins)
return ctxt

View File

@ -0,0 +1,20 @@
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
# {{ restart_trigger_l3agent }}
###############################################################################
[DEFAULT]
interface_driver = openvswitch
agent_mode = {{ agent_mode }}
{% if external_configuration_new -%}
gateway_external_network_id =
external_network_bridge =
{% endif %}
{% if use_l3ha and agent_mode == 'dvr_snat' -%}
ha_vrrp_health_check_interval = 30
{% endif %}
[AGENT]
extensions = {{ l3_extension_plugins }}

View File

@ -14,8 +14,8 @@ external_network_bridge =
{% endif %}
[AGENT]
extensions = {{ l3_extension_plugins }}
{% if enable_nfg_logging -%}
extensions = fwaas_v2,fwaas_v2_log
[network_log]
{% if nfg_log_rate_limit -%}
rate_limit = {{ nfg_log_rate_limit }}
@ -24,6 +24,4 @@ burst_limit = {{ nfg_log_burst_limit }}
{% if nfg_log_output_base -%}
local_output_log_base = {{ nfg_log_output_base }}
{% endif -%}
{% else %}
extensions = fwaas_v2
{% endif -%}
{% endif -%}

View File

@ -458,18 +458,24 @@ class L3AgentContextTest(CharmTestCase):
def tearDown(self):
super(L3AgentContextTest, self).tearDown()
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_enabled(self, _runits, _rids, _rget):
def test_dvr_enabled(self, _runits, _rids, _rget,
_get_os_cdnm_pkg, _os_release):
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'stein'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'True',
'l2-population': 'True',
'overlay-network-type': 'vxlan',
'network-device-mtu': 1500,
'l3_extension_plugins': 'fwaas_v2',
}
_rget.side_effect = lambda *args, **kwargs: rdata
self.assertEqual(
@ -481,15 +487,21 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_burst_limit': 25,
'nfg_log_output_base': None,
'nfg_log_rate_limit': None,
'l3_extension_plugins': 'fwaas_v2',
}
)
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_enabled_l3ha_enabled(self, _runits, _rids, _rget):
def test_dvr_enabled_l3ha_enabled(self, _runits, _rids, _rget,
_get_os_cdnm_pkg, _os_release):
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'rocky'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'True',
@ -508,17 +520,23 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_burst_limit': 25,
'nfg_log_output_base': None,
'nfg_log_rate_limit': None,
'l3_extension_plugins': '',
}
)
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(context, 'validate_nfg_log_path')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_nfg_enabled(self, _runits, _rids, _rget,
_validate_nfg_log_path):
_validate_nfg_log_path,
_get_os_cdnm_pkg, _os_release):
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'stein'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'True',
@ -527,6 +545,7 @@ class L3AgentContextTest(CharmTestCase):
'network-device-mtu': 1500,
'enable-nfg-logging': 'True',
'use_l3ha': False,
'l3_extension_plugins': 'fwaas_v2,fwaas_v2_log',
}
_rget.side_effect = lambda *args, **kwargs: rdata
_validate_nfg_log_path.side_effect = lambda x: x
@ -543,17 +562,23 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_output_base': '/var/log/neutron/firewall.log',
'nfg_log_rate_limit': 200,
'use_l3ha': False,
'l3_extension_plugins': 'fwaas_v2,fwaas_v2_log',
}
)
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(context, 'validate_nfg_log_path')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_nfg_enabled_mins(self, _runits, _rids, _rget,
_validate_nfg_log_path):
_validate_nfg_log_path,
_get_os_cdnm_pkg, _os_release):
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'stein'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'True',
@ -561,6 +586,7 @@ class L3AgentContextTest(CharmTestCase):
'overlay-network-type': 'vxlan',
'network-device-mtu': 1500,
'enable-nfg-logging': 'True',
'l3_extension_plugins': 'fwaas_v2,fwaas_v2_log',
}
_rget.side_effect = lambda *args, **kwargs: rdata
_validate_nfg_log_path.side_effect = lambda x: x
@ -577,22 +603,29 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_output_base': '/var/log/neutron/firewall.log',
'nfg_log_rate_limit': 100,
'use_l3ha': False,
'l3_extension_plugins': 'fwaas_v2,fwaas_v2_log',
}
)
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_enabled_dvr_snat_enabled(self, _runits, _rids, _rget):
def test_dvr_enabled_dvr_snat_enabled(self, _runits, _rids, _rget,
_get_os_cdnm_pkg, _os_release):
self.test_config.set('use-dvr-snat', True)
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'stein'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'True',
'l2-population': 'True',
'overlay-network-type': 'vxlan',
'network-device-mtu': 1500,
'l3_extension_plugins': 'fwaas_v2,fwaas_v2_log',
}
_rget.side_effect = lambda *args, **kwargs: rdata
self.assertEqual(
@ -604,21 +637,28 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_burst_limit': 25,
'nfg_log_output_base': None,
'nfg_log_rate_limit': None,
'l3_extension_plugins': 'fwaas_v2',
}
)
@patch.object(context, 'os_release')
@patch.object(charmhelpers.contrib.openstack.utils,
'get_os_codename_package')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
def test_dvr_disabled(self, _runits, _rids, _rget):
def test_dvr_disabled(self, _runits, _rids, _rget,
_get_os_cdnm_pkg, _os_release):
_runits.return_value = ['unit1']
_rids.return_value = ['rid2']
_os_release.return_value = 'stein'
rdata = {
'neutron-security-groups': 'True',
'enable-dvr': 'False',
'l2-population': 'True',
'overlay-network-type': 'vxlan',
'network-device-mtu': 1500,
'l3_extension_plugins': 'fwaas_v2',
}
_rget.side_effect = lambda *args, **kwargs: rdata
self.assertEqual(context.L3AgentContext()(), {
@ -627,6 +667,7 @@ class L3AgentContextTest(CharmTestCase):
'nfg_log_burst_limit': 25,
'nfg_log_output_base': None,
'nfg_log_rate_limit': None,
'l3_extension_plugins': 'fwaas_v2',
})