While messing with the ipa-ldap-updater, I found the order method was using an algorithm that could give incorrect results. I'm submitting a fix in an extra patch, as it's largely unrelated and shouldn't be so controversial.

--
PetrĀ³
From 02f7f2006d81bebb788d97853b09a9efd3b49427 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Wed, 30 May 2012 08:03:49 -0400
Subject: [PATCH] Fix update plugin order

Sort a filtered list in the update plugin ordering method.

Unlike the previous algorithm, this always gives a correct order.
It should also be faster and more readable.
---
 ipaserver/install/plugins/updateclient.py |   20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/ipaserver/install/plugins/updateclient.py b/ipaserver/install/plugins/updateclient.py
index 8f463fa693ad46d2630e92373ac3b1dee4844ed5..b566d19e7959f6567443ab3093e3a3213022fe34 100644
--- a/ipaserver/install/plugins/updateclient.py
+++ b/ipaserver/install/plugins/updateclient.py
@@ -106,22 +106,12 @@ def create_context(self, dm_password):
         self.Backend.ldap2.connect(bind_dn='cn=Directory Manager', bind_pw=dm_password, autobind=autobind)
 
     def order(self, updatetype):
+        """Return plugins of the given updatetype in sorted order.
         """
-        Calculate rough order of plugins.
-        """
-        order = []
-        for plugin in api.Updater(): #pylint: disable=E1101
-            if plugin.updatetype != updatetype:
-                continue
-            if plugin.order == FIRST:
-                order.insert(0, plugin)
-            elif plugin.order == MIDDLE:
-                order.insert(len(order)/2, plugin)
-            else:
-                order.append(plugin)
-
-        for o in order:
-            yield o
+        ordered = [plugin for plugin in api.Updater()  # pylint: disable=E1101
+                   if plugin.updatetype == updatetype]
+        ordered.sort(key=lambda p: p.order)
+        return ordered
 
     def update(self, updatetype, dm_password, ldapi, live_run):
         """
-- 
1.7.10.2

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to