Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cloudinit/net/eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def _render_route(self, route, indent=""):
if k == 'network':
if ':' in route[k]:
route_line += ' -A inet6'
elif route.get('prefix') == 32:
route_line += ' -host'
else:
route_line += ' -net'
if 'prefix' in route:
Expand Down
37 changes: 37 additions & 0 deletions tests/integration_tests/bugs/test_gh668.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Integration test for gh-668.

Ensure that static route to host is working correctly.
Comment thread
tnt-dev marked this conversation as resolved.
The original problem is specific to the ENI renderer but that test is suitable
for all network configuration outputs.
"""

import pytest

from tests.integration_tests.instances import IntegrationInstance


DESTINATION_IP = "172.16.0.10"
GATEWAY_IP = "10.0.0.100"

NETWORK_CONFIG = """\
version: 2
ethernets:
eth0:
addresses: [10.0.0.10/8]
dhcp4: false
routes:
- to: {}/32
via: {}
""".format(DESTINATION_IP, GATEWAY_IP)

EXPECTED_ROUTE = "{} via {}".format(DESTINATION_IP, GATEWAY_IP)


@pytest.mark.lxd_container
@pytest.mark.lxd_vm
@pytest.mark.lxd_config_dict({
"user.network-config": NETWORK_CONFIG,
})
def test_static_route_to_host(client: IntegrationInstance):
route = client.execute("ip route | grep {}".format(DESTINATION_IP))
assert route.startswith(EXPECTED_ROUTE)
7 changes: 7 additions & 0 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,9 @@ def test_routes_rendered(self):
{'type': 'route', 'id': 6,
'metric': 1, 'destination': '10.0.200.0/16',
'gateway': '172.23.31.1'},
{'type': 'route', 'id': 7,
'metric': 1, 'destination': '10.0.0.100/32',
'gateway': '172.23.31.1'},
]

files = self._render_and_read(
Expand All @@ -4843,6 +4846,10 @@ def test_routes_rendered(self):
'172.23.31.1 metric 1 || true'),
('pre-down route del -net 10.0.200.0/16 gw '
'172.23.31.1 metric 1 || true'),
('post-up route add -host 10.0.0.100/32 gw '
'172.23.31.1 metric 1 || true'),
('pre-down route del -host 10.0.0.100/32 gw '
'172.23.31.1 metric 1 || true'),
]
found = files['/etc/network/interfaces'].splitlines()

Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ slyon
smoser
sshedi
TheRealFalcon
tnt-dev
tomponline
tsanghan
WebSpider
Expand Down