Blob Blame History Raw
From b1cb57d1dc4bba6592ba5cfc5c810a2ad19ac941 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Thu, 22 Jul 2021 18:40:50 +0800
Subject: [PATCH 2/2] nm ethtool: Preserve existing ethtool settings when
 undesired

When user does not define ethtool settings in desire state,
we should preserve existing ethtool setting.

Integration test case included.

Signed-off-by: Gris Ge <fge@redhat.com>
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
 libnmstate/nm/connection.py | 18 +++---------------
 libnmstate/nm/ethtool.py    | 26 +++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/libnmstate/nm/connection.py b/libnmstate/nm/connection.py
index 5d60f6d..5a79c6f 100644
--- a/libnmstate/nm/connection.py
+++ b/libnmstate/nm/connection.py
@@ -22,8 +22,6 @@
 import uuid
 
 from libnmstate.error import NmstatePluginError
-from libnmstate.ifaces import IfaceEthtool
-from libnmstate.schema import Ethtool
 from libnmstate.schema import Interface
 from libnmstate.schema import InterfaceType
 from libnmstate.schema import LinuxBridge as LB
@@ -240,19 +238,9 @@ def create_new_nm_simple_conn(iface, nm_profile):
     if iface.ieee_802_1x_conf:
         settings.append(create_802_1x_setting(iface.ieee_802_1x_conf))
 
-    if Ethtool.CONFIG_SUBTREE in iface.original_desire_dict:
-        iface_ethtool = IfaceEthtool(
-            iface.original_desire_dict[Ethtool.CONFIG_SUBTREE]
-        )
-        iface_ethtool.canonicalize(
-            iface.original_desire_dict[Ethtool.CONFIG_SUBTREE]
-        )
-        setting = create_ethtool_setting(
-            iface_ethtool,
-            nm_profile,
-        )
-        if setting:
-            settings.append(setting)
+    ethtool_setting = create_ethtool_setting(iface, nm_profile)
+    if ethtool_setting:
+        settings.append(ethtool_setting)
 
     nm_simple_conn = NM.SimpleConnection.new()
     for setting in settings:
diff --git a/libnmstate/nm/ethtool.py b/libnmstate/nm/ethtool.py
index 466f4f9..3cad1bf 100644
--- a/libnmstate/nm/ethtool.py
+++ b/libnmstate/nm/ethtool.py
@@ -22,6 +22,7 @@ import logging
 from .common import NM
 from .common import GLib
 
+from libnmstate.ifaces import IfaceEthtool
 from libnmstate.schema import Ethtool
 
 
@@ -59,7 +60,7 @@ _NM_COALESCE_OPT_NAME_MAP = {
 }
 
 
-def create_ethtool_setting(iface_ethtool, base_con_profile):
+def _create_ethtool_setting(iface_ethtool, base_con_profile):
     nm_setting = None
 
     if base_con_profile:
@@ -159,3 +160,26 @@ def nm_set_pause(nm_setting, autoneg, rx, tx):
         tx_value,
     )
     # pylint: enable=no-member
+
+
+def create_ethtool_setting(iface, base_con_profile):
+    if Ethtool.CONFIG_SUBTREE in iface.original_desire_dict:
+        iface_ethtool = IfaceEthtool(
+            iface.original_desire_dict[Ethtool.CONFIG_SUBTREE]
+        )
+        iface_ethtool.canonicalize(
+            iface.original_desire_dict[Ethtool.CONFIG_SUBTREE]
+        )
+        return _create_ethtool_setting(
+            iface_ethtool,
+            base_con_profile,
+        )
+    else:
+        # Preserve existing setting but not create new
+        if base_con_profile:
+            ethtool_setting = base_con_profile.get_setting_by_name(
+                NM.SETTING_ETHTOOL_SETTING_NAME
+            )
+            if ethtool_setting:
+                return ethtool_setting.duplicate()
+        return None
-- 
2.32.0