Blame SOURCES/BZ_1859844-fix_converting_memory_only.patch

97e10a
From fc7e6b2329409b95ab1726b7b65f14c284bf67ab Mon Sep 17 00:00:00 2001
97e10a
From: Gris Ge <fge@redhat.com>
97e10a
Date: Mon, 3 Aug 2020 12:07:56 +0800
97e10a
Subject: [PATCH] nm: Fix converting memory-only profile to persistent
97e10a
97e10a
When converting memory-only profile to persistent using simple desire
97e10a
state with `state: up` only, the memory only profile will not be
97e10a
converted to persistent.
97e10a
97e10a
This is caused by `nm/applier.py` skip profile creation if desire state
97e10a
is only `state: up`.
97e10a
97e10a
The fix is checking whether current profile's persistent state is equal
97e10a
to desired.
97e10a
97e10a
Integration test case added.
97e10a
97e10a
Signed-off-by: Gris Ge <fge@redhat.com>
97e10a
---
97e10a
 libnmstate/nm/applier.py    |  1 +
97e10a
 libnmstate/nm/connection.py | 10 ++++++++++
97e10a
 2 files changed, 11 insertions(+)
97e10a
97e10a
diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py
97e10a
index 4d40862..26a057f 100644
97e10a
--- a/libnmstate/nm/applier.py
97e10a
+++ b/libnmstate/nm/applier.py
97e10a
@@ -125,6 +125,7 @@ def apply_changes(context, net_state, save_to_disk):
97e10a
                 and cur_con_profile
97e10a
                 and cur_con_profile.profile
97e10a
                 and not net_state.ifaces[ifname].is_changed
97e10a
+                and cur_con_profile.is_memory_only != save_to_disk
97e10a
             ):
97e10a
                 # Don't create new profile if original desire does not ask
97e10a
                 # anything besides state:up and not been marked as changed.
97e10a
diff --git a/libnmstate/nm/connection.py b/libnmstate/nm/connection.py
97e10a
index 5804f13..1f6c734 100644
97e10a
--- a/libnmstate/nm/connection.py
97e10a
+++ b/libnmstate/nm/connection.py
97e10a
@@ -162,6 +162,16 @@ class ConnectionProfile:
97e10a
         assert self._con_profile is None
97e10a
         self._con_profile = con_profile
97e10a
 
97e10a
+    @property
97e10a
+    def is_memory_only(self):
97e10a
+        if self._con_profile:
97e10a
+            profile_flags = self._con_profile.get_flags()
97e10a
+            return (
97e10a
+                NM.SettingsConnectionFlags.UNSAVED & profile_flags
97e10a
+                or NM.SettingsConnectionFlags.VOLATILE & profile_flags
97e10a
+            )
97e10a
+        return False
97e10a
+
97e10a
     @property
97e10a
     def devname(self):
97e10a
         if self._con_profile:
97e10a
-- 
97e10a
2.28.0
97e10a