Skip to content

net: render multi-word bond options in the NetworkManager keyfile#6936

Open
tushardev-365 wants to merge 1 commit into
canonical:mainfrom
tushardev-365:fix/nm-bond-multiword-options
Open

net: render multi-word bond options in the NetworkManager keyfile#6936
tushardev-365 wants to merge 1 commit into
canonical:mainfrom
tushardev-365:fix/nm-bond-multiword-options

Conversation

@tushardev-365

Copy link
Copy Markdown

Fixes GH-6932.

The NetworkManager renderer looks up bond options in _prop_map using underscore-separated keys (bond-fail_over_mac). v1 network config uses that spelling, but v2-derived config produces dash-separated internal keys (bond-fail-over-mac), so multi-word options like fail-over-mac-policy, primary-reselect-policy and transmit-hash-policy missed the lookup and were silently dropped from the rendered bond, with no error or warning. Single-token options (mode, miimon, primary, up-delay...) were unaffected, which is why this went unnoticed.

The fix accepts both spellings when looking up the option, mirroring what the sysconfig renderer already does (bond_keys = [bond_key, bond_key.replace("_", "-")]) and what eni/netplan do with .replace("_", "-"). The NM renderer was the only bond renderer not tolerating both.

Testing

  • Added test_bond_multiword_options_from_v2, which renders a v2 bond with fail-over-mac-policy, primary-reselect-policy and transmit-hash-policy and asserts they reach the bond0.nmconnection keyfile. It fails on main (options dropped) and passes with this change.
  • The full test_network_manager.py suite (7 tests) stays green.
  • ruff and black clean on both files.

@holmanb holmanb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this proposal. I left a couple of requests.

Comment on lines +266 to +302
config = textwrap.dedent(
"""\
config = textwrap.dedent("""\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid unnecessary whitespace changes. Same comment below.


def test_subnet_route_metric(self, tmpdir):
"""Test subnet metric renders as route-metric in NM config."""
config = textwrap.dedent(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid unnecessary whitespace changes.

Comment on lines +296 to +299
assert "fail_over_mac=active" in bond_conf
assert "primary_reselect=always" in bond_conf
assert "xmit_hash_policy=layer3+4" in bond_conf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this to use the config / expected_config style of the test above. Checking a couple of keys is okay, but I think it is better to assert the final output.

The NetworkManager renderer looked up bond options in _prop_map using
underscore-separated keys (bond-fail_over_mac). v1 network config uses
that spelling, but v2-derived config produces dash-separated internal
keys (bond-fail-over-mac), so multi-word options such as
fail-over-mac-policy, primary-reselect-policy and transmit-hash-policy
missed the lookup and were silently dropped from the rendered bond.

Accept both spellings when looking up the option, mirroring the
sysconfig and eni renderers which already tolerate dash or underscore.

Fixes canonicalGH-6932

Signed-off-by: Tushar Pagar <240662211+tushardev-365@users.noreply.github.com>
@tushardev-365
tushardev-365 force-pushed the fix/nm-bond-multiword-options branch from 4128abb to f5ab6d3 Compare July 17, 2026 18:32
@tushardev-365

Copy link
Copy Markdown
Author

Thanks for the review. Addressed both points:

  • Dropped the whitespace-only reformatting. The test diff is now purely additive (the new test method only), so the existing tests are untouched.
  • Rewrote test_bond_multiword_options_from_v2 to use the config / expected_config style like the tests above it, asserting the full rendered bond0, eth0 and eth1 nmconnection output rather than spot-checking a couple of keys. This also pins down the exact [bond] section (fail_over_mac=active, primary_reselect=always, xmit_hash_policy=layer3+4) instead of just their presence.

Full suite passes; ruff and black (25.1.0) are clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bond fail-over-mac-policy / primary-reselect-policy not rendered to NetworkManager keyfile (v2)

2 participants