Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-24 Thread David Kupka

On 11/21/2014 04:23 PM, Tomas Babej wrote:


On 11/21/2014 04:11 PM, David Kupka wrote:

https://fedorahosted.org/freeipa/ticket/4643


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


-obj.get_dn_if_exists(name)
+try:
+obj.get_dn(name)
+except errors.NotFound:
+obj.handle_not_found(*keys)

You switched from get_dn_if_exists to get_dn, why? The get_dn method
never raises the NotFound error, it just constructs the dn regardless of
the fact whether the actual entry at that dn exists.

You need to use get_dn_if_exists here. Some negative tests for this
would be welcome :).

Indeed, by testing the patch:

[tbabej@vm-218 ~]$ ipa automember_rebuild --users=doesnotexist

Automember rebuild task finished. Processed (0) entries.


Where the old behaviour was:

[tbabej@vm-218 ~]$ ipa automember_rebuild --users=test
ipa: ERROR: no such entry


Thanks for catching this Friday-afternoon brain error.
Attached patch should work as expected.

--
David Kupka
From 2799c22154808f3f5dc0d4373d87f432adfc0ac3 Mon Sep 17 00:00:00 2001
From: David Kupka dku...@redhat.com
Date: Tue, 21 Oct 2014 18:12:23 -0400
Subject: [PATCH] Fix error message for nonexistent members and add tests.

https://fedorahosted.org/freeipa/ticket/4643
---
 ipalib/plugins/automember.py   |  5 +++-
 ipatests/test_xmlrpc/test_automember_plugin.py | 35 ++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/ipalib/plugins/automember.py b/ipalib/plugins/automember.py
index 0f47393166003e04ec53c16dcd1629038127509a..0c2a246e1c24b36525f61b47878860f4056569fc 100644
--- a/ipalib/plugins/automember.py
+++ b/ipalib/plugins/automember.py
@@ -735,7 +735,10 @@ class automember_rebuild(Command):
 names = options.get(opt_name)
 if names:
 for name in names:
-obj.get_dn_if_exists(name)
+try:
+obj.get_dn_if_exists(name)
+except errors.NotFound:
+obj.handle_not_found(name)
 search_filter = ldap.make_filter_from_attr(
 obj.primary_key.name,
 names,
diff --git a/ipatests/test_xmlrpc/test_automember_plugin.py b/ipatests/test_xmlrpc/test_automember_plugin.py
index 6618ac60531ddce3e651eff16d0ce0031b9f189d..88ed334230fad254c8140e51d27f8cc47a00d405 100644
--- a/ipatests/test_xmlrpc/test_automember_plugin.py
+++ b/ipatests/test_xmlrpc/test_automember_plugin.py
@@ -30,6 +30,7 @@ from ipatests.test_xmlrpc.test_user_plugin import get_user_result
 
 
 user1 = u'tuser1'
+user_does_not_exist = u'does_not_exist'
 manager1 = u'mscott'
 fqdn1 = u'web1.%s' % api.env.domain
 short1 = u'web1'
@@ -41,6 +42,7 @@ fqdn4 = u'www5.%s' % api.env.domain
 short4 = u'www5'
 fqdn5 = u'webserver5.%s' % api.env.domain
 short5 = u'webserver5'
+fqdn_does_not_exist = u'does_not_exist.%s' % api.env.domain
 
 group1 = u'group1'
 group1_dn = DN(('cn', group1), ('cn', 'groups'),
@@ -1625,4 +1627,37 @@ class test_automember(Declarative):
 ),
 ),
 
+dict(
+desc='Rebuild membership with type hostgroup and --hosts',
+command=('automember_rebuild', [], {u'type': u'hostgroup', u'hosts': fqdn1}),
+expected=dict(
+value=None,
+summary=u'Automember rebuild task finished. Processed (1) entries.',
+result={
+}
+),
+),
+
+dict(
+desc='Rebuild membership with type group and --users',
+command=('automember_rebuild', [], {u'type': u'group', u'users': user1}),
+expected=dict(
+value=None,
+summary=u'Automember rebuild task finished. Processed (1) entries.',
+result={
+}
+),
+),
+
+dict(
+desc='Try to rebuild membership with invalid host in --hosts',
+command=('automember_rebuild', [], {u'type': u'hostgroup', u'hosts': fqdn_does_not_exist}),
+expected=errors.NotFound(reason='%s: host not found' % fqdn_does_not_exist),
+),
+
+dict(
+desc='Try to rebuild membership with invalid user in --users',
+command=('automember_rebuild', [], {u'type': u'group', u'users': user_does_not_exist}),
+expected=errors.NotFound(reason='%s: user not found' % user_does_not_exist),
+),
 ]
-- 
2.1.0

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

Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-24 Thread Tomas Babej

On 11/24/2014 01:20 PM, David Kupka wrote:
 On 11/21/2014 04:23 PM, Tomas Babej wrote:

 On 11/21/2014 04:11 PM, David Kupka wrote:
 https://fedorahosted.org/freeipa/ticket/4643


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

 -obj.get_dn_if_exists(name)
 +try:
 +obj.get_dn(name)
 +except errors.NotFound:
 +obj.handle_not_found(*keys)

 You switched from get_dn_if_exists to get_dn, why? The get_dn method
 never raises the NotFound error, it just constructs the dn regardless of
 the fact whether the actual entry at that dn exists.

 You need to use get_dn_if_exists here. Some negative tests for this
 would be welcome :).

 Indeed, by testing the patch:

 [tbabej@vm-218 ~]$ ipa automember_rebuild --users=doesnotexist
 
 Automember rebuild task finished. Processed (0) entries.
 

 Where the old behaviour was:

 [tbabej@vm-218 ~]$ ipa automember_rebuild --users=test
 ipa: ERROR: no such entry

 Thanks for catching this Friday-afternoon brain error.
 Attached patch should work as expected.


ACK, works fine.

master:
* b42b1755dcd0a681709525b4d574e12b77bbce13 webui: normalize idview tab
labels
ipa-4-1:
* 2fc53c9426ff976d4732cc1d16b1b61447cb4313 webui: normalize idview tab
labels


-- 
Tomas Babej
Associate Software Engineer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org 

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


Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-24 Thread Petr Vobornik

On 11/24/2014 04:07 PM, Tomas Babej wrote:





ACK, works fine.

master:
* b42b1755dcd0a681709525b4d574e12b77bbce13 webui: normalize idview tab
labels
ipa-4-1:
* 2fc53c9426ff976d4732cc1d16b1b61447cb4313 webui: normalize idview tab
labels



Wrong thread? Is it meant for  [PATCH] 783 webui: normalize idview tab 
labels?

--
Petr Vobornik

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


Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-24 Thread Tomas Babej

On 11/24/2014 04:15 PM, Petr Vobornik wrote:
 On 11/24/2014 04:07 PM, Tomas Babej wrote:



 ACK, works fine.

 master:
 * b42b1755dcd0a681709525b4d574e12b77bbce13 webui: normalize idview tab
 labels
 ipa-4-1:
 * 2fc53c9426ff976d4732cc1d16b1b61447cb4313 webui: normalize idview tab
 labels


 Wrong thread? Is it meant for  [PATCH] 783 webui: normalize idview
 tab labels?

Correct thread, wrong message in the clipboard. Thanks for noticing.

David's patches were pushed to:
master: 56ca47d535156122b2578ff19bc0b1a7642af40c
ipa-4-1: 192c499ef893b7118a2f7ff9f4c939a9348d5123


-- 
Tomas Babej
Associate Software Engineer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org 

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


Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-21 Thread Jan Cholasta

Hi,

Dne 21.11.2014 v 16:11 David Kupka napsal(a):

https://fedorahosted.org/freeipa/ticket/4643


You probably don't want to change get_dn_if_exists to get_dn, as the 
latter does not usually raise NotFound when the entry does not exist.


Honza

--
Jan Cholasta

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


Re: [Freeipa-devel] [PATCH] 0032 Fix error message for nonexistent members and add tests.

2014-11-21 Thread Tomas Babej

On 11/21/2014 04:11 PM, David Kupka wrote:
 https://fedorahosted.org/freeipa/ticket/4643


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

-obj.get_dn_if_exists(name)
+try:
+obj.get_dn(name)
+except errors.NotFound:
+obj.handle_not_found(*keys)

You switched from get_dn_if_exists to get_dn, why? The get_dn method
never raises the NotFound error, it just constructs the dn regardless of
the fact whether the actual entry at that dn exists.

You need to use get_dn_if_exists here. Some negative tests for this
would be welcome :).

Indeed, by testing the patch:

[tbabej@vm-218 ~]$ ipa automember_rebuild --users=doesnotexist

Automember rebuild task finished. Processed (0) entries.


Where the old behaviour was:

[tbabej@vm-218 ~]$ ipa automember_rebuild --users=test
ipa: ERROR: no such entry

-- 
Tomas Babej
Associate Software Engineer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org 

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