57b990
From 528a21996734467be193673e4f987e7e3acc3ad9 Mon Sep 17 00:00:00 2001
57b990
From: Alexander Bokovoy <abokovoy@redhat.com>
57b990
Date: Sat, 11 May 2019 11:54:40 +0300
57b990
Subject: [PATCH] upgrade: adtrust - catch empty result when retrieving list of
57b990
 trusts
57b990
57b990
Upgrade failure when ipa-server-upgrade is being run on a system with no
57b990
trust established but trust configured
57b990
57b990
Fixes: https://pagure.io/freeipa/issue/7939
57b990
---
57b990
 ipaserver/install/plugins/adtrust.py | 16 +++++++++++-----
57b990
 1 file changed, 11 insertions(+), 5 deletions(-)
57b990
57b990
diff --git a/ipaserver/install/plugins/adtrust.py b/ipaserver/install/plugins/adtrust.py
57b990
index 6b4e2caa2..cdc3a8b04 100644
57b990
--- a/ipaserver/install/plugins/adtrust.py
57b990
+++ b/ipaserver/install/plugins/adtrust.py
57b990
@@ -609,11 +609,17 @@ class update_tdo_to_new_layout(Updater):
57b990
 
57b990
         trusts_dn = self.api.env.container_adtrusts + self.api.env.basedn
57b990
 
57b990
-        trusts = ldap.get_entries(
57b990
-            base_dn=trusts_dn,
57b990
-            scope=ldap.SCOPE_ONELEVEL,
57b990
-            filter=self.trust_filter,
57b990
-            attrs_list=self.trust_attrs)
57b990
+        # We might be in a situation when no trusts exist yet
57b990
+        # In such case there is nothing to upgrade but we have to catch
57b990
+        # an exception or it will abort the whole upgrade process
57b990
+        try:
57b990
+            trusts = ldap.get_entries(
57b990
+                base_dn=trusts_dn,
57b990
+                scope=ldap.SCOPE_ONELEVEL,
57b990
+                filter=self.trust_filter,
57b990
+                attrs_list=self.trust_attrs)
57b990
+        except errors.EmptyResult:
57b990
+            trusts = []
57b990
 
57b990
         # For every trust, retrieve its principals and convert
57b990
         for t_entry in trusts:
57b990
-- 
57b990
2.21.0
57b990