From 6f125e56c66de0d275057eb485bb711751d31566 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 27 Apr 2020 17:45:36 -0700 Subject: Don't retry after Gerrit HTTP 409s Gerrit will return an HTTP status 409 when you try to modify changes that are already merged or abandoned. For example if you try to vote on a change in these closed states. In those cases we don't actually want to retry the request as doing so is a waste of effort. Update the gerritconnection drive to handle HTTP 409s as a special case that should not be retried. Change-Id: I4bd7b8e5aa512bf0ba1d1bf7dd9a39c3843e6ff6 --- zuul/driver/gerrit/gerritconnection.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index a75252ad9..0d0913789 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -48,6 +48,10 @@ from zuul.model import Ref, Tag, Branch, Project TIMEOUT = 30 +class HTTPConflictException(Exception): + message = "Received response 409" + + class GerritChangeData(object): """Compatability layer for SSH/HTTP @@ -613,7 +617,9 @@ class GerritConnection(BaseConnection): auth=self.auth, timeout=TIMEOUT, headers={'User-Agent': self.user_agent}) self.iolog.debug('Received: %s %s' % (r.status_code, r.text,)) - if r.status_code != 200: + if r.status_code == 409: + raise HTTPConflictException() + elif r.status_code != 200: raise Exception("Received response %s" % (r.status_code,)) ret = None if r.text and len(r.text) > 4: @@ -637,7 +643,9 @@ class GerritConnection(BaseConnection): headers={'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': self.user_agent}) self.iolog.debug('Received: %s %s' % (r.status_code, r.text,)) - if r.status_code != 200: + if r.status_code == 409: + raise HTTPConflictException() + elif r.status_code != 200: raise Exception("Received response %s" % (r.status_code,)) ret = None if r.text and len(r.text) > 4: @@ -1065,6 +1073,9 @@ class GerritConnection(BaseConnection): (changeid, change.commit, uuid), checkinfo) break + except HTTPConflictException: + log.exception("Conflict submitting check data to gerrit.") + break except Exception: log.exception("Error submitting check data to gerrit, " "attempt %s", x) @@ -1108,6 +1119,9 @@ class GerritConnection(BaseConnection): (changeid, change.commit), data) break + except HTTPConflictException: + log.exception("Conflict submitting data to gerrit.") + break except Exception: log.exception( "Error submitting data to gerrit, attempt %s", x) @@ -1117,6 +1131,9 @@ class GerritConnection(BaseConnection): try: self.post('changes/%s/submit' % (changeid,), {}) break + except HTTPConflictException: + log.exception("Conflict submitting data to gerrit.") + break except Exception: log.exception( "Error submitting data to gerrit, attempt %s", x) @@ -1261,7 +1278,9 @@ class GerritConnection(BaseConnection): auth=self.auth, timeout=TIMEOUT, headers={'User-Agent': self.user_agent}) self.iolog.debug('Received: %s %s' % (r.status_code, r.text,)) - if r.status_code != 200: + if r.status_code == 409: + raise HTTPConflictException() + elif r.status_code != 200: raise Exception("Received response %s" % (r.status_code,)) out = r.text[r.text.find('\n') + 5:] else: -- cgit v1.2.1