Add variable MTU support to the orchestrator.

This change add variable MTU support for each interface if the
underlying Neutron cloud supports it.

Change-Id: I52b2d95e892440afa7b941239abd44d37fc224a0
Depends-On: Ib4d4381f6977aabbeefd2f520bb5fc26ea54ffcd
Closes-Bug: #1539786
This commit is contained in:
Mark McClain 2016-01-29 18:43:19 -05:00
parent 154362037e
commit b236be83fc
5 changed files with 88 additions and 19 deletions

View File

@ -21,21 +21,24 @@ SERVICE_STATIC = 'static'
def network_config(client, port, ifname, network_type, network_ports=[]):
subnets = client.get_network_subnets(port.network_id)
subnets_dict = dict((s.id, s) for s in subnets)
network = client.get_network_detail(port.network_id)
subnets_dict = dict((s.id, s) for s in network.subnets)
return _make_network_config_dict(
_interface_config(ifname, port, subnets_dict),
_interface_config(ifname, port, subnets_dict, network.mtu),
network_type,
port.network_id,
mtu=network.mtu,
subnets_dict=subnets_dict,
network_ports=network_ports)
def _make_network_config_dict(interface, network_type, network_id,
def _make_network_config_dict(interface, network_type, network_id, mtu=None,
v4_conf=SERVICE_STATIC, v6_conf=SERVICE_STATIC,
subnets_dict={}, network_ports=[]):
return {'interface': interface,
'network_id': network_id,
'mtu': mtu,
'v4_conf_service': v4_conf,
'v6_conf_service': v6_conf,
'network_type': network_type,
@ -43,13 +46,17 @@ def _make_network_config_dict(interface, network_type, network_id,
'allocations': _allocation_config(network_ports, subnets_dict)}
def _interface_config(ifname, port, subnets_dict):
def _interface_config(ifname, port, subnets_dict, mtu):
def fmt(fixed):
return '%s/%s' % (fixed.ip_address,
subnets_dict[fixed.subnet_id].cidr.prefixlen)
return {'ifname': ifname,
'addresses': [fmt(fixed) for fixed in port.fixed_ips]}
retval = {'ifname': ifname,
'addresses': [fmt(fixed) for fixed in port.fixed_ips]}
if mtu:
retval['mtu'] = mtu
return retval
def _subnet_config(subnet):

View File

@ -212,6 +212,40 @@ class Router(object):
)
class Network(DictModelBase):
DICT_ATTRS = ('id', 'name', 'tenant_id', 'status', 'shared',
'admin_state_up', 'mtu', 'port_security_enabled')
def __init__(self, id_, name, tenant_id, status, shared, admin_state_up,
mtu=None, port_security_enabled=False, subnets=()):
self.id = id_
self.name = name
self.tenant_id = tenant_id
self.shared = shared
self.admin_state_up = admin_state_up
self.mtu = mtu
self.port_security_enabled = port_security_enabled
self.subnets = subnets
@classmethod
def from_dict(cls, d):
optional = {}
for opt in ['mtu', 'port_security_enabled']:
if opt in d:
optional[opt] = d[opt]
return cls(
d['id'],
d['name'],
d['tenant_id'],
d['status'],
d['shared'],
d['admin_state_up'],
**optional
)
class Subnet(DictModelBase):
DICT_ATTRS = ('id', 'name', 'tenant_id', 'network_id', 'ip_version',
'cidr', 'gateway_ip', 'enable_dhcp', 'dns_nameservers',
@ -650,6 +684,13 @@ class Neutron(object):
network_id, e)
return response
def get_network_detail(self, network_id):
network_response = self.api_client.show_network(network_id)['network']
network = Network.from_dict(network_response)
network.subnets = self.get_network_subnets(network_id)
return network
def get_ports_for_instance(self, instance_id):
ports = self.api_client.list_ports(device_id=instance_id)['ports']

View File

@ -96,6 +96,18 @@ fake_subnet_with_slaac = Subnet(
ipv6_ra_mode='slaac',
host_routes={})
fake_network = FakeModel(
'fake_network_id',
name='thenet',
tenant_id='tenant_id',
status='ACTIVE',
shared=False,
admin_statue_up=True,
mtu=1280,
port_security_enabled=False,
subnets=[fake_subnet]
)
fake_router = FakeModel(
'router_id',
tenant_id='tenant_id',

View File

@ -17,7 +17,6 @@
import mock
import netaddr
from oslo_config import cfg
import unittest2 as unittest
from astara.api.config import common
@ -26,15 +25,9 @@ from astara.test.unit.api.config import config_fakes as fakes
class TestCommonConfig(unittest.TestCase):
def setUp(self):
cfg.CONF.set_override('provider_rules_path', '/the/path')
def tearDown(self):
cfg.CONF.reset()
def test_network_config(self):
mock_client = mock.Mock()
mock_client.get_network_subnets.return_value = [fakes.fake_subnet]
mock_client.get_network_detail.return_value = fakes.fake_network
subnets_dict = {fakes.fake_subnet.id: fakes.fake_subnet}
with mock.patch.object(common, '_make_network_config_dict') as nc:
@ -50,13 +43,14 @@ class TestCommonConfig(unittest.TestCase):
[])
ic.assert_called_once_with(
'ge1', fakes.fake_int_port, subnets_dict)
'ge1', fakes.fake_int_port, subnets_dict, 1280)
nc.assert_called_once_with(
mock_interface,
'internal',
'int-net',
mtu=1280,
subnets_dict=subnets_dict,
network_ports=[])
network_ports=[]),
def test_make_network_config(self):
interface = {'ifname': 'ge2'}
@ -65,6 +59,7 @@ class TestCommonConfig(unittest.TestCase):
interface,
'internal',
fakes.fake_int_port.network_id,
1280,
'dhcp',
'ra',
subnets_dict={fakes.fake_subnet.id: fakes.fake_subnet},
@ -76,6 +71,7 @@ class TestCommonConfig(unittest.TestCase):
'v4_conf_service': 'dhcp',
'v6_conf_service': 'ra',
'network_type': 'internal',
'mtu': 1280,
'subnets': [{'cidr': '192.168.1.0/24',
'dhcp_enabled': True,
'dns_nameservers': ['8.8.8.8'],
@ -94,12 +90,22 @@ class TestCommonConfig(unittest.TestCase):
self.assertEqual(result, expected)
def test_interface_config(self):
expected = {'addresses': ['192.168.1.1/24'], 'ifname': 'ge1'}
expected = {
'addresses': ['192.168.1.1/24'],
'ifname': 'ge1',
'mtu': 1280
}
subnets_dict = {fakes.fake_subnet.id: fakes.fake_subnet}
self.assertEqual(
expected,
common._interface_config('ge1', fakes.fake_int_port, subnets_dict))
common._interface_config(
'ge1',
fakes.fake_int_port,
subnets_dict,
1280
)
)
def test_subnet_config(self):
expected = {

View File

@ -0,0 +1,3 @@
---
fixes:
- Bug `1539786 <https://bugs.launchpad.net/astara/+bug/1539786/>`_ Varible MTU support is now supported by the orchestrator and passed to appliance. This requires Neutron with MTU extension enabled to support.