]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Midonet plugin: Fix source NAT
authorDave Cahill <dcahill@midokura.com>
Tue, 17 Dec 2013 05:52:48 +0000 (05:52 +0000)
committerDave Cahill <dcahill@midokura.com>
Wed, 18 Dec 2013 04:04:14 +0000 (04:04 +0000)
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

neutron/plugins/midonet/plugin.py
neutron/tests/unit/midonet/test_midonet_plugin.py

index e4bdb995595ebe1f63cf17023416f31fac0a4738..a10b689c1419668ea57e0d31f689aa35da76a8bd 100644 (file)
@@ -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)
 
index 1822f9364abfeea03da71b61da8387dad95dfd04..3dcda484dda049b70737eab78bc4e0a8a5ef424f 100644 (file)
@@ -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)