From c60cec4fa7adf004d383b68b78f6fd51d5cecb21 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 27 Oct 2015 17:21:17 +0530 Subject: [PATCH] Added user friendly error message for dnszone enable and disable Added try-except block in dns plugin in order to provide user friendly message to end user. https://fedorahosted.org/freeipa/ticket/4811 Signed-off-by: Abhijeet Kasurde Reviewed-By: Martin Basti --- ipalib/plugins/dns.py | 12 ++++++++++-- ipatests/test_xmlrpc/test_dns_plugin.py | 8 ++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index ef282c946..48d6f740e 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -2231,7 +2231,11 @@ class DNSZoneBase_disable(LDAPQuery): ldap = self.obj.backend dn = self.obj.get_dn(*keys, **options) - entry = ldap.get_entry(dn, ['idnszoneactive', 'objectclass']) + try: + entry = ldap.get_entry(dn, ['idnszoneactive', 'objectclass']) + except errors.NotFound: + self.obj.handle_not_found(*keys) + if not _check_entry_objectclass(entry, self.obj.object_class): self.obj.handle_not_found(*keys) @@ -2252,7 +2256,11 @@ class DNSZoneBase_enable(LDAPQuery): ldap = self.obj.backend dn = self.obj.get_dn(*keys, **options) - entry = ldap.get_entry(dn, ['idnszoneactive', 'objectclass']) + try: + entry = ldap.get_entry(dn, ['idnszoneactive', 'objectclass']) + except errors.NotFound: + self.obj.handle_not_found(*keys) + if not _check_entry_objectclass(entry, self.obj.object_class): self.obj.handle_not_found(*keys) diff --git a/ipatests/test_xmlrpc/test_dns_plugin.py b/ipatests/test_xmlrpc/test_dns_plugin.py index f0b8edaa1..e5d1374d0 100644 --- a/ipatests/test_xmlrpc/test_dns_plugin.py +++ b/ipatests/test_xmlrpc/test_dns_plugin.py @@ -4319,7 +4319,9 @@ class test_forward_zones(Declarative): dict( desc='Try to disable non-existent forward zone', command=('dnsforwardzone_disable', [nonexistent_fwzone], {}), - expected=errors.NotFound(reason="no such entry") + expected=errors.NotFound( + reason=u'%s: DNS forward zone not found' % nonexistent_fwzone + ) ), @@ -4364,7 +4366,9 @@ class test_forward_zones(Declarative): dict( desc='Try to enable non-existent forward zone', command=('dnsforwardzone_enable', [nonexistent_fwzone], {}), - expected=errors.NotFound(reason="no such entry") + expected=errors.NotFound( + reason=u'%s: DNS forward zone not found' % nonexistent_fwzone + ) ), ]