diff --git a/config.yaml b/config.yaml index 3d92376b..6bf27e47 100644 --- a/config.yaml +++ b/config.yaml @@ -173,15 +173,3 @@ options: description: | Default multicast port number that will be used to communicate between HA Cluster nodes. - phy-nics: - type: string - default: - description: | - A space-separated list of NICs that we want phy-nic-mtu applied to. - phy-nic-mtu: - type: int - default: - description: | - To improve network performance of VM, sometimes we should keep VM MTU as - 1500 and use charm to modify MTU of tunnel nic more than 1500 (e.g. 1546 - for GRE). diff --git a/hooks/quantum_contexts.py b/hooks/quantum_contexts.py index be6e7fee..03459142 100644 --- a/hooks/quantum_contexts.py +++ b/hooks/quantum_contexts.py @@ -191,27 +191,14 @@ class ExternalPortContext(NeutronPortContext): ports = self.resolve_ports(ports) if ports: ctxt = {"ext_port": ports[0]} - mtu = config('phy-nic-mtu') + neutron_api_settings = _neutron_api_settings() + mtu = neutron_api_settings.get('network_device_mtu') if mtu: ctxt['ext_port_mtu'] = mtu return ctxt -class PhyNICMTUContext(OSContextGenerator): - - def __call__(self): - ctxt = {} - port = config('phy-nics') - if port: - ctxt = {"devs": port.replace(' ', '\\n')} - mtu = config('phy-nic-mtu') - if mtu: - ctxt['mtu'] = mtu - - return ctxt - - class DataPortContext(NeutronPortContext): def __call__(self): @@ -231,6 +218,22 @@ class DataPortContext(NeutronPortContext): return None +class PhyNICMTUContext(DataPortContext): + + def __call__(self): + ctxt = {} + mappings = super(PhyNICMTUContext, self).__call__() + if mappings and mappings.values(): + ports = mappings.values() + neutron_api_settings = _neutron_api_settings() + mtu = neutron_api_settings.get('network_device_mtu') + if mtu: + ctxt["devs"] = '\\n'.join(ports) + ctxt['mtu'] = mtu + + return ctxt + + class QuantumGatewayContext(OSContextGenerator): def __call__(self): diff --git a/unit_tests/test_quantum_contexts.py b/unit_tests/test_quantum_contexts.py index 03ef3247..d983cde3 100644 --- a/unit_tests/test_quantum_contexts.py +++ b/unit_tests/test_quantum_contexts.py @@ -181,6 +181,7 @@ class TestNeutronPortContext(CharmTestCase): self.assertEquals(quantum_contexts.ExternalPortContext()(), {}) + @patch.object(quantum_contexts, '_neutron_api_settings') @patch('charmhelpers.contrib.openstack.context.get_nic_hwaddr') @patch('charmhelpers.contrib.openstack.context.list_nics') @patch('charmhelpers.contrib.openstack.context.get_ipv6_addr') @@ -189,8 +190,10 @@ class TestNeutronPortContext(CharmTestCase): def test_ext_port_mac_one_used_nic(self, mock_config, mock_get_ipv4_addr, mock_get_ipv6_addr, mock_list_nics, - mock_get_nic_hwaddr): + mock_get_nic_hwaddr, + mock_neutron_api_settings): + mock_neutron_api_settings.return_value = {'network_device_mtu': 1234} config_macs = "%s %s" % (self.machine_macs['eth1'], self.machine_macs['eth2']) @@ -199,8 +202,7 @@ class TestNeutronPortContext(CharmTestCase): mock_list_nics.return_value = self.machine_macs.keys() mock_get_nic_hwaddr.side_effect = self._fake_get_hwaddr - config = self.fake_config({'ext-port': config_macs, - 'phy-nic-mtu': 1234}) + config = self.fake_config({'ext-port': config_macs}) self.config.side_effect = config mock_config.side_effect = config self.assertEquals(quantum_contexts.ExternalPortContext()(),