Blob Blame History Raw
From 90933d8e0f4fe1d5793ead4f251c1b3f08e25b71 Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <flo@redhat.com>
Date: Wed, 3 Jun 2020 11:42:27 +0200
Subject: [PATCH] ipa-adtrust-install: avoid failure when replica is offline

When ipa-adtrust-install --add-agents fails to connect to the
replica (for instance because services are stopped on the replica),
it should not exit on error but rather print an error message.

The issue happens because of python2/python3 differences in the
returned exceptions. As ipa-4-6 branch also supports python2,
a socket.error exception is raised when the connection fails and
must be properly caught.

In python2, socket.error inherits from IOError.
In python3, ConnectionRefusedError inherits from OSError, and
IOError is an alias for OSError.

Fixes: https://pagure.io/freeipa/issue/8345
Reviewed-By: Francois Cami <fcami@redhat.com>
---
 ipaserver/install/adtrust.py | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/ipaserver/install/adtrust.py b/ipaserver/install/adtrust.py
index be7cc34613fe486b4f36088da7f7a63a0fa78a24..a2cbf07185cb9edc8bc6b86dc51bd784ed3e5dc0 100644
--- a/ipaserver/install/adtrust.py
+++ b/ipaserver/install/adtrust.py
@@ -8,7 +8,6 @@ AD trust installer module
 
 from __future__ import print_function, absolute_import
 
-import errno
 import logging
 import os
 
@@ -375,19 +374,11 @@ def add_new_adtrust_agents(api, options):
                     "Remote server %s does not support agent enablement "
                     "over RPC: %s", agent, e)
                 failed_agents.append(agent)
-            except errors.PublicError as e:
+            except (errors.PublicError, IOError) as e:
                 logger.debug(
                     "Remote call to trust_enable_agent failed on server %s: "
                     "%s", agent, e)
                 failed_agents.append(agent)
-            except OSError as e:
-                if e.errno == errno.ECONNREFUSED:
-                    logger.debug(
-                        "Remote call to trust_enable_agent failed on "
-                        "server %s: %s", agent, e)
-                    failed_agents.append(agent)
-                else:
-                    raise
             else:
                 for message in result.get('messages'):
                     logger.debug('%s', message['message'])
-- 
2.25.4