From: Dave Cahill Date: Tue, 17 Dec 2013 05:52:48 +0000 (+0000) Subject: Midonet plugin: Fix source NAT X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7dc3c671656974596b9a373c911e5b786d57be35;p=openstack-build%2Fneutron-build.git Midonet plugin: Fix source NAT Source NAT rule was being applied on the incorrect port. It was being applied to the Neutron gateway port, not to the MidoNet tenant / provider router link port. Change-Id: Ib818c09adfb6957b7cad4523e5ce1fdffde9590b Closes-Bug: #1261665 --- diff --git a/neutron/plugins/midonet/plugin.py b/neutron/plugins/midonet/plugin.py index e4bdb9955..a10b689c1 100644 --- a/neutron/plugins/midonet/plugin.py +++ b/neutron/plugins/midonet/plugin.py @@ -870,14 +870,16 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2, if (l3_db.EXTERNAL_GW_INFO in r and r[l3_db.EXTERNAL_GW_INFO] is not None): # Gateway created - gw_port = self._get_port(context.elevated(), - r["gw_port_id"]) - gw_ip = gw_port['fixed_ips'][0]['ip_address'] + gw_port_neutron = self._get_port( + context.elevated(), r["gw_port_id"]) + gw_ip = gw_port_neutron['fixed_ips'][0]['ip_address'] # First link routers and set up the routes self._set_router_gateway(r["id"], self._get_provider_router(), gw_ip) + gw_port_midonet = self.client.get_link_port( + self._get_provider_router(), r["id"]) # Get the NAT chains and add dynamic SNAT rules. chain_names = _nat_chain_names(r["id"]) @@ -885,7 +887,9 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2, self.client.add_dynamic_snat(tenant_id, chain_names['pre-routing'], chain_names['post-routing'], - gw_ip, gw_port["id"], **props) + gw_ip, + gw_port_midonet.get_id(), + **props) self.client.update_router(id, **router_data) diff --git a/neutron/tests/unit/midonet/test_midonet_plugin.py b/neutron/tests/unit/midonet/test_midonet_plugin.py index 1822f9364..3dcda484d 100644 --- a/neutron/tests/unit/midonet/test_midonet_plugin.py +++ b/neutron/tests/unit/midonet/test_midonet_plugin.py @@ -103,6 +103,12 @@ class TestMidonetL3NatTestCase(test_l3_plugin.L3NatDBIntTestCase, self._add_external_gateway_to_router( r['router']['id'], public_sub['subnet']['network_id']) + + # Check that get_link_port was called - if not, Source NAT + # will not be set up correctly on the MidoNet side + self.assertTrue( + self.instance.return_value.get_link_port.called) + self._router_interface_action('add', r['router']['id'], private_sub['subnet']['id'], None)