Blob Blame History Raw
From bc2f8445d493f8a5a4ff1ceead13d2b3ac5325cc Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Sun, 26 Jul 2020 00:46:16 +0200
Subject: [PATCH 1/2] nm.wired: do not report MTU if it is 0

If an interface contains an MTU with value 0, Nmstate should not report
it because it is an special interface like OVS patch port interfaces.

Added a test case for this.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
 libnmstate/nm/wired.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libnmstate/nm/wired.py b/libnmstate/nm/wired.py
index 27d4318..64662ac 100644
--- a/libnmstate/nm/wired.py
+++ b/libnmstate/nm/wired.py
@@ -124,7 +124,9 @@ def get_info(device):
 
     iface = device.get_iface()
     try:
-        info[Interface.MTU] = int(device.get_mtu())
+        mtu = int(device.get_mtu())
+        if mtu:
+            info[Interface.MTU] = mtu
     except AttributeError:
         pass
 
-- 
2.27.0


From 03aea7d7debfca0f01b60e9f406c9acdf3de3775 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Mon, 27 Jul 2020 20:51:53 +0800
Subject: [PATCH 2/2] nm ovs: Raise NmstateNotSupportedError for
 save_to_disk=False

Due to limitation of NetworkManager 1.26, nmstate cannot support
`save_to_disk=False`(ask, memory only) state for OVS interfaces.

Raise NmstateNotSupportedError if NetworkManager version is older than
1.28 and has OVS interface in desire state with `save_to_disk=False`.

Integration test case included.

Signed-off-by: Gris Ge <fge@redhat.com>
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
 libnmstate/nm/applier.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py
index 4e20af5..a91cee5 100644
--- a/libnmstate/nm/applier.py
+++ b/libnmstate/nm/applier.py
@@ -17,9 +17,11 @@
 # along with this program. If not, see <https://www.gnu.org/licenses/>.
 #
 
+from distutils.version import StrictVersion
 import logging
 import itertools
 
+from libnmstate.error import NmstateNotSupportedError
 from libnmstate.error import NmstateValueError
 from libnmstate.schema import Interface
 from libnmstate.schema import InterfaceState
@@ -65,6 +67,17 @@ MASTER_IFACE_TYPES = (
 def apply_changes(context, net_state, save_to_disk):
     con_profiles = []
 
+    if (
+        not save_to_disk
+        and _has_ovs_interface_desired_or_changed(net_state)
+        and StrictVersion(context.client.get_version())
+        < StrictVersion("1.28.0")
+    ):
+        raise NmstateNotSupportedError(
+            f"NetworkManager version {context.client.get_version()} does not "
+            f"support 'save_to_disk=False' against OpenvSwitch interface"
+        )
+
     _preapply_dns_fix(context, net_state)
 
     ifaces_desired_state = net_state.ifaces.state_to_edit
@@ -602,3 +615,13 @@ def _preapply_dns_fix(context, net_state):
         for iface in net_state.ifaces.values():
             if iface.is_changed or iface.is_desired:
                 iface.remove_dns_metadata()
+
+
+def _has_ovs_interface_desired_or_changed(net_state):
+    for iface in net_state.ifaces.values():
+        if iface.type in (
+            InterfaceType.OVS_BRIDGE,
+            InterfaceType.OVS_INTERFACE,
+            InterfaceType.OVS_PORT,
+        ) and (iface.is_desired or iface.is_changed):
+            return True
-- 
2.27.0