dc4945
From 90933d8e0f4fe1d5793ead4f251c1b3f08e25b71 Mon Sep 17 00:00:00 2001
dc4945
From: Florence Blanc-Renaud <flo@redhat.com>
dc4945
Date: Wed, 3 Jun 2020 11:42:27 +0200
dc4945
Subject: [PATCH] ipa-adtrust-install: avoid failure when replica is offline
dc4945
dc4945
When ipa-adtrust-install --add-agents fails to connect to the
dc4945
replica (for instance because services are stopped on the replica),
dc4945
it should not exit on error but rather print an error message.
dc4945
dc4945
The issue happens because of python2/python3 differences in the
dc4945
returned exceptions. As ipa-4-6 branch also supports python2,
dc4945
a socket.error exception is raised when the connection fails and
dc4945
must be properly caught.
dc4945
dc4945
In python2, socket.error inherits from IOError.
dc4945
In python3, ConnectionRefusedError inherits from OSError, and
dc4945
IOError is an alias for OSError.
dc4945
dc4945
Fixes: https://pagure.io/freeipa/issue/8345
dc4945
Reviewed-By: Francois Cami <fcami@redhat.com>
dc4945
---
dc4945
 ipaserver/install/adtrust.py | 11 +----------
dc4945
 1 file changed, 1 insertion(+), 10 deletions(-)
dc4945
dc4945
diff --git a/ipaserver/install/adtrust.py b/ipaserver/install/adtrust.py
dc4945
index be7cc34613fe486b4f36088da7f7a63a0fa78a24..a2cbf07185cb9edc8bc6b86dc51bd784ed3e5dc0 100644
dc4945
--- a/ipaserver/install/adtrust.py
dc4945
+++ b/ipaserver/install/adtrust.py
dc4945
@@ -8,7 +8,6 @@ AD trust installer module
dc4945
 
dc4945
 from __future__ import print_function, absolute_import
dc4945
 
dc4945
-import errno
dc4945
 import logging
dc4945
 import os
dc4945
 
dc4945
@@ -375,19 +374,11 @@ def add_new_adtrust_agents(api, options):
dc4945
                     "Remote server %s does not support agent enablement "
dc4945
                     "over RPC: %s", agent, e)
dc4945
                 failed_agents.append(agent)
dc4945
-            except errors.PublicError as e:
dc4945
+            except (errors.PublicError, IOError) as e:
dc4945
                 logger.debug(
dc4945
                     "Remote call to trust_enable_agent failed on server %s: "
dc4945
                     "%s", agent, e)
dc4945
                 failed_agents.append(agent)
dc4945
-            except OSError as e:
dc4945
-                if e.errno == errno.ECONNREFUSED:
dc4945
-                    logger.debug(
dc4945
-                        "Remote call to trust_enable_agent failed on "
dc4945
-                        "server %s: %s", agent, e)
dc4945
-                    failed_agents.append(agent)
dc4945
-                else:
dc4945
-                    raise
dc4945
             else:
dc4945
                 for message in result.get('messages'):
dc4945
                     logger.debug('%s', message['message'])
dc4945
-- 
dc4945
2.25.4
dc4945