Browse Source

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
changes/32/813732/2
Ian Wienand 2 months ago
parent
commit
4a52c8053a
  1. 18
      zuul/driver/gerrit/gerritconnection.py

18
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)

Loading…
Cancel
Save