From 013860d2576a34a277178e6afba0935498dc4f72 Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Wed, 3 Feb 2021 11:59:05 +0100
Subject: [PATCH] connection: retry on profile activation if libnm error
happened
When activating a profile if NetworkManager fails during the activation,
Nmstate should retry it once.
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
libnmstate/nm/connection.py | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/libnmstate/nm/connection.py b/libnmstate/nm/connection.py
index 5b9a3aee2..45cb69019 100644
--- a/libnmstate/nm/connection.py
+++ b/libnmstate/nm/connection.py
@@ -180,7 +180,8 @@ def activate(self):
"BUG: Cannot activate a profile with empty profile id and "
"empty NM.Device"
)
- user_data = action
+ retry = True
+ user_data = action, retry
self._ctx.register_async(action)
self._ctx.client.activate_connection_async(
self.profile,
@@ -267,7 +268,7 @@ def _active_connection_callback(self, src_object, result, user_data):
if self._ctx.is_cancelled():
self._activation_clean_up()
return
- action = user_data
+ action, retry = user_data
try:
nm_act_con = src_object.activate_connection_finish(result)
@@ -279,6 +280,20 @@ def _active_connection_callback(self, src_object, result, user_data):
)
return
else:
+ if retry:
+ retry = False
+ user_data = action, retry
+ specific_object = None
+ logging.debug(f"Action {action} failed, trying again.")
+ self._ctx.client.activate_connection_async(
+ self.profile,
+ self.nmdevice,
+ specific_object,
+ self._ctx.cancellable,
+ self._active_connection_callback,
+ user_data,
+ )
+ return
self._ctx.fail(
NmstateLibnmError(f"{action} failed: error={e}")
)