From 960993652e1ab526c1ce8cd3cd04d28f13facc86 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 7 Jun 2020 20:43:22 +0000 Subject: [PATCH] Handle subnet without gateway * When libnetwork requests the IP address of the gateway (via /IpamDriver.RequestAddress) and the neutron subnet has gateway as None, return '0.0.0.0/0' as a placeholder. * Disable default docker gateway via the 'DisableGatewayService' flag (see https://github.com/moby/libnetwork/pull/778). Change-Id: I3033d28eb268a01de8cf038b1ed20110ca9a31ea Closes-Bug: #1881910 --- kuryr_libnetwork/controllers.py | 10 ++++++++-- kuryr_libnetwork/tests/unit/test_kuryr.py | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/kuryr_libnetwork/controllers.py b/kuryr_libnetwork/controllers.py index be78be9c..c2a6b03b 100644 --- a/kuryr_libnetwork/controllers.py +++ b/kuryr_libnetwork/controllers.py @@ -1397,7 +1397,8 @@ def network_driver_join(): "SrcName": iface_name, "DstPrefix": config.CONF.binding.veth_dst_prefix }, - "StaticRoutes": [] + "StaticRoutes": [], + "DisableGatewayService": True, } for subnet in all_subnets: @@ -1726,7 +1727,12 @@ def ipam_request_address(): if is_gateway: # check if request gateway ip same with existed gateway ip existed_gateway_ip = subnet.get('gateway_ip', '') - if req_address == existed_gateway_ip: + if not req_address: + if subnet['ip_version'] == 4: + allocated_address = "0.0.0.0/0" + else: + allocated_address = "::/0" + elif req_address == existed_gateway_ip: allocated_address = '{}/{}'.format(req_address, subnet_cidr.prefixlen) else: diff --git a/kuryr_libnetwork/tests/unit/test_kuryr.py b/kuryr_libnetwork/tests/unit/test_kuryr.py index ac338cd0..a77dae0f 100644 --- a/kuryr_libnetwork/tests/unit/test_kuryr.py +++ b/kuryr_libnetwork/tests/unit/test_kuryr.py @@ -2179,7 +2179,8 @@ class TestKuryr(base.TestKuryrBase): 'DstPrefix': config.CONF.binding.veth_dst_prefix, 'SrcName': fake_iface_name, }, - 'StaticRoutes': [] + 'StaticRoutes': [], + 'DisableGatewayService': True } self.assertEqual(200, response.status_code) @@ -2296,7 +2297,8 @@ class TestKuryr(base.TestKuryrBase): 'DstPrefix': config.CONF.binding.veth_dst_prefix, 'SrcName': fake_iface_name, }, - 'StaticRoutes': [] + 'StaticRoutes': [], + 'DisableGatewayService': True } self.assertEqual(200, response.status_code) @@ -2405,7 +2407,8 @@ class TestKuryr(base.TestKuryrBase): fake_v4_subnet['subnet']['host_routes'][0]['nexthop'], 'Destination': fake_v4_subnet['subnet']['host_routes'][0]['destination'], - 'RouteType': constants.ROUTE_TYPE['NEXTHOP']}] + 'RouteType': constants.ROUTE_TYPE['NEXTHOP']}], + 'DisableGatewayService': True } self.assertEqual(200, response.status_code)