86baa9
From dfb08e295420a9ea92776fa99cd1b7fe6a6badaa Mon Sep 17 00:00:00 2001
86baa9
From: Alexander Bokovoy <abokovoy@redhat.com>
86baa9
Date: Sat, 11 May 2019 11:54:40 +0300
86baa9
Subject: [PATCH] upgrade: adtrust - catch empty result when retrieving list of
86baa9
 trusts
86baa9
MIME-Version: 1.0
86baa9
Content-Type: text/plain; charset=UTF-8
86baa9
Content-Transfer-Encoding: 8bit
86baa9
86baa9
Upgrade failure when ipa-server-upgrade is being run on a system with no
86baa9
trust established but trust configured
86baa9
86baa9
Fixes: https://pagure.io/freeipa/issue/7939
86baa9
Reviewed-By: François Cami <fcami@redhat.com>
86baa9
---
86baa9
 ipaserver/install/plugins/adtrust.py | 16 +++++++++++-----
86baa9
 1 file changed, 11 insertions(+), 5 deletions(-)
86baa9
86baa9
diff --git a/ipaserver/install/plugins/adtrust.py b/ipaserver/install/plugins/adtrust.py
86baa9
index 1461e000dc855a21665eb5ea0cfe4a47df419344..55df5cd01fd0f585d5955e700ccf20c7fc9a747f 100644
86baa9
--- a/ipaserver/install/plugins/adtrust.py
86baa9
+++ b/ipaserver/install/plugins/adtrust.py
86baa9
@@ -610,11 +610,17 @@ class update_tdo_to_new_layout(Updater):
86baa9
 
86baa9
         trusts_dn = self.api.env.container_adtrusts + self.api.env.basedn
86baa9
 
86baa9
-        trusts = ldap.get_entries(
86baa9
-            base_dn=trusts_dn,
86baa9
-            scope=ldap.SCOPE_ONELEVEL,
86baa9
-            filter=self.trust_filter,
86baa9
-            attrs_list=self.trust_attrs)
86baa9
+        # We might be in a situation when no trusts exist yet
86baa9
+        # In such case there is nothing to upgrade but we have to catch
86baa9
+        # an exception or it will abort the whole upgrade process
86baa9
+        try:
86baa9
+            trusts = ldap.get_entries(
86baa9
+                base_dn=trusts_dn,
86baa9
+                scope=ldap.SCOPE_ONELEVEL,
86baa9
+                filter=self.trust_filter,
86baa9
+                attrs_list=self.trust_attrs)
86baa9
+        except errors.EmptyResult:
86baa9
+            trusts = []
86baa9
 
86baa9
         # For every trust, retrieve its principals and convert
86baa9
         for t_entry in trusts:
86baa9
-- 
86baa9
2.20.1
86baa9