Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian fix multi-bonds #84

Merged
merged 2 commits into from
Mar 21, 2024
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
9 changes: 8 additions & 1 deletion packetnetworking/distros/debian/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def expected_file_etc_network_interfaces_dhcp_2():
"1bond2nics",
"1bond4nics",
"2bonds2nics",
"2bonds2nics_unsorted",
],
params=[
[
Expand All @@ -57,13 +58,19 @@ def expected_file_etc_network_interfaces_dhcp_2():
{"name": "eth2", "mac": "00:0c:29:51:53:a2", "bond": "bond1"},
{"name": "eth3", "mac": "00:0c:29:51:53:a3", "bond": "bond1"},
],
[
{"name": "eth2", "mac": "00:0c:29:51:53:a2", "bond": "bond1"},
{"name": "eth3", "mac": "00:0c:29:51:53:a3", "bond": "bond1"},
{"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")
resolvers = reversed([fake.ipv4(), fake.ipv4()])
meta_interfaces = request.param
phys_interfaces = [
{"name": iface["name"].replace("eth", "enp"), "mac": iface["mac"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ auto lo
iface lo inet loopback

{% if osinfo.distro == 'ubuntu' %}
{% for iface in interfaces %}
{% for iface in interfaces | sort(attribute="name") %}

auto {{ iface.name }}
iface {{ iface.name }} inet manual
Expand All @@ -13,10 +13,10 @@ iface {{ iface.name }} inet manual
{% endfor %}
{% endif %}

{% for bond in bonds %}
{% for bond in bonds | sort %}

auto {{ bond }}
iface {{ bond }} inet static
iface {{ bond }} inet {% if bond == "bond0" %}static{% else %}manual{% endif +%}
{% if bond == "bond0" %}
{% if ip4pub %}
address {{ ip4pub.address }}
Expand All @@ -27,7 +27,7 @@ iface {{ bond }} inet static
netmask {{ ip4priv.netmask }}
gateway {{ ip4priv.gateway }}
{% endif %}
dns-nameservers {{ resolvers | join(" ") }}
dns-nameservers {{ resolvers | sort | join(" ") }}

{% endif %}
bond-downdelay 200
Expand All @@ -53,7 +53,7 @@ auto bond0:0
iface bond0:0 inet static
address {{ ip4priv.address }}
netmask {{ ip4priv.netmask }}
{% for subnet in private_subnets %}
{% for subnet in private_subnets | sort %}
post-up route add -net {{ subnet }} gw {{ ip4priv.gateway }}
post-down route del -net {{ subnet }} gw {{ ip4priv.gateway }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ iface {{ iface0.name }} inet static
netmask {{ ip4priv.netmask }}
gateway {{ ip4priv.gateway }}
{% endif %}
dns-nameservers {{ resolvers | join(" ") }}
dns-nameservers {{ resolvers | sort | join(" ") }}
{% if ip6pub %}

iface {{ iface0.name }} inet6 static
Expand All @@ -26,7 +26,7 @@ auto {{ iface0.name }}:0
iface {{ iface0.name }}:0 inet static
address {{ ip4priv.address }}
netmask {{ ip4priv.netmask }}
{% for subnet in private_subnets %}
{% for subnet in private_subnets | sort %}
post-up route add -net {{ subnet }} gw {{ ip4priv.gateway }}
post-down route del -net {{ subnet }} gw {{ ip4priv.gateway }}
{% endfor %}
Expand Down
145 changes: 68 additions & 77 deletions packetnetworking/distros/debian/test_bonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def test_public_bonded_task_etc_network_interfaces(
tasks = builder.render()

bonding_mode = builder.network.bonding.mode
dns1 = builder.network.resolvers[0]
dns2 = builder.network.resolvers[1]
ipv4priv = builder.ipv4priv.first
ipv4pub = builder.ipv4pub.first
ipv6pub = builder.ipv6pub.first
Expand All @@ -32,28 +30,28 @@ def test_public_bonded_task_etc_network_interfaces(
"""
result = dedent(partial)
if distro == "ubuntu":
partial = f"""
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
"""
for iface in sorted(builder.network.interfaces, key=lambda iface: iface.name):
if iface.name != builder.network.interfaces[0].name:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
pre-up sleep 4
bond-master bond0
"""
else:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
bond-master bond0
"""
result += dedent(partial)

partial = f"""
auto bond0
iface bond0 inet static
address {ipv4pub.address}
netmask {ipv4pub.netmask}
gateway {ipv4pub.gateway}
dns-nameservers {dns1} {dns2}
dns-nameservers {" ".join(sorted(builder.network.resolvers))}

bond-downdelay 200
bond-miimon 100
Expand Down Expand Up @@ -87,7 +85,7 @@ def test_public_bonded_task_etc_network_interfaces(

partial = f"""
auto {bond}
iface {bond} inet static
iface {bond} inet manual
bond-downdelay 200
bond-miimon 100
bond-mode {bonding_mode}
Expand All @@ -113,37 +111,35 @@ def test_private_bonded_task_etc_network_interfaces(
tasks = builder.render()

bonding_mode = builder.network.bonding.mode
dns1 = builder.network.resolvers[0]
dns2 = builder.network.resolvers[1]
ipv4priv = builder.ipv4priv.first
partial = """\
auto lo
iface lo inet loopback
"""
result = dedent(partial)
if distro == "ubuntu":
partial = f"""
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
"""
for iface in sorted(builder.network.interfaces, key=lambda iface: iface.name):
if iface.name != builder.network.interfaces[0].name:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
pre-up sleep 4
bond-master bond0
"""
else:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
bond-master bond0
"""
result += dedent(partial)

partial = f"""
auto bond0
iface bond0 inet static
address {ipv4priv.address}
netmask {ipv4priv.netmask}
gateway {ipv4priv.gateway}
dns-nameservers {dns1} {dns2}
dns-nameservers {" ".join(sorted(builder.network.resolvers))}

bond-downdelay 200
bond-miimon 100
Expand All @@ -162,7 +158,7 @@ def test_private_bonded_task_etc_network_interfaces(

partial = f"""
auto {bond}
iface {bond} inet static
iface {bond} inet manual
bond-downdelay 200
bond-miimon 100
bond-mode {bonding_mode}
Expand All @@ -181,13 +177,11 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space(
bonded_network_builder, distro, version
):
"""Validates /etc/network/interfaces for a public bond"""
subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]}
subnets = {"private_subnets": reversed(["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]
ipv4priv = builder.ipv4priv.first
ipv4pub = builder.ipv4pub.first
ipv6pub = builder.ipv6pub.first
Expand All @@ -197,28 +191,28 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space(
"""
result = dedent(partial)
if distro == "ubuntu":
partial = f"""
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
"""
for iface in sorted(builder.network.interfaces, key=lambda iface: iface.name):
if iface.name != builder.network.interfaces[0].name:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
pre-up sleep 4
bond-master bond0
"""
else:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
bond-master bond0
"""
result += dedent(partial)

partial = f"""
auto bond0
iface bond0 inet static
address {ipv4pub.address}
netmask {ipv4pub.netmask}
gateway {ipv4pub.gateway}
dns-nameservers {dns1} {dns2}
dns-nameservers {" ".join(sorted(builder.network.resolvers))}

bond-downdelay 200
bond-miimon 100
Expand All @@ -241,10 +235,10 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space(
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}
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}
"""
result += dedent(partial)

Expand All @@ -254,7 +248,7 @@ def test_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space(

partial = f"""
auto {bond}
iface {bond} inet static
iface {bond} inet manual
bond-downdelay 200
bond-miimon 100
bond-mode {bonding_mode}
Expand All @@ -276,42 +270,39 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space
When no public ip is assigned, we should see the private ip details in the
/etc/network/interfaces file.
"""
subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]}
builder = bonded_network_builder(distro, version, public=False, metadata=subnets)
builder = bonded_network_builder(distro, version, public=False)
tasks = builder.render()

bonding_mode = builder.network.bonding.mode
dns1 = builder.network.resolvers[0]
dns2 = builder.network.resolvers[1]
ipv4priv = builder.ipv4priv.first
partial = """\
auto lo
iface lo inet loopback
"""
result = dedent(partial)
if distro == "ubuntu":
partial = f"""
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
"""
for iface in sorted(builder.network.interfaces, key=lambda iface: iface.name):
if iface.name != builder.network.interfaces[0].name:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
pre-up sleep 4
bond-master bond0
"""
else:
partial = f"""
auto {iface.name}
iface {iface.name} inet manual
bond-master bond0
"""
result += dedent(partial)

partial = f"""
auto bond0
iface bond0 inet static
address {ipv4priv.address}
netmask {ipv4priv.netmask}
gateway {ipv4priv.gateway}
dns-nameservers {dns1} {dns2}
dns-nameservers {" ".join(sorted(builder.network.resolvers))}

bond-downdelay 200
bond-miimon 100
Expand All @@ -331,7 +322,7 @@ def test_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space

partial = f"""
auto {bond}
iface {bond} inet static
iface {bond} inet manual
bond-downdelay 200
bond-miimon 100
bond-mode {bonding_mode}
Expand Down
Loading