network: do not accept route metric > 20000
Network manager can create routes at metric aka priority above 20000. These can stick around if they are not the best choice, or they may disappear quickly. Do not consider one of these routes as a valid default route for has_network purposes.
This commit is contained in:
parent
e095d5040f
commit
69bb8307eb
|
@ -91,8 +91,17 @@ class SubiquityNetworkEventReceiver(NetworkEventReceiver):
|
|||
self.controller.update_has_default_route(self.has_default_route)
|
||||
|
||||
def _default_route_exists(self, routes):
|
||||
return any(route['table'] == 254 and not route['dst']
|
||||
for route in routes)
|
||||
for route in routes:
|
||||
if int(route['table']) != 254:
|
||||
continue
|
||||
if route['dst']:
|
||||
continue
|
||||
if int(route['priority']) >= 20000:
|
||||
# network manager probes routes by creating one at 20000 +
|
||||
# the real metric, but those aren't necessarily valid.
|
||||
continue
|
||||
return True
|
||||
return False
|
||||
|
||||
def probe_default_routes(self):
|
||||
with pyroute2.NDB() as ndb:
|
||||
|
|
|
@ -34,12 +34,13 @@ class TestRoutes(unittest.IsolatedAsyncioTestCase):
|
|||
"ifname": "ens3",
|
||||
"dst": "",
|
||||
"dst_len": 0,
|
||||
"priority": 100,
|
||||
"gateway": "10.0.2.2"
|
||||
}]
|
||||
|
||||
self.assertTrue(self.er._default_route_exists(routes))
|
||||
|
||||
def test_one_good_one_other(self):
|
||||
def test_mix(self):
|
||||
routes = [{
|
||||
"target": "localhost",
|
||||
"tflags": 0,
|
||||
|
@ -47,6 +48,7 @@ class TestRoutes(unittest.IsolatedAsyncioTestCase):
|
|||
"ifname": "ens3",
|
||||
"dst": "",
|
||||
"dst_len": 0,
|
||||
"priority": 100,
|
||||
"gateway": "10.0.2.2"
|
||||
}, {
|
||||
"target": "localhost",
|
||||
|
@ -55,6 +57,25 @@ class TestRoutes(unittest.IsolatedAsyncioTestCase):
|
|||
"ifname": "ens3",
|
||||
"dst": "10.0.2.0",
|
||||
"dst_len": 24,
|
||||
"priority": 100,
|
||||
"gateway": None
|
||||
}, {
|
||||
"target": "localhost",
|
||||
"tflags": 0,
|
||||
"table": 255,
|
||||
"ifname": "ens3",
|
||||
"dst": "10.0.2.0",
|
||||
"dst_len": 24,
|
||||
"priority": 100,
|
||||
"gateway": None
|
||||
}, {
|
||||
"target": "localhost",
|
||||
"tflags": 0,
|
||||
"table": 254,
|
||||
"ifname": "ens3",
|
||||
"dst": "10.0.2.0",
|
||||
"dst_len": 24,
|
||||
"priority": 20100,
|
||||
"gateway": None
|
||||
}]
|
||||
|
||||
|
@ -68,6 +89,7 @@ class TestRoutes(unittest.IsolatedAsyncioTestCase):
|
|||
"ifname": "ens3",
|
||||
"dst": "10.0.2.0",
|
||||
"dst_len": 24,
|
||||
"priority": 100,
|
||||
"gateway": None
|
||||
}]
|
||||
|
||||
|
@ -81,6 +103,21 @@ class TestRoutes(unittest.IsolatedAsyncioTestCase):
|
|||
"ifname": "ens3",
|
||||
"dst": "",
|
||||
"dst_len": 0,
|
||||
"priority": 100,
|
||||
"gateway": "10.0.2.2"
|
||||
}]
|
||||
|
||||
self.assertFalse(self.er._default_route_exists(routes))
|
||||
|
||||
def test_wrong_priority(self):
|
||||
routes = [{
|
||||
"target": "localhost",
|
||||
"tflags": 0,
|
||||
"table": 254,
|
||||
"ifname": "ens3",
|
||||
"dst": "",
|
||||
"dst_len": 0,
|
||||
"priority": 20100,
|
||||
"gateway": "10.0.2.2"
|
||||
}]
|
||||
|
||||
|
|
Loading…
Reference in New Issue