Skip to content

Commit

Permalink
Add tests for quad nic setups and fix debian (#80)
Browse files Browse the repository at this point in the history
This PR adds tests for debian for quad nic setups. The first 5 commits are just some refactors so that the main commits will be easier to see. They mostly just refactor the tests so that we use f-strings instead of .format because we need to process (dedent) the strings in each thunk. Since we are already needing to split the one string in thunks for multi-nic logic I went ahead and added a little more splitting to handle debian vs ubuntu too, hooray deduping.

The second to last commit adds a test parameter with 4 nics but test still pass because the code is buggy. The final commit updates the expected results along with the interfaces template that has the fix.
  • Loading branch information
mmlb authored Mar 5, 2024
2 parents 641d439 + 3ed4379 commit ad6f3e3
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 342 deletions.
37 changes: 29 additions & 8 deletions packetnetworking/distros/debian/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,40 @@ 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",
"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):
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ad6f3e3

Please sign in to comment.