added vlan-ranges config

This commit is contained in:
Edward Hope-Morley 2015-03-16 18:44:02 +00:00
parent d049c7e5e1
commit 42270d52ee
4 changed files with 51 additions and 23 deletions

View File

@ -118,17 +118,16 @@ def _neutron_api_settings():
for rid in relation_ids('neutron-plugin-api'):
for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit)
if 'l2-population' not in rdata:
continue
neutron_settings = {
'l2_population': rdata['l2-population'],
'overlay_network_type': rdata['overlay-network-type'],
}
if 'l2-population' in rdata:
neutron_settings.update({
'l2_population': rdata['l2-population'],
'overlay_network_type': rdata['overlay-network-type'],
})
net_dev_mtu = rdata.get('network-device-mtu')
if net_dev_mtu:
neutron_settings['network_device_mtu'] = net_dev_mtu
return neutron_settings
return neutron_settings
@ -258,9 +257,10 @@ class QuantumGatewayContext(OSContextGenerator):
ctxt['bridge_mappings'] = mappings
vlan_ranges = config('vlan-ranges')
vlan_range_mappings = parse_vlan_range_mappings(config('vlan-ranges'))
if vlan_ranges:
ctxt['network_providers'] = ' '.join(vlan_range_mappings.keys())
vlan_range_mappings = parse_vlan_range_mappings(vlan_ranges)
if vlan_range_mappings:
providers = sorted(vlan_range_mappings.keys())
ctxt['network_providers'] = ' '.join(providers)
ctxt['vlan_ranges'] = vlan_ranges
net_dev_mtu = neutron_api_settings.get('network_device_mtu')

View File

@ -620,7 +620,8 @@ def configure_ovs():
add_bridge_port(br, portmaps[br], promisc=True)
# Ensure this runs so that any new bridges have correct mtu
# Ensure this runs so that mtu is applied to data-port interfaces if
# provided.
service_restart('os-charm-phy-nic-mtu')

View File

@ -266,10 +266,19 @@ class TestQuantumGatewayContext(CharmTestCase):
self.test_config.set('debug', False)
self.test_config.set('verbose', True)
self.test_config.set('instance-mtu', 1420)
self.test_config.set('vlan-ranges',
'physnet1:1000:2000 physnet2:2001:3000')
# Provided by neutron-api relation
self.relation_ids.return_value = ['neutron-plugin-api:0']
self.related_units.return_value = ['neutron-api/0']
rdata = {'network-device-mtu': 9000}
self.relation_get.side_effect = lambda *args, **kwargs: rdata
self.get_os_codename_install_source.return_value = 'folsom'
_host_ip.return_value = '10.5.0.1'
_secret.return_value = 'testsecret'
self.assertEquals(quantum_contexts.QuantumGatewayContext()(), {
ctxt = quantum_contexts.QuantumGatewayContext()()
self.relation_ids.assert_called_with('neutron-plugin-api')
self.assertEquals(ctxt, {
'shared_secret': 'testsecret',
'local_ip': '10.5.0.1',
'instance_mtu': 1420,
@ -281,8 +290,10 @@ class TestQuantumGatewayContext(CharmTestCase):
'l2_population': False,
'overlay_network_type': 'gre',
'bridge_mappings': 'physnet1:br-data',
'network_providers': 'physnet1',
'vlan_ranges': 'physnet1:1000:2000'
'network_providers': 'physnet1 physnet2',
'vlan_ranges': 'physnet1:1000:2000 physnet2:2001:3000',
'network_device_mtu': 9000,
'veth_mtu': 9000,
})

View File

@ -36,7 +36,6 @@ TO_PATCH = [
'service_running',
'NetworkServiceContext',
'ExternalPortContext',
'DataPortContext',
'unit_private_ip',
'relations_of_type',
'service_stop',
@ -139,7 +138,9 @@ class TestQuantumUtils(CharmTestCase):
self.get_os_codename_install_source.return_value = 'kilo'
self.assertTrue('python-neutron-fwaas' in quantum_utils.get_packages())
def test_configure_ovs_starts_service_if_required(self):
@patch('quantum_contexts.config')
def test_configure_ovs_starts_service_if_required(self, mock_config):
mock_config.side_effect = self.test_config.get
self.config.return_value = 'ovs'
self.service_running.return_value = False
quantum_utils.configure_ovs()
@ -150,14 +151,14 @@ class TestQuantumUtils(CharmTestCase):
quantum_utils.configure_ovs()
self.assertFalse(self.full_restart.called)
def test_configure_ovs_ovs_ext_port(self):
@patch('quantum_contexts.config')
def test_configure_ovs_ovs_ext_port(self, mock_config):
mock_config.side_effect = self.test_config.get
self.config.side_effect = self.test_config.get
self.test_config.set('plugin', 'ovs')
self.test_config.set('ext-port', 'eth0')
self.ExternalPortContext.return_value = \
DummyExternalPortContext(return_value={'ext_port': 'eth0'})
self.DataPortContext.return_value = \
DummyExternalPortContext(return_value=None)
quantum_utils.configure_ovs()
self.add_bridge.assert_has_calls([
call('br-int'),
@ -166,20 +167,35 @@ class TestQuantumUtils(CharmTestCase):
])
self.add_bridge_port.assert_called_with('br-ex', 'eth0')
def test_configure_ovs_ovs_data_port(self):
@patch('quantum_contexts.config')
def test_configure_ovs_ovs_data_port(self, mock_config):
mock_config.side_effect = self.test_config.get
self.config.side_effect = self.test_config.get
self.test_config.set('plugin', 'ovs')
self.test_config.set('data-port', 'eth0')
self.ExternalPortContext.return_value = \
DummyExternalPortContext(return_value=None)
self.DataPortContext.return_value = \
DummyExternalPortContext(return_value={'data_port': 'eth0'})
# Test back-compatibility i.e. port but no bridge (so br-data is
# assumed)
self.test_config.set('data-port', 'eth0')
quantum_utils.configure_ovs()
self.add_bridge.assert_has_calls([
call('br-int'),
call('br-ex'),
call('br-data')
])
self.assertTrue(self.add_bridge_port.called)
# Now test with bridge:port format
self.test_config.set('data-port', 'br-foo:eth0')
self.add_bridge.reset_mock()
self.add_bridge_port.reset_mock()
quantum_utils.configure_ovs()
self.add_bridge.assert_has_calls([
call('br-int'),
call('br-ex'),
call('br-data')
])
# Not called since we have a bogus bridge in data-ports
self.assertFalse(self.add_bridge_port.called)
def test_do_openstack_upgrade(self):