ipa host-add: do not raise exception when reverse record not added

When ipa host-add --random is unable to add a reverse record (for instance
because the server does not manage any reverse zone), the command
adds the host but exits (return code=1) with an error without actually
outputing the random password generated.
With this fix, the behavior is modified. The commands succeeds (return code=0)
but prints a warning.

This commit also adds a unit test.

https://pagure.io/freeipa/issue/7374

Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Florence Blanc-Renaud
2018-02-23 14:39:34 +01:00
committed by Christian Heimes
parent 642712f9c4
commit 4295df17a4
3 changed files with 49 additions and 14 deletions
+3 -7
View File
@@ -700,7 +700,6 @@ class host_add(LDAPCreate):
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
assert isinstance(dn, DN)
exc = None
if dns_container_exists(ldap):
try:
parts = keys[-1].split('.')
@@ -719,18 +718,15 @@ class host_add(LDAPCreate):
update_sshfp_record(domain, unicode(parts[0]), entry_attrs)
except Exception as e:
exc = e
self.add_message(messages.FailedToAddHostDNSRecords(reason=e))
if options.get('random', False):
try:
entry_attrs['randompassword'] = unicode(getattr(context, 'randompassword'))
entry_attrs['randompassword'] = unicode(
getattr(context, 'randompassword'))
except AttributeError:
# On the off-chance some other extension deletes this from the
# context, don't crash.
pass
if exc:
raise errors.NonFatalError(
reason=_('The host was added but the DNS update failed with: %(exc)s') % dict(exc=exc)
)
set_certificate_attrs(entry_attrs)
set_kerberos_attrs(entry_attrs, options)
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)