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
This commit is contained in:
Ian Wienand 2021-10-13 09:02:20 +11:00
parent a32753227b
commit 4a52c8053a
1 changed files with 18 additions and 0 deletions

View File

@ -57,6 +57,10 @@ class HTTPConflictException(Exception):
message = "Received response 409" message = "Received response 409"
class HTTPBadRequestException(Exception):
pass
class GerritChangeCache(AbstractChangeCache): class GerritChangeCache(AbstractChangeCache):
log = logging.getLogger("zuul.driver.GerritChangeCache") 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,)) self.iolog.debug('Received: %s %s' % (r.status_code, r.text,))
if r.status_code == 409: if r.status_code == 409:
raise HTTPConflictException() raise HTTPConflictException()
if r.status_code == 400:
raise HTTPBadRequestException('Received response 400: %s' % r.text)
elif r.status_code != 200: elif r.status_code != 200:
raise Exception("Received response %s" % (r.status_code,)) raise Exception("Received response %s" % (r.status_code,))
ret = None ret = None
@ -1188,6 +1194,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection):
except HTTPConflictException: except HTTPConflictException:
log.exception("Conflict submitting check data to gerrit.") log.exception("Conflict submitting check data to gerrit.")
break break
except HTTPBadRequestException:
log.exception(
"Bad request submitting check data to gerrit.")
break
except Exception: except Exception:
log.exception("Error submitting check data to gerrit, " log.exception("Error submitting check data to gerrit, "
"attempt %s", x) "attempt %s", x)
@ -1235,6 +1245,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection):
except HTTPConflictException: except HTTPConflictException:
log.exception("Conflict submitting data to gerrit.") log.exception("Conflict submitting data to gerrit.")
break break
except HTTPBadRequestException:
log.exception(
"Bad request submitting check data to gerrit.")
break
except Exception: except Exception:
log.exception( log.exception(
"Error submitting data to gerrit, attempt %s", x) "Error submitting data to gerrit, attempt %s", x)
@ -1247,6 +1261,10 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection):
except HTTPConflictException: except HTTPConflictException:
log.exception("Conflict submitting data to gerrit.") log.exception("Conflict submitting data to gerrit.")
break break
except HTTPBadRequestException:
log.exception(
"Bad request submitting check data to gerrit.")
break
except Exception: except Exception:
log.exception( log.exception(
"Error submitting data to gerrit, attempt %s", x) "Error submitting data to gerrit, attempt %s", x)