Repository navigation
Add nm_ip NetworkManager provider for network.managed (#54791) - #69620
Conversation
charzl
left a comment
There was a problem hiding this comment.
Overall looks good to me, I think the PR is on the correct direction, just some minor issue that can improve.
|
Thanks @charzl, good catches - both addressed in the latest push. Keyfile permissions: switched MTU on bond/bridge/vlan: I dug into this rather than adding a warn/error, and it turns out MTU is settable on those types, so I implemented emitting it. You're right that the native Deduplication: the provider-selection gate duplicated in While I was in here I closed a few adjacent gaps against the rh_ip parity bar, each with direct + inverse tests: Validation: beyond the unit tests, I rendered the emitted keyfile for every one of these and parsed it back with libnm on EL8/EL9/EL10/Fedora (NetworkManager 1.40 through 1.56), asserting each property comes back set - 48/48 green, mtu-on-bond included on the old 1.40 stack. So the new keys are accepted across the supported NM range, not just the latest. Changelog added as |
Move tests/unit/modules/test_rh_ip.py to tests/pytests/unit/modules/test_rh_ip.py, converting the legacy unittest.TestCase style (LoaderModuleMockMixin, self.assertX) to modern pytest (configure_loader_modules fixture, plain asserts, pytest.raises). Faithful style-only migration: all 26 tests preserved and passing; the legacy file (which no longer runs under the current pytest/py3.12 test env) is removed. This lets the rh_ip test suite run in the maintained pytests tree, ahead of adding NetworkManager-aware provider selection for saltstack#54791.
network.managed has been broken on RedHat-family systems since EL8. The
rh_ip provider writes /etc/sysconfig/network-scripts/ifcfg-* files and
brings interfaces up with ifup/ifdown from the network-scripts package.
That package is not installed by default on EL8+ and is removed entirely
on EL10, so the state fails with
Unable to run command '['ifdown', 'eth1']' ... No such file or
directory: 'ifdown'
and configures nothing. Verified on AlmaLinux 8, 9 and 10.
nm_ip writes NetworkManager keyfiles under
/etc/NetworkManager/system-connections/ and applies them with nmcli, the
supported way to manage networking on modern RedHat systems. It supports
ethernet (static/dhcp/disabled, dual-stack), bond, vlan and bridge, with
bond/bridge members written as their own port keyfiles. A deterministic
per-interface connection uuid keeps build_interface output identical to
the keyfile NetworkManager reads back, so the state stays idempotent.
Provider selection is a single condition both modules test: nmcli
present, /run/NetworkManager exists, and no ifup/ifdown on PATH. nm_ip
claims the ip virtual when that holds; rh_ip defers to it. Hosts that
still have network-scripts installed keep the legacy rh_ip behavior.
Also addresses saltstack#68252 and saltstack#62844, which share this root cause.
Validated end to end on AlmaLinux 8, 9 and 10 VMs: nm_ip is selected,
network.managed brings the interface up, a second apply is a no-op, and
the address persists across reboot.
3006.27 was released 2026-07-01 without this provider, so the next available 3006.x release is 3006.28.
… Amazon deferral The direct tests call nm_ip.build_interface at the exact altitude network.managed uses (name, iface_type, enabled, **kwargs with the state-injected test flag): test=True must return the rendered keyfile lines for the diff without writing anything (including bond port keyfiles), and the same call with test=False must write those exact lines. The inverse tests guard the refactored rh_ip.__virtual__ against overcorrection: Amazon Linux 2 with network-scripts must still claim ip and Amazon Linux 1 must still decline, verified against the base branch module as well.
Close a set of coverage gaps in the nm_ip (NetworkManager keyfile) ip provider so it maps more of the network.managed schema and moves closer to rh_ip parity, and address review feedback on keyfile permissions and code duplication. Coverage: - mtu on bond/bridge/vlan is now emitted via a separate [ethernet] (802-3-ethernet) section attached to the connection, matching how NM sets MTU on virtual devices. Previously it was accepted and silently dropped because the native [bond]/[bridge]/[vlan] settings have no mtu key. Ethernet interfaces keep folding mtu into their own [ethernet] section. - hwaddr pins a connection to a NIC's permanent MAC (802-3-ethernet mac-address, or bridge.mac-address for bridges), honouring the auto/none sentinels. macaddr sets the in-use MAC (802-3-ethernet cloned-mac-address) and is mutually exclusive with hwaddr, matching rh_ip. - The autoneg/speed/duplex ethtool link parameters map to [ethernet] auto-negotiate/speed/duplex (speed and duplex must be set together) instead of being rejected. Offload/channel/advertise ethtool knobs, which have no keyfile equivalent, are still refused. - Bond options are passed through to [bond] from the full kernel bonding set (ad_select, fail_over_mac, primary_reselect, arp_validate, all_slaves_active, min_links, ...) rather than a fixed ten-key allow-list. Option names are validated and mode stays required. - dns-search is written under [ipv6] as well as [ipv4], so search domains survive on IPv6-only hosts; a disabled family no longer carries a dead dns-search line. - vlan reorder_hdr/gvrp/loose_binding fold into the [vlan] flags bitmask (emitted only when it diverges from NM's default), and wol maps to [ethernet] wake-on-lan. Hardening / cleanup: - Write keyfiles with salt.utils.files.fpopen(mode=0o600) so the connection file is created with 0600 permissions before any content is written, instead of chmod'ing an already-populated file. - Extract the shared NetworkManager provider-selection check into salt.utils.network.nm_managed; nm_ip.nm_managed and rh_ip._nm_managed now both call it so exactly one provider claims the ip module. Add direct and inverse unit tests for each gap under tests/pytests/unit/modules/test_nm_ip.py.
…d-mode error - _write_keyfile writes to a 0600 mkstemp temp in the keyfile's own directory and os.replace()s it onto the target, so NetworkManager (which watches these files via inotify) never sees a half-written or briefly world-readable keyfile. Replaces the in-place fpopen write; a copy that preserves the destination mode (salt.utils.files.copyfile) would let an existing 0644 keyfile stay world-readable, so it is deliberately not used here. - _listify also splits on ';', NetworkManager's on-disk array delimiter, so a pillar value pre-formatted that way parses into individual entries. - The missing-bond-mode error names example modes and explains why mode is required rather than defaulted (rh_ip requires it too). Adds direct tests for the atomic 0600 write (including rewriting an existing 0644 keyfile) and for semicolon _listify.
|
Please address the lint failures, otherwise looks good. |
The atomic-write test read the file back with a bare open(), which the test suite's pylint checker flags as W8470 (resource-leakage). Use salt.utils.files.fopen instead, per the salt convention. This is what broke Lint / Lint Salt's Test Suite on the previous commit.
|
Done in ec566e2 -- the lint failure was salt's W8470 (resource-leakage) checker flagging two bare |
What does this PR do?
network.managedhas been broken on RedHat-family systems since EL8. Therh_ipprovider writes/etc/sysconfig/network-scripts/ifcfg-*files and brings interfaces up withifup/ifdownfrom thenetwork-scriptspackage, which is not installed by default on EL8+ and is removed entirely on EL10. The state fails with:and configures nothing.
This adds
nm_ip, anipprovider that writes NetworkManager keyfiles under/etc/NetworkManager/system-connections/and applies them withnmcli. It supports ethernet (static/dhcp/disabled, dual-stack), bond, vlan, and bridge, with bond/bridge members written as their own port keyfiles. A deterministic per-interface connection uuid keepsbuild_interfaceoutput identical to the keyfile NetworkManager reads back, so the state stays idempotent.Fixes #54791. Also addresses #68252 and #62844, which share this root cause.
Compatibility note (automatic provider swap)
Provider selection is a single condition both modules test:
nmclipresent,/run/NetworkManagerexists, and noifup/ifdownon PATH.nm_ipclaims theipvirtual when that holds;rh_ipdefers.This means the
ipprovider changes automatically on affected hosts:network-scripts(the default): the provider switches fromrh_iptonm_ip. On these hostsrh_ipis already non-functional (it dies onifdown), so nothing that previously worked stops working -- but operators should be aware the config now lands as NM keyfiles rather thanifcfg-*files.network-scriptsinstalled (legacy setups, or where an admin has added it):ifup/ifdownare present, the condition is false, andrh_ipcontinues to own theipprovider exactly as before. No change.The switch is intentional -- it is what makes
network.managedwork again on modern EL -- but it is a behavior change worth calling out for anyone who inspectsifcfg-*files or has tooling that reads them.What issues does this PR fix or reference?
Fixes #54791
Refs #68252, #62844
Previous Behavior
network.managedon EL8+ failed withNo such file or directory: 'ifdown'and wrote no configuration.New Behavior
On NetworkManager-managed RedHat hosts,
network.managedwrites NM keyfiles and applies them withnmcli; interfaces come up and persist across reboot.Tests written?
Yes. 33 unit tests for
nm_ipplus deferral tests forrh_ip. The existingrh_ipunit tests were also migrated from the legacyTestCasestyle to pytest in this branch.Validated end-to-end on real AlmaLinux 8, 9, and 10 VMs (VMware):
nm_ipis selected,network.managedbrings the interface up, a second apply is a no-op, and the address persists across reboot.Branch target
Targeted at 3006.x since it fixes a severity-high regression that makes the state unusable on current EL. Happy to rebase onto master (or a newer branch) if maintainers consider a new provider module more appropriate there.