Blob Blame History Raw
From fb9352b902f8fec813c149e02e97c7014ef6399c Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Mon, 1 Mar 2021 16:25:57 +0100
Subject: [PATCH] nm.applier: ignore not desired unmanaged ifaces

Nmstate will ignore not desired unmanaged interfaces. If an existing
unmanaged port of a bridge is not being included in the desired state
bridge port list, it will not be removed. Basically, Nmstate will not be
able to remove unmanaged ports from a bridge.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
 libnmstate/ifaces/ifaces.py               | 11 ++++++---
 libnmstate/nm/applier.py                  | 11 ++++++++-
 tests/integration/linux_bridge_test.py    |  1 +
 tests/integration/nm/linux_bridge_test.py | 30 +++--------------------
 4 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/libnmstate/ifaces/ifaces.py b/libnmstate/ifaces/ifaces.py
index 5f1f548d..cfc306c6 100644
--- a/libnmstate/ifaces/ifaces.py
+++ b/libnmstate/ifaces/ifaces.py
@@ -193,7 +193,7 @@ class Ifaces:
         if not defiend in desire state
         """
         for iface in self._ifaces.values():
-            if iface.is_up and iface.is_master:
+            if iface.is_desired and iface.is_up and iface.is_master:
                 cur_iface = self.current_ifaces.get(iface.name)
                 for slave_name in iface.slaves:
                     if cur_iface and slave_name in cur_iface.slaves:
@@ -353,14 +353,17 @@ class Ifaces:
 
     def _remove_unknown_interface_type_slaves(self):
         """
-        When master containing slaves with unknown interface type, they should
-        be removed from master slave list before verifying.
+        When master containing slaves with unknown interface type or down
+        state, they should be removed from master slave list before verifying.
         """
         for iface in self._ifaces.values():
             if iface.is_up and iface.is_master and iface.slaves:
                 for slave_name in iface.slaves:
                     slave_iface = self._ifaces[slave_name]
-                    if slave_iface.type == InterfaceType.UNKNOWN:
+                    if (
+                        slave_iface.type == InterfaceType.UNKNOWN
+                        or slave_iface.state != InterfaceState.UP
+                    ):
                         iface.remove_slave(slave_name)
 
     def verify(self, cur_iface_infos):
diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py
index cd319ffb..da2dab5b 100644
--- a/libnmstate/nm/applier.py
+++ b/libnmstate/nm/applier.py
@@ -80,7 +80,16 @@ 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 = []
+    for iface in net_state.ifaces.all_ifaces.values():
+        nm_dev = context.get_nm_dev(iface.name)
+        if nm_dev and not nm_dev.get_managed() and not iface.is_desired:
+            # We don't change NM.Device from unmanaged to managed unless
+            # been asked explicitly in desire state
+            continue
+        if iface.is_changed or iface.is_desired:
+            ifaces_desired_state.append(iface.to_dict())
+
     ifaces_desired_state.extend(
         _create_proxy_ifaces_desired_state(ifaces_desired_state)
     )
-- 
2.29.2