autoland: improve duplicate request detection (bug 1377065) r?gps draft
authorbyron jones <glob@mozilla.com>
Wed, 19 Jul 2017 22:44:34 +0800
changeset 11387 5246841f8ed12e81e37c42a001e934ec14453eb8
parent 11386 584b874e4758034711c24c003b89c3565595b273
push id1734
push userbjones@mozilla.com
push dateWed, 19 Jul 2017 14:44:46 +0000
reviewersgps
bugs1377065
autoland: improve duplicate request detection (bug 1377065) r?gps Refuse to land commits that have already landed, in addition to those waiting to be landed. MozReview-Commit-ID: KomY9XaVcSI
autoland/autoland/autoland_rest.py
--- a/autoland/autoland/autoland_rest.py
+++ b/autoland/autoland/autoland_rest.py
@@ -130,30 +130,32 @@ def autoland():
         error = ('Bad request: one of trysyntax or commit_descriptions must '
                  'be specified.')
         return make_response(jsonify({'error': error}), 400)
 
     dbconn = get_dbconn()
     cursor = dbconn.cursor()
 
     query = """
-        SELECT created, request->>'ldap_username'
+        SELECT created, landed, request->>'ldap_username'
           FROM Transplant
-         WHERE landed IS NULL
+         WHERE (landed IS NULL or NOT landed)
                AND request->>'rev' = %s
                AND request->>'destination' = %s
     """
     cursor.execute(query, (request.json['rev'], request.json['destination']))
-    in_flight = cursor.fetchone()
-    if in_flight:
-        error = ('Bad request: a request to land revision %s to %s is already '
-                 'in progress'
-                 % (request.json['rev'], request.json['destination']))
+    duplicate = cursor.fetchone()
+    if duplicate:
+        if duplicate[1]:
+            message = 'revision % has already landed on %s'
+        else:
+            message = 'landing revision %s to %s is already in progress'
+        error = message % (request.json['rev'], request.json['destination'])
         app.logger.warn(
-            '%s from %s at %s' % (error, in_flight[0], in_flight[1]))
+            '%s from %s at %s' % (error, duplicate[2], duplicate[1]))
         return make_response(jsonify({'error': error}), 400)
 
     app.logger.info('received transplant request: %s' %
                     json.dumps(request.json))
 
     query = """
         insert into Transplant(destination, request)
         values (%s, %s)