-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: use pyroute2 to manage default routes
The existing event based method of watching for has_network has a flaw. The incoming route_change events from probert do not distinguish routes on the same interface but a different metric, so if 2 routes on one interface appear, we only get one event. Then if one of those routes is removed, we will inappropriately remove this route from the default_routes list. Aside from the code watching the event stream, the set of default routes is an elaborate boolean value. Simplify the code by passing around a boolean, and when we get a route_change event, use that to go looking again at the list of default routes. LP: #2004659
- Loading branch information
Showing
10 changed files
with
157 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2015 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright 2023 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
from unittest.mock import Mock | ||
|
||
from subiquitycore.controllers.network import SubiquityNetworkEventReceiver | ||
|
||
|
||
class TestRoutes(unittest.IsolatedAsyncioTestCase): | ||
def setUp(self): | ||
self.er = SubiquityNetworkEventReceiver(Mock()) | ||
|
||
def test_empty(self): | ||
self.assertFalse(self.er._analyze_routes([])) | ||
|
||
def test_one_good(self): | ||
routes = [{ | ||
"target": "localhost", | ||
"tflags": 0, | ||
"table": 254, | ||
"ifname": "ens3", | ||
"dst": "", | ||
"dst_len": 0, | ||
"gateway": "10.0.2.2" | ||
}] | ||
|
||
self.assertTrue(self.er._analyze_routes(routes)) | ||
|
||
def test_one_good_one_other(self): | ||
routes = [{ | ||
"target": "localhost", | ||
"tflags": 0, | ||
"table": 254, | ||
"ifname": "ens3", | ||
"dst": "", | ||
"dst_len": 0, | ||
"gateway": "10.0.2.2" | ||
}, { | ||
"target": "localhost", | ||
"tflags": 0, | ||
"table": 254, | ||
"ifname": "ens3", | ||
"dst": "10.0.2.0", | ||
"dst_len": 24, | ||
"gateway": None | ||
}] | ||
|
||
self.assertTrue(self.er._analyze_routes(routes)) | ||
|
||
def test_one_other(self): | ||
routes = [{ | ||
"target": "localhost", | ||
"tflags": 0, | ||
"table": 254, | ||
"ifname": "ens3", | ||
"dst": "10.0.2.0", | ||
"dst_len": 24, | ||
"gateway": None | ||
}] | ||
|
||
self.assertFalse(self.er._analyze_routes(routes)) | ||
|
||
def test_wrong_table(self): | ||
routes = [{ | ||
"target": "localhost", | ||
"tflags": 0, | ||
"table": 255, | ||
"ifname": "ens3", | ||
"dst": "", | ||
"dst_len": 0, | ||
"gateway": "10.0.2.2" | ||
}] | ||
|
||
self.assertFalse(self.er._analyze_routes(routes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters