Skip to content

Commit

Permalink
fix(scaleway): Don't override IPv6 routes when IPv4 not primary (#5640)
Browse files Browse the repository at this point in the history
If an instance in _routed-ip_ mode uses both IPv4 **and** IPv6, but
the IPv6 is listed (attached) first, the default IPv6 route may be
absent from the final network configuration for systems that do not
accept Router Advertisements.

This change fixes the problem by making sure that routes are
appended, not overwritten.
  • Loading branch information
NoSuchCommand committed Sep 3, 2024
1 parent 9faafb0 commit e30ce6b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cloudinit/sources/DataSourceScaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ def network_config(self):
if ip["address"] == self.ephemeral_fixed_address:
ip_cfg["dhcp4"] = True
# Force addition of a route to the metadata API
ip_cfg["routes"] = [
{"to": "169.254.42.42/32", "via": "62.210.0.1"}
]
route = {"to": "169.254.42.42/32", "via": "62.210.0.1"}
if "routes" in ip_cfg.keys():
ip_cfg["routes"] += [route]
else:
ip_cfg["routes"] = [route]
else:
if "addresses" in ip_cfg.keys():
ip_cfg["addresses"] += (
Expand Down
49 changes: 48 additions & 1 deletion tests/unittests/sources/test_scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def test_ipmob_primary_ipv4_v6_config_ok(
self, m_get_cmdline, fallback_nic
):
"""
Generate network_config with only IPv6
Generate network_config with IPv4+IPv6
"""
m_get_cmdline.return_value = "scaleway"
fallback_nic.return_value = "ens2"
Expand Down Expand Up @@ -995,3 +995,50 @@ def test_ipmob_primary_ipv4_v6_config_ok(
}

self.assertEqual(netcfg, resp)

@mock.patch("cloudinit.distros.net.find_fallback_nic")
@mock.patch("cloudinit.util.get_cmdline")
def test_ipmob_primary_ipv6_v4_config_ok(
self, m_get_cmdline, fallback_nic
):
"""
Generate network_config with IPv6+IPv4
"""
m_get_cmdline.return_value = "scaleway"
fallback_nic.return_value = "ens2"
self.datasource.metadata["private_ip"] = None
self.datasource.metadata["ipv6"] = None
self.datasource.ephemeral_fixed_address = "10.10.10.10"
self.datasource.metadata["public_ips"] = [
{
"address": "2001:aaa:aaaa:a:aaaa:aaaa:aaaa:1",
"netmask": "64",
"gateway": "fe80::ffff:ffff:ffff:fff1",
"family": "inet6",
},
{
"address": "10.10.10.10",
"netmask": "32",
"family": "inet",
},
]

netcfg = self.datasource.network_config
resp = {
"version": 2,
"ethernets": {
fallback_nic.return_value: {
"dhcp4": True,
"routes": [
{
"via": "fe80::ffff:ffff:ffff:fff1",
"to": "::/0",
},
{"to": "169.254.42.42/32", "via": "62.210.0.1"},
],
"addresses": ("2001:aaa:aaaa:a:aaaa:aaaa:aaaa:1/64",),
},
},
}

self.assertEqual(netcfg, resp)
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ nicolasbock
nishigori
nkukard
nmeyerhans
NoSuchCommand
ogayot
olivierlemasle
omBratteng
Expand Down

0 comments on commit e30ce6b

Please sign in to comment.