From 42270d52ee4b44e57d9f5a54e43bd1047994907a Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 16 Mar 2015 18:44:02 +0000 Subject: [PATCH] added vlan-ranges config --- hooks/quantum_contexts.py | 20 ++++++++--------- hooks/quantum_utils.py | 3 ++- unit_tests/test_quantum_contexts.py | 17 ++++++++++++--- unit_tests/test_quantum_utils.py | 34 +++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/hooks/quantum_contexts.py b/hooks/quantum_contexts.py index 03459142..7856bf06 100644 --- a/hooks/quantum_contexts.py +++ b/hooks/quantum_contexts.py @@ -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') diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index b23d951d..e7a0f6c6 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -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') diff --git a/unit_tests/test_quantum_contexts.py b/unit_tests/test_quantum_contexts.py index d983cde3..5244ec89 100644 --- a/unit_tests/test_quantum_contexts.py +++ b/unit_tests/test_quantum_contexts.py @@ -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, }) diff --git a/unit_tests/test_quantum_utils.py b/unit_tests/test_quantum_utils.py index ecd25240..60a87d03 100644 --- a/unit_tests/test_quantum_utils.py +++ b/unit_tests/test_quantum_utils.py @@ -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):