nmstate/SOURCES/BZ_1820009_only_reapply_if_activated.patch
2021-10-08 14:04:54 +00:00

64 lines
1.8 KiB
Diff

From 26ca4e3a1a96829ca115f436872d4a575490cce6 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Wed, 24 Jun 2020 15:27:42 +0800
Subject: [PATCH] nm/device: Only invoke reapply on activated device
Only invoke `NM.Device.reapply_async()` on activated device.
Signed-off-by: Gris Ge <fge@redhat.com>
---
libnmstate/nm/device.py | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/libnmstate/nm/device.py b/libnmstate/nm/device.py
index 92447b0..528f57d 100644
--- a/libnmstate/nm/device.py
+++ b/libnmstate/nm/device.py
@@ -53,25 +53,29 @@ def delete(context, dev):
con_profile.delete()
-def modify(context, dev, connection_profile):
+def modify(context, nm_dev, connection_profile):
"""
Modify the given connection profile on the device.
Implemented by the reapply operation with a fallback to the
connection profile activation.
"""
- version_id = 0
- flags = 0
- action = f"Reapply device config: {dev.get_iface()}"
- context.register_async(action)
- user_data = context, dev, action
- dev.reapply_async(
- connection_profile,
- version_id,
- flags,
- context.cancellable,
- _modify_callback,
- user_data,
- )
+ nm_ac = nm_dev.get_active_connection()
+ if connection.is_activated(nm_ac, nm_dev):
+ version_id = 0
+ flags = 0
+ action = f"Reapply device config: {nm_dev.get_iface()}"
+ context.register_async(action)
+ user_data = context, nm_dev, action
+ nm_dev.reapply_async(
+ connection_profile,
+ version_id,
+ flags,
+ context.cancellable,
+ _modify_callback,
+ user_data,
+ )
+ else:
+ _activate_async(context, nm_dev)
def _modify_callback(src_object, result, user_data):
--
2.27.0