Blame SOURCES/BZ_2080530-python-bridge-clear-vlan-filtering-when-set-empty.patch

d3f050
From bc677dc4f356a89a9af5cf45e80d31afff44c6d7 Mon Sep 17 00:00:00 2001
d3f050
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
d3f050
Date: Fri, 25 Mar 2022 13:27:16 +0100
d3f050
Subject: [PATCH] python, bridge: clear vlan filtering when set empty
d3f050
d3f050
When the user specifies 'vlan: {}', Nmstate should clear the vlan
d3f050
configuration for that port instead of merging it.
d3f050
d3f050
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
d3f050
(cherry picked from commit 8b87c7d533dfb568f9a1715d7b2c59c415c9470a)
d3f050
---
d3f050
 libnmstate/ifaces/linux_bridge.py | 23 +++++++++++++++++++++++
d3f050
 1 file changed, 23 insertions(+)
d3f050
d3f050
diff --git a/libnmstate/ifaces/linux_bridge.py b/libnmstate/ifaces/linux_bridge.py
d3f050
index ce331692..950e8c9e 100644
d3f050
--- a/libnmstate/ifaces/linux_bridge.py
d3f050
+++ b/libnmstate/ifaces/linux_bridge.py
d3f050
@@ -124,15 +124,38 @@ class LinuxBridgeIface(BridgeIface):
d3f050
     def gen_metadata(self, ifaces):
d3f050
         super().gen_metadata(ifaces)
d3f050
         if not self.is_absent:
d3f050
+            original_ports_config = self.original_desire_dict.get(
d3f050
+                LinuxBridge.CONFIG_SUBTREE, {}
d3f050
+            ).get(LinuxBridge.PORT_SUBTREE, [])
d3f050
             for port_config in self.port_configs:
d3f050
                 port_iface = ifaces.all_kernel_ifaces.get(
d3f050
                     port_config[LinuxBridge.Port.NAME]
d3f050
                 )
d3f050
                 if port_iface:
d3f050
+                    original_port = self._get_port_config(
d3f050
+                        original_ports_config, port_iface.name
d3f050
+                    )
d3f050
+                    if (
d3f050
+                        original_port
d3f050
+                        and original_port.get(
d3f050
+                            LinuxBridge.Port.VLAN_SUBTREE, None
d3f050
+                        )
d3f050
+                        == {}
d3f050
+                    ):
d3f050
+                        port_config[
d3f050
+                            LinuxBridge.Port.VLAN_SUBTREE
d3f050
+                        ] = original_port.get(LinuxBridge.Port.VLAN_SUBTREE)
d3f050
                     port_iface.update(
d3f050
                         {BridgeIface.BRPORT_OPTIONS_METADATA: port_config}
d3f050
                     )
d3f050
 
d3f050
+    def _get_port_config(self, ports, port_name):
d3f050
+        for port_config in ports:
d3f050
+            if port_config[LinuxBridge.Port.NAME] == port_name:
d3f050
+                return port_config
d3f050
+
d3f050
+        return None
d3f050
+
d3f050
     def remove_port(self, port_name):
d3f050
         if self._bridge_config:
d3f050
             self.raw[LinuxBridge.CONFIG_SUBTREE][LinuxBridge.PORT_SUBTREE] = [
d3f050
-- 
d3f050
2.35.1
d3f050