From 4a52c8053a633d37b609be79e34115f82fed982c Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 13 Oct 2021 09:02:20 +1100 Subject: [PATCH] gerrit: handle POST 400 errors and don't retry A 400 response from Gerrit indicates that we sent something bad, or that something failed validation, etc. It is not going to disappear with retries. Thus this catches 400 separately on POST requests and stops any retry loops. The response also returns some text telling you what is wrong; log that in the exception (it is logged at the zuul.GerritConnection.io logger, but that is usually set high to avoid too much log traffic). Change-Id: I6a470bf338cf8b9944760c89d5742c79318c7cb8 --- zuul/driver/gerrit/gerritconnection.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index ef0b9c39fb..1db8b4ec2a 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -57,6 +57,10 @@ class HTTPConflictException(Exception): message = "Received response 409" +class HTTPBadRequestException(Exception): + pass + + class GerritChangeCache(AbstractChangeCache): log = logging.getLogger("zuul.driver.GerritChangeCache") @@ -713,6 +717,8 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): self.iolog.debug('Received: %s %s' % (r.status_code, r.text,)) if r.status_code == 409: raise HTTPConflictException() + if r.status_code == 400: + raise HTTPBadRequestException('Received response 400: %s' % r.text) elif r.status_code != 200: raise Exception("Received response %s" % (r.status_code,)) ret = None @@ -1188,6 +1194,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): except HTTPConflictException: log.exception("Conflict submitting check data to gerrit.") break + except HTTPBadRequestException: + log.exception( + "Bad request submitting check data to gerrit.") + break except Exception: log.exception("Error submitting check data to gerrit, " "attempt %s", x) @@ -1235,6 +1245,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): except HTTPConflictException: log.exception("Conflict submitting data to gerrit.") break + except HTTPBadRequestException: + log.exception( + "Bad request submitting check data to gerrit.") + break except Exception: log.exception( "Error submitting data to gerrit, attempt %s", x) @@ -1247,6 +1261,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): except HTTPConflictException: log.exception("Conflict submitting data to gerrit.") break + except HTTPBadRequestException: + log.exception( + "Bad request submitting check data to gerrit.") + break except Exception: log.exception( "Error submitting data to gerrit, attempt %s", x)