From dc0d8d30dbfba27da01349794d8e8c34f9b77ab9 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 10:28:14 -0500 Subject: [PATCH 1/7] Sort context dictionary items Helps to find the item being looked for. Editor based search does not work as well because we get lots of hits before this dict so its easier to find the dict then find with my eyes. --- packetnetworking/distros/distro_builder.py | 4 ++-- packetnetworking/distros/test_distro_builder.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packetnetworking/distros/distro_builder.py b/packetnetworking/distros/distro_builder.py index c684338..4f94fa4 100644 --- a/packetnetworking/distros/distro_builder.py +++ b/packetnetworking/distros/distro_builder.py @@ -74,15 +74,15 @@ def build_tasks(self): def context(self): return { "hostname": self.metadata.hostname, - "interfaces": self.network.interfaces, "iface0": self.network.interfaces[0], + "interfaces": self.network.interfaces, "ip4priv": self.ipv4priv.first, "ip4pub": self.ipv4pub.first, "ip6pub": self.ipv6pub.first, "net": self.network, "osinfo": self.metadata.operating_system, - "resolvers": self.network.resolvers, "private_subnets": self.network.private_subnets, + "resolvers": self.network.resolvers, } @property diff --git a/packetnetworking/distros/test_distro_builder.py b/packetnetworking/distros/test_distro_builder.py index 18878b7..ec6d561 100644 --- a/packetnetworking/distros/test_distro_builder.py +++ b/packetnetworking/distros/test_distro_builder.py @@ -176,8 +176,8 @@ def test_distro_builder_context_as_expected(fake_distro_builder_with_metadata): context = fake_distro.context() wanted_context = { "hostname": fake_distro.metadata.hostname, - "interfaces": fake_distro.network.interfaces, "iface0": fake_distro.network.interfaces[0], + "interfaces": fake_distro.network.interfaces, "ip4priv": fake_distro.ipv4priv.first, "ip4pub": fake_distro.ipv4pub.first, "ip6pub": fake_distro.ipv6pub.first, From c9072c500371e81be37ba0f289261c0ed95fc984 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 13:39:28 -0500 Subject: [PATCH 2/7] debian: Use f-strings for results Going to need some logic in here when we start adding variable number of nics. --- .../distros/debian/test_bonded.py | 177 +++++++----------- .../distros/debian/test_individual.py | 105 +++++------ 2 files changed, 116 insertions(+), 166 deletions(-) diff --git a/packetnetworking/distros/debian/test_bonded.py b/packetnetworking/distros/debian/test_bonded.py index 87da470..1bd79fb 100644 --- a/packetnetworking/distros/debian/test_bonded.py +++ b/packetnetworking/distros/debian/test_bonded.py @@ -1,5 +1,4 @@ from textwrap import dedent -from ... import utils from .conftest import versions import pytest @@ -21,8 +20,16 @@ def test_public_bonded_task_etc_network_interfaces( builder = bonded_network_builder(distro, version, public=True) tasks = builder.render() + bonding_mode = builder.network.bonding.mode + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + ipv4priv = builder.ipv4priv.first + ipv4pub = builder.ipv4pub.first + ipv6pub = builder.ipv6pub.first if distro == "ubuntu": - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -63,7 +70,7 @@ def test_public_bonded_task_etc_network_interfaces( post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} """ else: - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -94,17 +101,7 @@ def test_public_bonded_task_etc_network_interfaces( post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} """ - result = dedent(result).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -117,36 +114,15 @@ def test_private_bonded_task_etc_network_interfaces( """ builder = bonded_network_builder(distro, version, public=False) tasks = builder.render() - if distro == "ubuntu": - result = """\ - auto lo - iface lo inet loopback - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - """ - result = """\ + bonding_mode = builder.network.bonding.mode + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + ipv4priv = builder.ipv4priv.first + if distro == "ubuntu": + result = f"""\ auto lo iface lo inet loopback @@ -175,7 +151,7 @@ def test_private_bonded_task_etc_network_interfaces( bond-slaves {iface0.name} {iface1.name} """ else: - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -193,15 +169,7 @@ def test_private_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} """ - result = dedent(result).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -212,8 +180,17 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} builder = bonded_network_builder(distro, version, public=True, metadata=subnets) tasks = builder.render() + + bonding_mode = builder.network.bonding.mode + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + ipv4priv = builder.ipv4priv.first + ipv4pub = builder.ipv4pub.first + ipv6pub = builder.ipv6pub.first if distro == "ubuntu": - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -256,7 +233,7 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} """ else: - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -288,17 +265,7 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} """ - result = dedent(result).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -312,8 +279,15 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} builder = bonded_network_builder(distro, version, public=False, metadata=subnets) tasks = builder.render() + + bonding_mode = builder.network.bonding.mode + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + ipv4priv = builder.ipv4priv.first if distro == "ubuntu": - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -340,9 +314,9 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - """ + """ else: - result = """\ + result = f"""\ auto lo iface lo inet loopback @@ -359,16 +333,8 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - """ - result = dedent(result).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + """ + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -376,11 +342,8 @@ def test_task_etc_modules(bonded_network_builder, distro, version): """Validates /etc/modules for a public bond""" builder = bonded_network_builder(distro, version, public=True) tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) + + result = "bonding\n" assert tasks["etc/modules"]["file_mode"] == "a" assert tasks["etc/modules"]["content"] == result @@ -396,20 +359,18 @@ def test_etc_systemd_resolved_configured(bonded_network_builder, fake, distro, v builder.network.resolvers = (resolver1, resolver2) tasks = builder.render() if distro == "ubuntu": - result = """\ + result = f"""\ [Resolve] DNS={resolver1} {resolver2} """ - result = dedent(result).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/systemd/resolved.conf"] == result + assert tasks["etc/systemd/resolved.conf"] == dedent(result) assert "etc/resolv.conf" not in tasks else: - result = """\ + result = f"""\ nameserver {resolver1} nameserver {resolver2} """ - result = dedent(result).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result + assert tasks["etc/resolv.conf"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -419,11 +380,9 @@ def test_etc_hostname_configured(bonded_network_builder, distro, version): """ builder = bonded_network_builder(distro, version) tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) + + hostname = builder.metadata.hostname + result = f"{hostname}\n" assert tasks["etc/hostname"] == result @@ -434,17 +393,17 @@ def test_etc_hosts_configured(bonded_network_builder, distro, version): """ builder = bonded_network_builder(distro, version) tasks = builder.render() - result = dedent( - """\ + + hostname = builder.metadata.hostname + result = f"""\ 127.0.0.1 localhost {hostname} # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result + """ + assert tasks["etc/hosts"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -455,9 +414,12 @@ def test_persistent_interface_names(bonded_network_builder, distro, version): """ builder = bonded_network_builder(distro, version) tasks = builder.render() - result = dedent( - """\ - {header} + + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + result = f"""\ + # This file was automatically generated by the Equinix Metal installation environment. + # See https://github.com/packethost/packet-networking for details. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. @@ -467,10 +429,5 @@ def test_persistent_interface_names(bonded_network_builder, distro, version): # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}" - """ - ).format( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result + """ + assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == dedent(result) diff --git a/packetnetworking/distros/debian/test_individual.py b/packetnetworking/distros/debian/test_individual.py index 1662a07..f661918 100644 --- a/packetnetworking/distros/debian/test_individual.py +++ b/packetnetworking/distros/debian/test_individual.py @@ -1,5 +1,4 @@ from textwrap import dedent -from ... import utils from .conftest import versions import pytest @@ -20,7 +19,13 @@ def test_public_individual_task_etc_network_interfaces( builder = individual_network_builder(distro, version, public=True) tasks = builder.render() - result = """\ + + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + ipv4priv = builder.ipv4priv.first + ipv4pub = builder.ipv4pub.first + ipv6pub = builder.ipv6pub.first + result = f"""\ auto lo iface lo inet loopback @@ -43,14 +48,7 @@ def test_public_individual_task_etc_network_interfaces( post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} """ - result = dedent(result).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -63,7 +61,11 @@ def test_private_individual_task_etc_network_interfaces( """ builder = individual_network_builder(distro, version, public=False) tasks = builder.render() - result = """\ + + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + ipv4priv = builder.ipv4priv.first + result = f"""\ auto lo iface lo inet loopback @@ -74,12 +76,7 @@ def test_private_individual_task_etc_network_interfaces( gateway {ipv4priv.gateway} dns-nameservers {dns1} {dns2} """ - result = dedent(result).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -90,7 +87,13 @@ def test_public_individual_task_etc_network_interfaces_with_custom_private_ip_sp subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} builder = individual_network_builder(distro, version, public=True, metadata=subnets) tasks = builder.render() - result = """\ + + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + ipv4priv = builder.ipv4priv.first + ipv4pub = builder.ipv4pub.first + ipv6pub = builder.ipv6pub.first + result = f"""\ auto lo iface lo inet loopback @@ -115,14 +118,7 @@ def test_public_individual_task_etc_network_interfaces_with_custom_private_ip_sp post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} """ - result = dedent(result).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -138,7 +134,11 @@ def test_private_individual_task_etc_network_interfaces_with_custom_private_ip_s distro, version, public=False, metadata=subnets ) tasks = builder.render() - result = """\ + + dns1 = builder.network.resolvers[0] + dns2 = builder.network.resolvers[1] + ipv4priv = builder.ipv4priv.first + result = f"""\ auto lo iface lo inet loopback @@ -149,12 +149,7 @@ def test_private_individual_task_etc_network_interfaces_with_custom_private_ip_s gateway {ipv4priv.gateway} dns-nameservers {dns1} {dns2} """ - result = dedent(result).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result + assert tasks["etc/network/interfaces"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -167,21 +162,20 @@ def test_dns_resolver_configured(individual_network_builder, fake, distro, versi resolver2 = fake.ipv4() builder.network.resolvers = (resolver1, resolver2) tasks = builder.render() + if distro == "ubuntu": - result = """\ + result = f"""\ [Resolve] DNS={resolver1} {resolver2} """ - result = dedent(result).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/systemd/resolved.conf"] == result + assert tasks["etc/systemd/resolved.conf"] == dedent(result) assert "etc/resolv.conf" not in tasks else: - result = """\ + result = f"""\ nameserver {resolver1} nameserver {resolver2} """ - result = dedent(result).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result + assert tasks["etc/resolv.conf"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -191,10 +185,9 @@ def test_etc_hostname_configured(individual_network_builder, distro, version): """ builder = individual_network_builder(distro, version) tasks = builder.render() - result = """\ - {hostname} - """ - result = dedent(result).format(hostname=builder.metadata.hostname) + + hostname = builder.metadata.hostname + result = f"{hostname}\n" assert tasks["etc/hostname"] == result @@ -205,16 +198,17 @@ def test_etc_hosts_configured(individual_network_builder, distro, version): """ builder = individual_network_builder(distro, version) tasks = builder.render() - result = """\ + + hostname = builder.metadata.hostname + result = f"""\ 127.0.0.1 localhost {hostname} # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters - """ - result = dedent(result).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result + """ + assert tasks["etc/hosts"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) @@ -225,8 +219,12 @@ def test_persistent_interface_names(individual_network_builder, distro, version) """ builder = individual_network_builder(distro, version) tasks = builder.render() - result = """\ - {header} + + iface0 = builder.network.interfaces[0] + iface1 = builder.network.interfaces[1] + result = f"""\ + # This file was automatically generated by the Equinix Metal installation environment. + # See https://github.com/packethost/packet-networking for details. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. @@ -236,16 +234,11 @@ def test_persistent_interface_names(individual_network_builder, distro, version) # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}" - """ - result = dedent(result).format( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) + """ if distro == "debian" and version == "12": assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks else: - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result + assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == dedent(result) @pytest.mark.parametrize("distro,version", versions) From 91e6c79b2c5922bf232e08d32832f57323c007bd Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 14:49:52 -0500 Subject: [PATCH 3/7] Avoid duplicating expected results for debian/ubuntu tests I figured out what needed to be done to share as much of the expected results as possible. This is going to come very handy when we get variable number of nics which requires the results to built up in pieces (to avoid using jinja template to verify jinja template...). --- .../distros/debian/test_bonded.py | 252 +++++++----------- 1 file changed, 92 insertions(+), 160 deletions(-) diff --git a/packetnetworking/distros/debian/test_bonded.py b/packetnetworking/distros/debian/test_bonded.py index 1bd79fb..0327b7c 100644 --- a/packetnetworking/distros/debian/test_bonded.py +++ b/packetnetworking/distros/debian/test_bonded.py @@ -28,20 +28,25 @@ def test_public_bonded_task_etc_network_interfaces( ipv4priv = builder.ipv4priv.first ipv4pub = builder.ipv4pub.first ipv6pub = builder.ipv6pub.first - if distro == "ubuntu": - result = f"""\ + partial = """\ auto lo iface lo inet loopback + """ + result = dedent(partial) + if distro == "ubuntu": + partial = f""" + auto {iface0.name} + iface {iface0.name} inet manual + bond-master bond0 - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 + auto {iface1.name} + iface {iface1.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) + partial = f""" auto bond0 iface bond0 inet static address {ipv4pub.address} @@ -54,40 +59,12 @@ def test_public_bonded_task_etc_network_interfaces( bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} """ - else: - result = f"""\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} - - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - + result += dedent(partial) + if distro == "ubuntu": + result += " bond-lacp-rate 1\n" + result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + partial = f""" iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -100,8 +77,8 @@ def test_public_bonded_task_etc_network_interfaces( post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} """ - - assert tasks["etc/network/interfaces"] == dedent(result) + result += dedent(partial) + assert tasks["etc/network/interfaces"] == result @pytest.mark.parametrize("distro,version", versions) @@ -121,20 +98,25 @@ def test_private_bonded_task_etc_network_interfaces( iface0 = builder.network.interfaces[0] iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first - if distro == "ubuntu": - result = f"""\ + partial = """\ auto lo iface lo inet loopback + """ + result = dedent(partial) + if distro == "ubuntu": + partial = f""" + auto {iface0.name} + iface {iface0.name} inet manual + bond-master bond0 - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 + auto {iface1.name} + iface {iface1.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) + partial = f""" auto bond0 iface bond0 inet static address {ipv4priv.address} @@ -147,29 +129,13 @@ def test_private_bonded_task_etc_network_interfaces( bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} """ - else: - result = f"""\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} + result += dedent(partial) + if distro == "ubuntu": + result += " bond-lacp-rate 1\n" + result += f" bond-slaves {iface0.name} {iface1.name}\n" - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - """ - assert tasks["etc/network/interfaces"] == dedent(result) + assert tasks["etc/network/interfaces"] == result @pytest.mark.parametrize("distro,version", versions) @@ -189,20 +155,25 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( ipv4priv = builder.ipv4priv.first ipv4pub = builder.ipv4pub.first ipv6pub = builder.ipv6pub.first - if distro == "ubuntu": - result = f"""\ + partial = """\ auto lo iface lo inet loopback + """ + result = dedent(partial) + if distro == "ubuntu": + partial = f""" + auto {iface0.name} + iface {iface0.name} inet manual + bond-master bond0 - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 + auto {iface1.name} + iface {iface1.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) + partial = f""" auto bond0 iface bond0 inet static address {ipv4pub.address} @@ -215,42 +186,13 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} """ - else: - result = f"""\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} - - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} + result += dedent(partial) + if distro == "ubuntu": + result += " bond-lacp-rate 1\n" + result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + partial = f""" iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -265,7 +207,8 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} """ - assert tasks["etc/network/interfaces"] == dedent(result) + result += dedent(partial) + assert tasks["etc/network/interfaces"] == result @pytest.mark.parametrize("distro,version", versions) @@ -286,11 +229,13 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space iface0 = builder.network.interfaces[0] iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first + partial = """\ + auto lo + iface lo inet loopback + """ + result = dedent(partial) if distro == "ubuntu": - result = f"""\ - auto lo - iface lo inet loopback - + partial = f""" auto {iface0.name} iface {iface0.name} inet manual bond-master bond0 @@ -299,42 +244,29 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space iface {iface1.name} inet manual pre-up sleep 4 bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - """ - else: - result = f"""\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} """ - assert tasks["etc/network/interfaces"] == dedent(result) + result += dedent(partial) + + partial = f""" + auto bond0 + iface bond0 inet static + address {ipv4priv.address} + netmask {ipv4priv.netmask} + gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + + bond-downdelay 200 + bond-miimon 100 + bond-mode {bonding_mode} + bond-updelay 200 + bond-xmit_hash_policy layer3+4 + """ + result += dedent(partial) + if distro == "ubuntu": + result += " bond-lacp-rate 1\n" + + result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + assert tasks["etc/network/interfaces"] == result @pytest.mark.parametrize("distro,version", versions) From 3585d66a3213c37baa0863621ddae8a6b748bda3 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 15:00:55 -0500 Subject: [PATCH 4/7] Rework debian/ubuntu expected results for variable nic quantities These strings are hard coding the number of nics at 2 and would fail when we add any more. Now they wont. --- .../distros/debian/test_bonded.py | 102 +++++++++--------- .../distros/debian/test_individual.py | 34 ++++-- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/packetnetworking/distros/debian/test_bonded.py b/packetnetworking/distros/debian/test_bonded.py index 0327b7c..70f043e 100644 --- a/packetnetworking/distros/debian/test_bonded.py +++ b/packetnetworking/distros/debian/test_bonded.py @@ -23,8 +23,6 @@ def test_public_bonded_task_etc_network_interfaces( bonding_mode = builder.network.bonding.mode dns1 = builder.network.resolvers[0] dns2 = builder.network.resolvers[1] - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first ipv4pub = builder.ipv4pub.first ipv6pub = builder.ipv6pub.first @@ -35,16 +33,19 @@ def test_public_bonded_task_etc_network_interfaces( result = dedent(partial) if distro == "ubuntu": partial = f""" - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 + auto {builder.network.interfaces[0].name} + iface {builder.network.interfaces[0].name} inet manual bond-master bond0 """ result += dedent(partial) + for iface in builder.network.interfaces[1:]: + partial = f""" + auto {iface.name} + iface {iface.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) partial = f""" auto bond0 @@ -63,7 +64,7 @@ def test_public_bonded_task_etc_network_interfaces( result += dedent(partial) if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" partial = f""" iface bond0 inet6 static address {ipv6pub.address} @@ -95,8 +96,6 @@ def test_private_bonded_task_etc_network_interfaces( bonding_mode = builder.network.bonding.mode dns1 = builder.network.resolvers[0] dns2 = builder.network.resolvers[1] - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first partial = """\ auto lo @@ -105,16 +104,19 @@ def test_private_bonded_task_etc_network_interfaces( result = dedent(partial) if distro == "ubuntu": partial = f""" - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 + auto {builder.network.interfaces[0].name} + iface {builder.network.interfaces[0].name} inet manual bond-master bond0 """ result += dedent(partial) + for iface in builder.network.interfaces[1:]: + partial = f""" + auto {iface.name} + iface {iface.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) partial = f""" auto bond0 @@ -133,7 +135,7 @@ def test_private_bonded_task_etc_network_interfaces( result += dedent(partial) if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f" bond-slaves {iface0.name} {iface1.name}\n" + result += f" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n" assert tasks["etc/network/interfaces"] == result @@ -150,8 +152,6 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( bonding_mode = builder.network.bonding.mode dns1 = builder.network.resolvers[0] dns2 = builder.network.resolvers[1] - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first ipv4pub = builder.ipv4pub.first ipv6pub = builder.ipv6pub.first @@ -162,16 +162,19 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( result = dedent(partial) if distro == "ubuntu": partial = f""" - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 + auto {builder.network.interfaces[0].name} + iface {builder.network.interfaces[0].name} inet manual bond-master bond0 """ result += dedent(partial) + for iface in builder.network.interfaces[1:]: + partial = f""" + auto {iface.name} + iface {iface.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) partial = f""" auto bond0 @@ -191,7 +194,7 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" partial = f""" iface bond0 inet6 static address {ipv6pub.address} @@ -226,8 +229,6 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space bonding_mode = builder.network.bonding.mode dns1 = builder.network.resolvers[0] dns2 = builder.network.resolvers[1] - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] ipv4priv = builder.ipv4priv.first partial = """\ auto lo @@ -236,16 +237,19 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space result = dedent(partial) if distro == "ubuntu": partial = f""" - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 + auto {builder.network.interfaces[0].name} + iface {builder.network.interfaces[0].name} inet manual bond-master bond0 """ result += dedent(partial) + for iface in builder.network.interfaces[1:]: + partial = f""" + auto {iface.name} + iface {iface.name} inet manual + pre-up sleep 4 + bond-master bond0 + """ + result += dedent(partial) partial = f""" auto bond0 @@ -265,7 +269,7 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {iface0.name} {iface1.name}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" assert tasks["etc/network/interfaces"] == result @@ -347,19 +351,19 @@ def test_persistent_interface_names(bonded_network_builder, distro, version): builder = bonded_network_builder(distro, version) tasks = builder.render() - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] - result = f"""\ + result = """\ # This file was automatically generated by the Equinix Metal installation environment. # See https://github.com/packethost/packet-networking for details. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. - - # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) - SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface0.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface0.name}" - - # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) - SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}" """ + result = dedent(result) + + for iface in builder.network.interfaces: + partial = f""" + # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) + SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface.name}" + """ + result += dedent(partial) assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == dedent(result) diff --git a/packetnetworking/distros/debian/test_individual.py b/packetnetworking/distros/debian/test_individual.py index f661918..1560084 100644 --- a/packetnetworking/distros/debian/test_individual.py +++ b/packetnetworking/distros/debian/test_individual.py @@ -220,32 +220,32 @@ def test_persistent_interface_names(individual_network_builder, distro, version) builder = individual_network_builder(distro, version) tasks = builder.render() - iface0 = builder.network.interfaces[0] - iface1 = builder.network.interfaces[1] - result = f"""\ + partial = """\ # This file was automatically generated by the Equinix Metal installation environment. # See https://github.com/packethost/packet-networking for details. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. + """ + result = dedent(partial) - # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) - SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface0.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface0.name}" + for iface in builder.network.interfaces: + partial = f""" + # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) + SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface.name}" + """ + result += dedent(partial) - # PCI device (custom name provided by external tool to mimic Predictable Network Interface Names) - SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}" - """ if distro == "debian" and version == "12": assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks else: - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == dedent(result) + assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result @pytest.mark.parametrize("distro,version", versions) def test_public_individual_dhcp_task_etc_network_interfaces( individual_network_builder, make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, distro, version, ): @@ -256,6 +256,18 @@ def test_public_individual_dhcp_task_etc_network_interfaces( ) tasks = builder.render() - result = expected_file_etc_network_interfaces_dhcp_2 + partial = """\ + auto lo + iface lo inet loopback + """ + result = dedent(partial) + + for iface in builder.network.interfaces: + partial = f""" + auto {iface.name} + iface {iface.name} inet dhcp + """ + result += dedent(partial) + result += "\n" assert tasks["etc/network/interfaces"] == result From 71280760c03ee16c01a7f6510a7fc7cbd1bf3cb0 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 15:04:28 -0500 Subject: [PATCH 5/7] Rework debianbuilder test fixture to parametrize the nic setup By parametrizing this we will be able to easily add more permuations. --- packetnetworking/distros/debian/conftest.py | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packetnetworking/distros/debian/conftest.py b/packetnetworking/distros/debian/conftest.py index 5df1942..735a8eb 100644 --- a/packetnetworking/distros/debian/conftest.py +++ b/packetnetworking/distros/debian/conftest.py @@ -34,19 +34,26 @@ def expected_file_etc_network_interfaces_dhcp_2(): yield expected_file_etc_network_interfaces_dhcp_2 -@pytest.fixture -def debianbuilder(mockit, fake, metadata, patch_dict): +@pytest.fixture( + ids=[ + "1bond2nics", + ], + params=[ + [ + {"name": "eth0", "mac": "00:0c:29:51:53:a0", "bond": "bond0"}, + {"name": "eth1", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, + ], + ], +) +def debianbuilder(mockit, fake, metadata, patch_dict, request): gen_metadata = metadata def _builder(metadata=None, public=True, post_gen_metadata=None): resolvers = ("1.2.3.4", "2.3.4.5") - meta_interfaces = [ - {"name": "eth0", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, - {"name": "eth1", "mac": "00:0c:29:51:53:a2", "bond": "bond0"}, - ] + meta_interfaces = request.param phys_interfaces = [ - {"name": "enp0", "mac": "00:0c:29:51:53:a1"}, - {"name": "enp1", "mac": "00:0c:29:51:53:a2"}, + {"name": iface["name"].replace("eth", "enp"), "mac": iface["mac"]} + for iface in meta_interfaces ] _metadata = {"network": {"interfaces": meta_interfaces}} if metadata: From 3bf1f016dc834f85c0562fb813895b326728bf0e Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 15:05:32 -0500 Subject: [PATCH 6/7] Add new set of test scenarios for quad nics to debian This is to verify current behavior that is actually buggy. When we have 4 nics we always end up putting them in the same bond, regardless of what metadata instructs. --- packetnetworking/distros/debian/conftest.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packetnetworking/distros/debian/conftest.py b/packetnetworking/distros/debian/conftest.py index 735a8eb..55463b6 100644 --- a/packetnetworking/distros/debian/conftest.py +++ b/packetnetworking/distros/debian/conftest.py @@ -37,12 +37,26 @@ def expected_file_etc_network_interfaces_dhcp_2(): @pytest.fixture( ids=[ "1bond2nics", + "1bond4nics", + "2bonds2nics", ], params=[ [ {"name": "eth0", "mac": "00:0c:29:51:53:a0", "bond": "bond0"}, {"name": "eth1", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, ], + [ + {"name": "eth0", "mac": "00:0c:29:51:53:a0", "bond": "bond0"}, + {"name": "eth1", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, + {"name": "eth2", "mac": "00:0c:29:51:53:a2", "bond": "bond0"}, + {"name": "eth3", "mac": "00:0c:29:51:53:a3", "bond": "bond0"}, + ], + [ + {"name": "eth0", "mac": "00:0c:29:51:53:a0", "bond": "bond0"}, + {"name": "eth1", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, + {"name": "eth2", "mac": "00:0c:29:51:53:a2", "bond": "bond1"}, + {"name": "eth3", "mac": "00:0c:29:51:53:a3", "bond": "bond1"}, + ], ], ) def debianbuilder(mockit, fake, metadata, patch_dict, request): From 3ed4379375d8f96c1581204f1b8edeb8e4afa3b2 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 5 Mar 2024 15:15:19 -0500 Subject: [PATCH 7/7] Ensure bond0 has only the requested nics as members for debianish oses This has been a long time bug that is very hard to reproduce due to depending on what order the nics come up on the network. Quoting Tim Jackson: > If all 4 nics are in the same bond, the remote (partner lacp id) has > to match for all 4, so if say eth1 [recte eth2] comes up first on the > server side, anything in the other bond from the ToR side will fail to > actually bond due to a mismatch in the partner key. This is only happening in Debian because Ubuntu has the `pre-up sleep 4` for all the other nics so eth0 comes up first which causes the "main" bond to be correct and thus networking works well enough to phone-home and activate. --- .../debian/templates/bonded/etc_network_interfaces.j2 | 2 +- packetnetworking/distros/debian/test_bonded.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 b/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 index cde6e56..69af616 100644 --- a/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 +++ b/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 @@ -33,7 +33,7 @@ iface bond0 inet static {% if osinfo.distro == 'ubuntu' and net.bonding.mode == 4 %} bond-lacp-rate 1 {% endif %} - bond-slaves {{ interfaces | map(attribute='name') | join(' ')}} + bond-slaves {{ interfaces | selectattr('bond', 'in', '["bond0"]') | map(attribute='name') | join(' ')}} {% if ip6pub %} iface bond0 inet6 static diff --git a/packetnetworking/distros/debian/test_bonded.py b/packetnetworking/distros/debian/test_bonded.py index 70f043e..fe254ca 100644 --- a/packetnetworking/distros/debian/test_bonded.py +++ b/packetnetworking/distros/debian/test_bonded.py @@ -64,7 +64,7 @@ def test_public_bonded_task_etc_network_interfaces( result += dedent(partial) if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces if iface.bond == "bond0"])}\n""" partial = f""" iface bond0 inet6 static address {ipv6pub.address} @@ -135,7 +135,7 @@ def test_private_bonded_task_etc_network_interfaces( result += dedent(partial) if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces if iface.bond == "bond0"])}\n""" assert tasks["etc/network/interfaces"] == result @@ -194,7 +194,7 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces if iface.bond == "bond0"])}\n""" partial = f""" iface bond0 inet6 static address {ipv6pub.address} @@ -269,7 +269,7 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space if distro == "ubuntu": result += " bond-lacp-rate 1\n" - result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces])}\n""" + result += f""" bond-slaves {' '.join([iface.name for iface in builder.network.interfaces if iface.bond == "bond0"])}\n""" assert tasks["etc/network/interfaces"] == result