Blob Blame History Raw
From fc7e6b2329409b95ab1726b7b65f14c284bf67ab Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Mon, 3 Aug 2020 12:07:56 +0800
Subject: [PATCH] nm: Fix converting memory-only profile to persistent

When converting memory-only profile to persistent using simple desire
state with `state: up` only, the memory only profile will not be
converted to persistent.

This is caused by `nm/applier.py` skip profile creation if desire state
is only `state: up`.

The fix is checking whether current profile's persistent state is equal
to desired.

Integration test case added.

Signed-off-by: Gris Ge <fge@redhat.com>
---
 libnmstate/nm/applier.py    |  1 +
 libnmstate/nm/connection.py | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py
index 4d40862..26a057f 100644
--- a/libnmstate/nm/applier.py
+++ b/libnmstate/nm/applier.py
@@ -125,6 +125,7 @@ def apply_changes(context, net_state, save_to_disk):
                 and cur_con_profile
                 and cur_con_profile.profile
                 and not net_state.ifaces[ifname].is_changed
+                and cur_con_profile.is_memory_only != save_to_disk
             ):
                 # Don't create new profile if original desire does not ask
                 # anything besides state:up and not been marked as changed.
diff --git a/libnmstate/nm/connection.py b/libnmstate/nm/connection.py
index 5804f13..1f6c734 100644
--- a/libnmstate/nm/connection.py
+++ b/libnmstate/nm/connection.py
@@ -162,6 +162,16 @@ class ConnectionProfile:
         assert self._con_profile is None
         self._con_profile = con_profile
 
+    @property
+    def is_memory_only(self):
+        if self._con_profile:
+            profile_flags = self._con_profile.get_flags()
+            return (
+                NM.SettingsConnectionFlags.UNSAVED & profile_flags
+                or NM.SettingsConnectionFlags.VOLATILE & profile_flags
+            )
+        return False
+
     @property
     def devname(self):
         if self._con_profile:
-- 
2.28.0