Improve dnszone-add error message

When a new DNS record is being added to DNS zone via command
  ipa dnsrecord-add ZONE @
and the target ZONE does not exist it returns ObjectclassViolation
which may confuse users. Make sure that standard DNS Zone NotFound
exception is returned.

https://fedorahosted.org/freeipa/ticket/2270
This commit is contained in:
Martin Kosek 2012-02-02 13:40:26 +01:00
parent f411ed1e47
commit de9a0df508

View File

@ -1495,6 +1495,13 @@ class dnsrecord(LDAPObject):
def get_dn(self, *keys, **options):
if self.is_pkey_zone_record(*keys):
dn = self.api.Object[self.parent_object].get_dn(*keys[:-1], **options)
# zone must exist
ldap = self.api.Backend.ldap2
try:
(dn_, zone) = ldap.get_entry(dn, [])
except errors.NotFound:
self.api.Object['dnszone'].handle_not_found(keys[-2])
return self.api.Object[self.parent_object].get_dn(*keys[:-1], **options)
return super(dnsrecord, self).get_dn(*keys, **options)