autoland: accept and store patch based requests (bug 1368516) r?smacleod draft
authorbyron jones <glob@mozilla.com>
Wed, 26 Jul 2017 13:34:37 +0800
changeset 11683 0ac9ae8c1e3f0b9ea58589504b6c4baeea8baeb2
parent 11682 602f2d837a3b5052304b475eea62a2de7d6cf976
child 11684 7b27551e0618c40743059787a0d2c4707bf73394
push id1790
push userbjones@mozilla.com
push dateTue, 19 Sep 2017 04:17:41 +0000
reviewerssmacleod
bugs1368516
autoland: accept and store patch based requests (bug 1368516) r?smacleod Update the web app to accept patch based requests and insert them into the database. Processing of patch based requests is still not implemented. MozReview-Commit-ID: ETrciHILGeb
autoland/autoland/autoland.py
autoland/autoland/autoland_rest.py
autoland/tests/test-post-autoland-job-from-repo.t
autoland/tests/test-post-autoland-job.t
testing/vcttesting/autoland_mach_commands.py
--- a/autoland/autoland/autoland.py
+++ b/autoland/autoland/autoland.py
@@ -91,16 +91,19 @@ def handle_pending_transplants(dbconn):
         # to binary because command arguments aren't unicode.
         destination = destination.encode('ascii')
         requester = request['ldap_username']
         tree = request['tree'].encode('ascii')
         rev = request['rev'].encode('ascii')
         trysyntax = request.get('trysyntax', '')
         push_bookmark = request.get('push_bookmark', '').encode('ascii')
         commit_descriptions = request.get('commit_descriptions')
+        patch_urls = map(lambda u: u.encode('ascii'),
+                         request.get('patch_urls', []))
+
         repo_config = config.get_repo(tree)
         if not repo_config['tree']:
             # Trees not present on treestatus cannot be closed.
             tree_open = True
         else:
             # When pushing to try we need to check if try is open, not the
             # tree for the source repo.
             tree_name = 'try' if trysyntax else repo_config['tree']
@@ -115,16 +118,21 @@ def handle_pending_transplants(dbconn):
         attempts = 0
         started = datetime.datetime.now()
         landed = False
         while attempts < MAX_TRANSPLANT_ATTEMPTS:
             logger.info('initiating transplant from tree: %s rev: %s '
                         'to destination: %s, attempt %s' % (
                             tree, rev, destination, attempts + 1))
 
+            if patch_urls:
+                result = 'patch based landings not implemented'
+                landed = False
+                break
+
             # TODO: We should break the transplant call into two steps, one
             #       to pull down the commits to transplant, and another
             #       one to rebase it and attempt to push so we don't
             #       duplicate work unnecessarily if we have to rebase more
             #       than once.
             os.environ['AUTOLAND_REQUEST_USER'] = requester
             try:
                 with Transplant(tree, destination, rev) as tp:
--- a/autoland/autoland/autoland_rest.py
+++ b/autoland/autoland/autoland_rest.py
@@ -227,19 +227,16 @@ def autoland():
         return Response('Login required', 401, auth_response)
 
     try:
         validate_request(request)
     except ValueError as e:
         app.logger.warn('Bad Request from %s: %s' % (request.remote_addr, e))
         return make_response(jsonify({'error': 'Bad request: %s' % e}), 400)
 
-    if 'patch_urls' in request.json:
-        raise NotImplementedError('patch based landings not implemented')
-
     dbconn = get_dbconn()
     cursor = dbconn.cursor()
 
     query = """
         SELECT created, request->>'ldap_username'
           FROM Transplant
          WHERE landed IS NULL
                AND request->>'rev' = %s
rename from autoland/tests/test-post-autoland-job.t
rename to autoland/tests/test-post-autoland-job-from-repo.t
--- a/testing/vcttesting/autoland_mach_commands.py
+++ b/testing/vcttesting/autoland_mach_commands.py
@@ -32,17 +32,17 @@ class AutolandCommands(object):
                 if r.status_code != 200 or json.loads(r.text)['landed'] is not None:
                     print(r.status_code, r.text)
                     break
                 time.sleep(POLL_INTERVAL)
             else:
                 print('timed out')
 
     @Command('post-autoland-job', category='autoland',
-        description='Post a job to autoland')
+             description='Post a job to autoland')
     @CommandArgument('host', help='Host to which to post the job')
     @CommandArgument('tree', help='Source tree of the revision')
     @CommandArgument('rev', help='Revision to land')
     @CommandArgument('destination', help='Destination tree for the revision')
     @CommandArgument('pingback_url', default='http://localhost/',
                      help='URL to which Autoland should post result')
     @CommandArgument('--trysyntax', required=False, default='',
                      help='Try syntax to use [optional]')
@@ -51,35 +51,39 @@ class AutolandCommands(object):
     @CommandArgument('--commit-descriptions', required=False, default='',
                      help='Commit descriptions to use when rewriting [optional]')
     @CommandArgument('--ldap-username', required=False, default='autolanduser@example.com',
                      help='Commit descriptions to use when rewriting [optional]')
     @CommandArgument('--user', required=False, default='autoland',
                      help='Autoland user')
     @CommandArgument('--password', required=False, default='autoland',
                      help='Autoland password')
+    @CommandArgument('--patch-url', required=False, default='',
+                     help='URL of patch [optional]')
     def post_autoland_job(self, host, tree, rev, destination, pingback_url,
                           trysyntax=None, push_bookmark=None,
                           commit_descriptions=None, ldap_username=None,
-                          user=None, password=None):
+                          user=None, password=None, patch_url=None):
 
         data = {
             'tree': tree,
             'rev': rev,
             'destination': destination,
             'pingback_url': pingback_url
         }
         if trysyntax:
             data['trysyntax'] = trysyntax
         if push_bookmark:
             data['push_bookmark'] = push_bookmark
         if commit_descriptions:
             data['commit_descriptions'] = json.loads(commit_descriptions)
         if ldap_username:
             data['ldap_username'] = ldap_username
+        if patch_url:
+            data['patch_urls'] = [patch_url]
 
         host = host.rstrip('/')
         r = requests.post(host + '/autoland', data=json.dumps(data),
                           headers={'Content-Type': 'application/json'},
                           auth=(user, password))
         print(r.status_code, r.text)
 
     @Command('autoland-job-status', category='autoland',