From 071563198530008651ef12c6039241086c5b60ad Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 16 Dec 2016 17:10:56 -0500 Subject: network: add ENI unit test for statically rendered routes. This just adds a unit test for a case found to be failing in curtin. The issue was reported under bug 1649652. --- tests/unittests/test_net.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 789c78b2..3242c19e 100755 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -769,6 +769,52 @@ class TestEniRoundTrip(TestCase): entry['expected_eni'].splitlines(), files['/etc/network/interfaces'].splitlines()) + def test_routes_rendered(self): + # as reported in bug 1649652 + conf = [ + {'name': 'eth0', 'type': 'physical', + 'subnets': [{ + 'address': '172.23.31.42/26', + 'dns_nameservers': [], 'gateway': '172.23.31.2', + 'type': 'static'}]}, + {'type': 'route', 'id': 4, + 'metric': 0, 'destination': '10.0.0.0/12', + 'gateway': '172.23.31.1'}, + {'type': 'route', 'id': 5, + 'metric': 0, 'destination': '192.168.2.0/16', + 'gateway': '172.23.31.1'}, + {'type': 'route', 'id': 6, + 'metric': 1, 'destination': '10.0.200.0/16', + 'gateway': '172.23.31.1'}, + ] + + files = self._render_and_read( + network_config={'config': conf, 'version': 1}) + expected = [ + 'auto lo', + 'iface lo inet loopback', + 'auto eth0', + 'iface eth0 inet static', + ' address 172.23.31.42/26', + ' gateway 172.23.31.2', + ('post-up route add -net 10.0.0.0 netmask 255.240.0.0 gw ' + '172.23.31.1 metric 0 || true'), + ('pre-down route del -net 10.0.0.0 netmask 255.240.0.0 gw ' + '172.23.31.1 metric 0 || true'), + ('post-up route add -net 192.168.2.0 netmask 255.255.0.0 gw ' + '172.23.31.1 metric 0 || true'), + ('pre-down route del -net 192.168.2.0 netmask 255.255.0.0 gw ' + '172.23.31.1 metric 0 || true'), + ('post-up route add -net 10.0.200.0 netmask 255.255.0.0 gw ' + '172.23.31.1 metric 1 || true'), + ('pre-down route del -net 10.0.200.0 netmask 255.255.0.0 gw ' + '172.23.31.1 metric 1 || true'), + ] + found = files['/etc/network/interfaces'].splitlines() + + self.assertEqual( + expected, [line for line in found if line]) + def _gzip_data(data): with io.BytesIO() as iobuf: -- cgit v1.2.3