From ea7f304cc1ad32c3f2c25b49bf6b2663f348496a Mon Sep 17 00:00:00 2001 From: Gris Ge Date: Tue, 28 Jul 2020 15:59:11 +0800 Subject: [PATCH] nm: Mark external subordinate as changed When user create bond with subordinate interfaces using non-NM tools(iproute), the NetworkManager will mark the subordinates as managed externally. When the desire state only contains the main interface, nmstate noticing the slave list is unchanged, so only activate the main interface, then NM remove the subordinate from their main interface. To workaround that, mark subordinate interfaces as changed when they are managed by NM as externally. Integration test case included. Signed-off-by: Gris Ge --- libnmstate/nm/applier.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py index a91cee5..68d11dc 100644 --- a/libnmstate/nm/applier.py +++ b/libnmstate/nm/applier.py @@ -79,6 +79,7 @@ def apply_changes(context, net_state, save_to_disk): ) _preapply_dns_fix(context, net_state) + _mark_nm_external_subordinate_changed(context, net_state) ifaces_desired_state = net_state.ifaces.state_to_edit ifaces_desired_state.extend( @@ -625,3 +626,26 @@ def _has_ovs_interface_desired_or_changed(net_state): InterfaceType.OVS_PORT, ) and (iface.is_desired or iface.is_changed): return True + + +def _mark_nm_external_subordinate_changed(context, net_state): + """ + When certain main interface contains subordinates is marked as + connected(externally), it means its profile is memory only and will lost + on next deactivation. + For this case, we should mark the subordinate as changed. + that subordinate should be marked as changed for NM to take over. + """ + for iface in net_state.ifaces.values(): + if iface.type in MASTER_IFACE_TYPES: + for subordinate in iface.slaves: + nmdev = context.get_nm_dev(subordinate) + if nmdev: + nm_ac = nmdev.get_active_connection() + if ( + nm_ac + and NM.ActivationStateFlags.EXTERNAL + & nm_ac.get_state_flags() + ): + subordinate_iface = net_state.ifaces[subordinate] + subordinate_iface.mark_as_changed() -- 2.27.0