]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add a route to reach the MD server when a subnet is created
authorRossella Sblendido <rossella@midokura.com>
Wed, 25 Sep 2013 14:55:04 +0000 (14:55 +0000)
committerMark McClain <mark.mcclain@dreamhost.com>
Wed, 9 Oct 2013 14:36:02 +0000 (10:36 -0400)
When the first subnet is created, the dhcp port is created and
midonet plugin correctly adds the static route to reach the MD
server in create_port. When a second or following subnets are
created, a new ip is added to the dhcp port. This patch takes
care of adding the static route to correcly reach the MD server
in update_port. This fixes the problem of VMs not being able to
reach the MD if assigned to the second subnet

Closes-bug: #1231914
Change-Id: Ifc95f901d4222b76a4254e21295829ac8d82493b
(cherry picked from commit 3568a9cac73a2da19e86d82f561be10ae9dbe9a0)

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

index cd12ec5ce7faf9c601b25f5a7542dcc8892c77d9..196fa3936f7862b7521a5fc4a789fe19f17f81fa 100644 (file)
@@ -625,20 +625,30 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
             old_port = self._get_port(context, id)
             net_id = old_port["network_id"]
             mac = old_port["mac_address"]
-            old_fixed_ips = old_port.get('fixed_ips')
-
+            old_ips = old_port["fixed_ips"]
             # update the port DB
             p = super(MidonetPluginV2, self).update_port(context, id, port)
 
-            if "fixed_ips" in p:
-                # IPs have changed.  Re-map the DHCP entries
+            new_ips = p["fixed_ips"]
+            if new_ips:
                 bridge = self.client.get_bridge(net_id)
-                for cidr, ip, mac in self._dhcp_mappings(
-                        context, old_fixed_ips, mac):
-                    self.client.remove_dhcp_host(bridge, cidr, ip, mac)
-                for cidr, ip, mac in self._dhcp_mappings(context,
-                                                         p["fixed_ips"], mac):
-                    self.client.add_dhcp_host(bridge, cidr, ip, mac)
+                # If it's a DHCP port, add a route to reach the MD server
+                if _is_dhcp_port(p):
+                    for cidr, ip in self._metadata_subnets(
+                        context, new_ips):
+                        self.client.add_dhcp_route_option(
+                            bridge, cidr, ip, METADATA_DEFAULT_IP)
+                else:
+                # IPs have changed.  Re-map the DHCP entries
+                    for cidr, ip, mac in self._dhcp_mappings(
+                            context, old_ips, mac):
+                        self.client.remove_dhcp_host(
+                            bridge, cidr, ip, mac)
+
+                    for cidr, ip, mac in self._dhcp_mappings(
+                        context, new_ips, mac):
+                        self.client.add_dhcp_host(
+                            bridge, cidr, ip, mac)
 
             if (self._check_update_deletes_security_groups(port) or
                     self._check_update_has_security_groups(port)):
index 0fe95f99f185641a9bfa691c1239559964fcd767..2b6889a1fdeb31664ffa1786276053a3b970d267 100644 (file)
@@ -108,6 +108,25 @@ class MidoClientTestCase(testtools.TestCase):
                                   "2A:DB:6B:8C:19:99")
         bridge.assert_has_calls(calls, any_order=True)
 
+    def test_add_dhcp_route_option(self):
+
+        bridge = mock.Mock()
+        subnet = bridge.get_dhcp_subnet.return_value
+        subnet.get_opt121_routes.return_value = None
+        dhcp_subnet_call = mock.call.get_dhcp_subnet("10.0.0.0_24")
+        dst_ip = "10.0.0.3/24"
+        gw_ip = "10.0.0.1"
+        prefix, length = dst_ip.split("/")
+        routes = [{'destinationPrefix': prefix, 'destinationLength': length,
+                   'gatewayAddr': gw_ip}]
+        opt121_routes_call = dhcp_subnet_call.opt121_routes(routes)
+        calls = [dhcp_subnet_call, opt121_routes_call,
+                 opt121_routes_call.update()]
+
+        self.client.add_dhcp_route_option(bridge, "10.0.0.0/24",
+                                          gw_ip, dst_ip)
+        bridge.assert_has_calls(calls, any_order=True)
+
     def test_get_router_error(self):
         self.mock_api.get_router.side_effect = w_exc.HTTPInternalServerError()
         self.assertRaises(midonet_lib.MidonetApiException,