Martin Kosek wrote:
On Tue, 2011-04-12 at 16:56 -0400, Rob Crittenden wrote:
Martin Kosek wrote:
On Wed, 2011-03-30 at 17:14 -0400, Rob Crittenden wrote:
Sort output on find commands based on the baseldap LDAPSearch class.
A couple tests had to be modified to match the new order.
ticket 794
rob
The patch works fine except the case when entries are being added in
post_callback. Check this search:
ipa permission-find --permissions=write
The result is not sorted. I suggest moving the sort process after the
self.POST_CALLBACKS calls.
What about performance issues? May somebody want to disable the sorting?
(e.g. --nosort option).
Martin
I think the timing would only be a problem if the sizelimit is made very
large. The amount of time with/without sorting was negligible. I think
we're safe.
rob
I agree.
What do you think about my first comment? The patch fails to sort
correctly when the entries are being added in the post_callback.
Martin
Ah right, forgot to attach updated patch.
rob
>From f921df423026fad8c1762ae6351eb1a55de5a4df Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Wed, 13 Apr 2011 10:48:07 -0400
Subject: [PATCH] Sort entries returned by *-find by the primary key (if any).
Do a server-side sort if there is a primary key.
Fix a couple of tests that were failing due to the new sorting.
ticket 794
---
ipalib/plugins/baseldap.py | 4 ++++
tests/test_xmlrpc/test_automount_plugin.py | 4 ++--
tests/test_xmlrpc/test_group_plugin.py | 12 ++++++------
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 8053b27..177b142 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1413,6 +1413,10 @@ class LDAPSearch(CallbackInterface, crud.Search):
else:
callback(self, ldap, entries, truncated, *args, **options)
+ if self.obj.primary_key:
+ sortfn=lambda x,y: cmp(x[1][self.obj.primary_key.name][0].lower(), y[1][self.obj.primary_key.name][0].lower())
+ entries.sort(sortfn)
+
if not options.get('raw', False):
for e in entries:
self.obj.convert_attribute_members(e[1], *args, **options)
diff --git a/tests/test_xmlrpc/test_automount_plugin.py b/tests/test_xmlrpc/test_automount_plugin.py
index c2fa15a..c5dd619 100644
--- a/tests/test_xmlrpc/test_automount_plugin.py
+++ b/tests/test_xmlrpc/test_automount_plugin.py
@@ -119,8 +119,8 @@ class test_automount(XMLRPC_test):
res = api.Command['automountkey_find'](self.locname, self.mapname, raw=True)['result']
assert res
assert len(res) == 2
- assert_attr_equal(res[1], 'automountkey', self.keyname)
- assert_attr_equal(res[1], 'automountinformation', self.info)
+ assert_attr_equal(res[0], 'automountkey', self.keyname)
+ assert_attr_equal(res[0], 'automountinformation', self.info)
def test_9_automountkey_mod(self):
"""
diff --git a/tests/test_xmlrpc/test_group_plugin.py b/tests/test_xmlrpc/test_group_plugin.py
index 5cb94f3..a491932 100644
--- a/tests/test_xmlrpc/test_group_plugin.py
+++ b/tests/test_xmlrpc/test_group_plugin.py
@@ -336,17 +336,17 @@ class test_group(Declarative):
'description': [u'Account administrators group'],
},
{
- 'dn': u'cn=ipausers,cn=groups,cn=accounts,%s' % api.env.basedn,
- 'gidnumber': [fuzzy_digits],
- 'cn': [u'ipausers'],
- 'description': [u'Default group for all users'],
- },
- {
'dn': u'cn=editors,cn=groups,cn=accounts,%s' % api.env.basedn,
'gidnumber': [fuzzy_digits],
'cn': [u'editors'],
'description': [u'Limited admins who can edit other users'],
},
+ {
+ 'dn': u'cn=ipausers,cn=groups,cn=accounts,%s' % api.env.basedn,
+ 'gidnumber': [fuzzy_digits],
+ 'cn': [u'ipausers'],
+ 'description': [u'Default group for all users'],
+ },
dict(
dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn),
cn=[group1],
--
1.7.4
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel