Add a route to reach the MD server when a subnet is created
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
This commit is contained in:
parent
61dce1a606
commit
cf7aca87e1
@ -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)):
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user