Add default-tenant-network-type config option

- Add default-tenant-network-type config option to allow the default
  network type for a tenant network to be set

- Fix rendering of overlay-network-type so that an empty string is
  valid

Change-Id: Ib2325d273a0dd5e637f36113b951130387902777
Closes-Bug: 1533651
This commit is contained in:
Liam Young 2016-12-05 15:08:35 +00:00 committed by James Page
parent a50bc93a9b
commit 446de085a0
5 changed files with 106 additions and 14 deletions

View File

@ -140,7 +140,8 @@ options:
gre
vxlan
.
Multiple types can be provided - field is space delimited.
Multiple types can be provided - field is space delimited. To disable
overlay networks set to the empty string ''
flat-network-providers:
type: string
default:
@ -617,3 +618,8 @@ options:
http://bugs.launchpad.net/charms providing an explanation of why the
config was needed so that we may consider it for inclusion as a
natively supported config in the the charm.
default-tenant-network-type:
type: string
default:
description: |
The default type for a tenant network e.g. vxlan, vlan, gre etc

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import OrderedDict
from charmhelpers.core.hookenv import (
config,
relation_ids,
@ -31,7 +33,11 @@ from charmhelpers.contrib.openstack.utils import (
VLAN = 'vlan'
VXLAN = 'vxlan'
GRE = 'gre'
FLAT = 'flat'
LOCAL = 'local'
OVERLAY_NET_TYPES = [VXLAN, GRE]
NON_OVERLAY_NET_TYPES = [VLAN, FLAT, LOCAL]
TENANT_NET_TYPES = [VXLAN, GRE, VLAN, FLAT, LOCAL]
def get_l2population():
@ -39,13 +45,42 @@ def get_l2population():
return config('l2-population') if plugin == "ovs" else False
def get_overlay_network_type():
def _get_overlay_network_type():
overlay_networks = config('overlay-network-type').split()
for overlay_net in overlay_networks:
if overlay_net not in OVERLAY_NET_TYPES:
raise ValueError('Unsupported overlay-network-type %s'
% overlay_net)
return ','.join(overlay_networks)
return overlay_networks
def get_overlay_network_type():
return ','.join(_get_overlay_network_type())
def _get_tenant_network_types():
default_tenant_network_type = config('default-tenant-network-type')
tenant_network_types = _get_overlay_network_type()
tenant_network_types.extend(NON_OVERLAY_NET_TYPES)
if default_tenant_network_type:
if (default_tenant_network_type in TENANT_NET_TYPES and
default_tenant_network_type in tenant_network_types):
tenant_network_types[:0] = [default_tenant_network_type]
else:
raise ValueError('Unsupported or unconfigured '
'default-tenant-network-type'
' {}'.format(default_tenant_network_type))
# Dedupe list but preserve order
return list(OrderedDict.fromkeys(tenant_network_types))
def get_tenant_network_types():
'''Get the configured tenant network types
@return: comma delimited string of configured tenant
network types.
'''
return ','.join(_get_tenant_network_types())
def get_l3ha():
@ -124,6 +159,10 @@ class NeutronCCContext(context.NeutronContext):
def neutron_l2_population(self):
return get_l2population()
@property
def neutron_tenant_network_types(self):
return get_tenant_network_types()
@property
def neutron_overlay_network_type(self):
return get_overlay_network_type()
@ -195,6 +234,7 @@ class NeutronCCContext(context.NeutronContext):
ctxt['min_l3_agents_per_router'] = \
config('min-l3-agents-per-router')
ctxt['dhcp_agents_per_network'] = config('dhcp-agents-per-network')
ctxt['tenant_network_types'] = self.neutron_tenant_network_types
ctxt['overlay_network_type'] = self.neutron_overlay_network_type
ctxt['external_network'] = config('neutron-external-network')
release = os_release('neutron-server')

View File

@ -8,8 +8,8 @@
type_drivers = local,flat
mechanism_drivers = calico
{% else -%}
type_drivers = {{ overlay_network_type }},vlan,flat,local
tenant_network_types = {{ overlay_network_type }},vlan,flat,local
type_drivers = {{ tenant_network_types }}
tenant_network_types = {{ tenant_network_types }}
mechanism_drivers = openvswitch,hyperv,l2population
[ml2_type_gre]

View File

@ -12,8 +12,8 @@ extension_drivers=port_security
type_drivers = local,flat
mechanism_drivers = calico
{% else -%}
type_drivers = {{ overlay_network_type }},vlan,flat,local
tenant_network_types = {{ overlay_network_type }},vlan,flat,local
type_drivers = {{ tenant_network_types }}
tenant_network_types = {{ tenant_network_types }}
{% if enable_sriov %}
mechanism_drivers = openvswitch,l2population,sriovnicswitch
{% elif enable_hyperv %}

View File

@ -49,21 +49,64 @@ class GeneralTests(CharmTestCase):
self.test_config.set('neutron-plugin', 'nsx')
self.assertEquals(context.get_l2population(), False)
def test_get_overlay_network_type(self):
def test_get_tenant_network_types(self):
self.test_config.set('overlay-network-type', 'gre')
self.assertEquals(context.get_overlay_network_type(), 'gre')
self.assertEquals(
context._get_tenant_network_types(),
['gre', 'vlan', 'flat', 'local'])
def test_get_overlay_network_type_multi(self):
def test_get_tenant_network_types_multi(self):
self.test_config.set('overlay-network-type', 'gre vxlan')
self.assertEquals(context.get_overlay_network_type(), 'gre,vxlan')
self.assertEquals(
context._get_tenant_network_types(),
['gre', 'vxlan', 'vlan', 'flat', 'local'])
def test_get_overlay_network_type_unsupported(self):
def test_get_tenant_network_types_unsupported(self):
self.test_config.set('overlay-network-type', 'tokenring')
with self.assertRaises(ValueError) as _exceptctxt:
context.get_overlay_network_type()
context._get_tenant_network_types()
self.assertEqual(_exceptctxt.exception.message,
'Unsupported overlay-network-type tokenring')
def test_get_tenant_network_types_default(self):
self.test_config.set('overlay-network-type', 'gre vxlan')
self.test_config.set('default-tenant-network-type', 'vxlan')
self.assertEquals(
context._get_tenant_network_types(),
['vxlan', 'gre', 'vlan', 'flat', 'local'])
def test_get_tenant_network_types_default_dup(self):
self.test_config.set('overlay-network-type', 'gre')
self.test_config.set('default-tenant-network-type', 'vlan')
self.assertEquals(
context._get_tenant_network_types(),
['vlan', 'gre', 'flat', 'local'])
def test_get_tenant_network_types_empty(self):
self.test_config.set('overlay-network-type', '')
self.test_config.set('default-tenant-network-type', 'vlan')
self.assertEquals(
context._get_tenant_network_types(),
['vlan', 'flat', 'local'])
def test_get_tenant_network_types_unsupported_default(self):
self.test_config.set('overlay-network-type', '')
self.test_config.set('default-tenant-network-type', 'whizzy')
with self.assertRaises(ValueError) as _exceptctxt:
context._get_tenant_network_types()
self.assertEqual(_exceptctxt.exception.message,
'Unsupported or unconfigured '
'default-tenant-network-type whizzy')
def test_get_tenant_network_types_unconfigured_default(self):
self.test_config.set('overlay-network-type', 'gre')
self.test_config.set('default-tenant-network-type', 'vxlan')
with self.assertRaises(ValueError) as _exceptctxt:
context._get_tenant_network_types()
self.assertEqual(_exceptctxt.exception.message,
'Unsupported or unconfigured '
'default-tenant-network-type vxlan')
def test_get_l3ha(self):
self.test_config.set('enable-l3ha', True)
self.test_config.set('overlay-network-type', 'gre')
@ -252,7 +295,6 @@ class HAProxyContextTest(CharmTestCase):
_get_netmask_for_address.return_value = '255.255.255.0'
_kv().get.return_value = 'abcdefghijklmnopqrstuvwxyz123456'
service_ports = {'neutron-server': [9696, 9686]}
self.maxDiff = None
ctxt_data = {
'local_host': '127.0.0.1',
'haproxy_host': '0.0.0.0',
@ -326,6 +368,7 @@ class NeutronCCContextTest(CharmTestCase):
'verbose': True,
'l2_population': True,
'overlay_network_type': 'gre',
'tenant_network_types': 'gre,vlan,flat,local',
'quota_floatingip': 50,
'quota_health_monitors': -1,
'quota_member': -1,
@ -365,6 +408,7 @@ class NeutronCCContextTest(CharmTestCase):
'verbose': True,
'l2_population': True,
'overlay_network_type': 'vxlan',
'tenant_network_types': 'vxlan,vlan,flat,local',
'quota_floatingip': 50,
'quota_health_monitors': -1,
'quota_member': -1,
@ -406,6 +450,7 @@ class NeutronCCContextTest(CharmTestCase):
'verbose': True,
'l2_population': False,
'overlay_network_type': 'gre',
'tenant_network_types': 'gre,vlan,flat,local',
'max_l3_agents_per_router': 2,
'min_l3_agents_per_router': 2,
'dhcp_agents_per_network': 3,
@ -446,6 +491,7 @@ class NeutronCCContextTest(CharmTestCase):
'verbose': True,
'l2_population': True,
'overlay_network_type': 'gre',
'tenant_network_types': 'gre,vlan,flat,local',
'quota_floatingip': 50,
'quota_health_monitors': -1,
'quota_member': -1,