|
|
dad7e0 |
From 3c5337a22273717df6fb51818216816bbff77035 Mon Sep 17 00:00:00 2001
|
|
|
dad7e0 |
From: Gris Ge <fge@redhat.com>
|
|
|
dad7e0 |
Date: Thu, 30 Jul 2020 16:54:40 +0800
|
|
|
dad7e0 |
Subject: [PATCH] nm profile: Remove inactivate profile of desired interface
|
|
|
dad7e0 |
|
|
|
dad7e0 |
For changed/desired interface, NM should remove all its inactive
|
|
|
dad7e0 |
profiles so that it could update and activate the same one.
|
|
|
dad7e0 |
|
|
|
dad7e0 |
Integration test case included.
|
|
|
dad7e0 |
|
|
|
dad7e0 |
Signed-off-by: Gris Ge <fge@redhat.com>
|
|
|
dad7e0 |
---
|
|
|
dad7e0 |
libnmstate/nm/applier.py | 10 +++++++++-
|
|
|
dad7e0 |
libnmstate/nm/connection.py | 9 +++++++--
|
|
|
dad7e0 |
2 files changed, 16 insertions(+), 3 deletions(-)
|
|
|
dad7e0 |
|
|
|
dad7e0 |
diff --git a/libnmstate/nm/applier.py b/libnmstate/nm/applier.py
|
|
|
dad7e0 |
index 9cd8f9a..4d40862 100644
|
|
|
dad7e0 |
--- a/libnmstate/nm/applier.py
|
|
|
dad7e0 |
+++ b/libnmstate/nm/applier.py
|
|
|
dad7e0 |
@@ -105,6 +105,15 @@ def apply_changes(context, net_state, save_to_disk):
|
|
|
dad7e0 |
cur_con_profile = connection.ConnectionProfile(
|
|
|
dad7e0 |
context, profile=con_profile
|
|
|
dad7e0 |
)
|
|
|
dad7e0 |
+
|
|
|
dad7e0 |
+ if save_to_disk:
|
|
|
dad7e0 |
+ # TODO: Need handle save_to_disk=False
|
|
|
dad7e0 |
+ connection.delete_iface_profiles_except(
|
|
|
dad7e0 |
+ context,
|
|
|
dad7e0 |
+ ifname,
|
|
|
dad7e0 |
+ cur_con_profile.profile if cur_con_profile else None,
|
|
|
dad7e0 |
+ )
|
|
|
dad7e0 |
+
|
|
|
dad7e0 |
original_desired_iface_state = {}
|
|
|
dad7e0 |
if net_state.ifaces.get(ifname):
|
|
|
dad7e0 |
iface = net_state.ifaces[ifname]
|
|
|
dad7e0 |
@@ -137,7 +146,6 @@ def apply_changes(context, net_state, save_to_disk):
|
|
|
dad7e0 |
con_profiles.append(new_con_profile)
|
|
|
dad7e0 |
else:
|
|
|
dad7e0 |
# Missing connection, attempting to create a new one.
|
|
|
dad7e0 |
- connection.delete_iface_inactive_connections(context, ifname)
|
|
|
dad7e0 |
new_con_profile.add(save_to_disk)
|
|
|
dad7e0 |
con_profiles.append(new_con_profile)
|
|
|
dad7e0 |
context.wait_all_finish()
|
|
|
dad7e0 |
diff --git a/libnmstate/nm/connection.py b/libnmstate/nm/connection.py
|
|
|
dad7e0 |
index 02890bc..5804f13 100644
|
|
|
dad7e0 |
--- a/libnmstate/nm/connection.py
|
|
|
dad7e0 |
+++ b/libnmstate/nm/connection.py
|
|
|
dad7e0 |
@@ -496,9 +496,14 @@ def get_device_active_connection(nm_device):
|
|
|
dad7e0 |
return active_conn
|
|
|
dad7e0 |
|
|
|
dad7e0 |
|
|
|
dad7e0 |
-def delete_iface_inactive_connections(context, ifname):
|
|
|
dad7e0 |
+def delete_iface_profiles_except(context, ifname, excluded_profile):
|
|
|
dad7e0 |
for con in list_connections_by_ifname(context, ifname):
|
|
|
dad7e0 |
- con.delete()
|
|
|
dad7e0 |
+ if (
|
|
|
dad7e0 |
+ not excluded_profile
|
|
|
dad7e0 |
+ or not con.profile
|
|
|
dad7e0 |
+ or con.profile.get_uuid() != excluded_profile.get_uuid()
|
|
|
dad7e0 |
+ ):
|
|
|
dad7e0 |
+ con.delete()
|
|
|
dad7e0 |
|
|
|
dad7e0 |
|
|
|
dad7e0 |
def list_connections_by_ifname(context, ifname):
|
|
|
dad7e0 |
--
|
|
|
dad7e0 |
2.28.0
|
|
|
dad7e0 |
|