diff --git a/kayobe/plugins/filter/networkd.py b/kayobe/plugins/filter/networkd.py index 2d2313581..221272239 100644 --- a/kayobe/plugins/filter/networkd.py +++ b/kayobe/plugins/filter/networkd.py @@ -641,7 +641,8 @@ def networkd_networks(context, names, inventory_hostname=None): set(bond_member_to_bond)) for device in implied_vlan_parents: vlan_interfaces = interface_to_vlans[device] - mtu = max([vlan["mtu"] for vlan in vlan_interfaces]) + vlan_mtus = [vlan["mtu"] for vlan in vlan_interfaces if vlan["mtu"]] + mtu = max(vlan_mtus) if vlan_mtus else None net = _vlan_parent_network(device, mtu, [vlan["device"] for vlan in vlan_interfaces]) diff --git a/kayobe/tests/unit/plugins/filter/test_networkd.py b/kayobe/tests/unit/plugins/filter/test_networkd.py index 45e2e81a2..f2253877c 100644 --- a/kayobe/tests/unit/plugins/filter/test_networkd.py +++ b/kayobe/tests/unit/plugins/filter/test_networkd.py @@ -491,6 +491,44 @@ class TestNetworkdNetworks(BaseNetworkdTest): } self.assertEqual(expected, nets) + def test_vlan_multiple(self): + # Test the case with multiple VLANs on an implied parent without MTUs. + # https://storyboard.openstack.org/#!/story/2009013 + self._update_context({ + "net5_interface": "eth0.3", + "net5_vlan": 3}) + nets = networkd.networkd_networks(self.context, ["net2", "net5"]) + expected = { + "50-kayobe-eth0": [ + { + "Match": [ + {"Name": "eth0"} + ], + }, + { + "Network": [ + {"VLAN": "eth0.2"}, + {"VLAN": "eth0.3"}, + ] + }, + ], + "50-kayobe-eth0.2": [ + { + "Match": [ + {"Name": "eth0.2"} + ] + }, + ], + "50-kayobe-eth0.3": [ + { + "Match": [ + {"Name": "eth0.3"} + ] + }, + ] + } + self.assertEqual(expected, nets) + def test_vlan_with_parent(self): nets = networkd.networkd_networks(self.context, ["net1", "net2", "net5", "net6"]) diff --git a/releasenotes/notes/fix-networkd-vlans-8d5d85da4d2e50ae.yaml b/releasenotes/notes/fix-networkd-vlans-8d5d85da4d2e50ae.yaml new file mode 100644 index 000000000..b17115e07 --- /dev/null +++ b/releasenotes/notes/fix-networkd-vlans-8d5d85da4d2e50ae.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue with systemd-networkd configuration on Ubuntu with multiple + VLAN interfaces. See `story 2009013 + `__ for details.