From 5d3c6b761b9d59ce6640d1141848eb66585795f7 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Apr 02 2024 21:06:43 +0000 Subject: Return 2 when certificates are not found during requests The ipa tool has nearly since epoch returned 2 for the case of entry not found. The certificate processing raises a separate error, CertificateOperationsError, when something goes wrong. This returns 1. With the introduction of the JSON API most requests will get a proper HTTP return code representing what went wrong. In this case we can use 404 to determine if the request resulted in a NotFound therefore can eventually return a 2 and be consistent in return values. Related: https://pagure.io/freeipa/issue/9562 Signed-off-by: Rob Crittenden Reviewed-By: Florence Blanc-Renaud --- diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py index 23667c3..78afb27 100644 --- a/ipaserver/plugins/dogtag.py +++ b/ipaserver/plugins/dogtag.py @@ -689,7 +689,7 @@ class ra(rabase.rabase, RestClient): :param err_msg: diagnostic error message, if not supplied it will be 'Unable to communicate with CMS' :param detail: extra information that will be appended to err_msg - inside a parenthesis + inside a parenthesis. This may be an HTTP status msg Raise a CertificateOperationError and log the error message. """ @@ -701,6 +701,8 @@ class ra(rabase.rabase, RestClient): err_msg = u'%s (%s)' % (err_msg, detail) logger.error('%s.%s(): %s', type(self).__name__, func_name, err_msg) + if detail == 404: + raise errors.NotFound(reason=err_msg) raise errors.CertificateOperationError(error=err_msg) def _request(self, url, port, **kw): diff --git a/ipatests/test_xmlrpc/test_cert_plugin.py b/ipatests/test_xmlrpc/test_cert_plugin.py index a0bf08d..a760937 100644 --- a/ipatests/test_xmlrpc/test_cert_plugin.py +++ b/ipatests/test_xmlrpc/test_cert_plugin.py @@ -558,6 +558,6 @@ class test_cert_remove_hold(BaseCert): def test_remove_hold_nonexistent_cert(self): # remove hold must print 'Certificate ID xx not found' - with pytest.raises(errors.CertificateOperationError, + with pytest.raises(errors.NotFound, match=r'Certificate ID 0x.* not found'): api.Command['cert_remove_hold'](9999)