autoland: add lando pingback support (
bug 1368516) r?smacleod
Plug in config and code to support Lando pingbacks.
MozReview-Commit-ID: FQKxEQZcz7w
--- a/ansible/roles/autoland/templates/config.json.j2
+++ b/ansible/roles/autoland/templates/config.json.j2
@@ -4,16 +4,20 @@
},
"database": "dbname={{ secrets.db_name }} user={{ secrets.db_user }} password={{ secrets.db_password }} host={{ secrets.db_host }}",
"repos" : {{ repos | to_nice_json }},
"pingback": {
"reviewboard.mozilla.org": {
"type": "mozreview",
"user": "{{ secrets.bugzilla_user }}",
"password": "{{ secrets.bugzilla_password }}"
+ },
+ "lando-api.example.com": {
+ "type": "lando",
+ "api-key": "{{ secrets.lando_api_key }}"
}
},
"patch_url_buckets": {
"to-be-determined": {
"aws_access_key_id": "{{ secrets.lando_aws_access_key_id }}",
"aws_secret_access_key": "{{ secrets.lando_aws_secret_access_key }}"
}
}
--- a/autoland/autoland/autoland.py
+++ b/autoland/autoland/autoland.py
@@ -1,13 +1,14 @@
#!/usr/bin/env python
import argparse
import config
import datetime
import json
+import lando
import logging
import mozreview
import os
import psycopg2
import sys
import time
import traceback
import urlparse
@@ -254,16 +255,17 @@ def handle_pending_mozreview_updates(dbc
select MozreviewUpdate.id,transplant_id,request,data
from MozreviewUpdate inner join Transplant
on (Transplant.id = MozreviewUpdate.transplant_id)
limit %(limit)s
"""
cursor.execute(query, {'limit': MOZREVIEW_COMMENT_LIMIT})
mozreview_pingback = mozreview.MozReviewPingback()
+ lando_pingback = lando.LandoPingback()
updated = []
all_posted = True
for row in cursor.fetchall():
update_id, transplant_id, request, data = row
# Validate the pingback hostname is still present in config.json.
pingback_url = request.get('pingback_url')
@@ -282,16 +284,19 @@ def handle_pending_mozreview_updates(dbc
# Use the appropriate handler for this pingback.
if pingback_url:
pingback_config = config.get('pingback').get(hostname)
if pingback_config['type'] == 'mozreview':
pingback = mozreview_pingback
+ elif pingback_config['type'] == 'lando':
+ pingback = lando_pingback
+
else:
logging.warning('ignoring pinback to %s: not supported'
% hostname)
pingback_url = None
# Update the requester if required.
if pingback_url:
logger.info('trying to post %s update to: %s for request: %s' %
new file mode 100644
--- /dev/null
+++ b/autoland/autoland/lando.py
@@ -0,0 +1,37 @@
+import config
+import logging
+import requests
+import urlparse
+
+
+logger = logging.getLogger('autoland')
+
+
+class LandoPingback(object):
+ """Handle updating Lando requests."""
+
+ def __init__(self):
+ self.name = 'lando'
+ self.auth = {}
+
+ def update(self, pingback_url, data):
+ """Sends the 'data' to the 'pingback_url', handing auth and errors"""
+
+ try:
+ # Grab the api-key for this hostname.
+ hostname = urlparse.urlparse(pingback_url).hostname
+ if hostname not in self.auth:
+ auth_config = config.get('pingback').get(hostname)
+ self.auth[hostname] = auth_config['api-key']
+
+ res = requests.post(pingback_url,
+ data=data,
+ headers={'API-Key': self.auth[hostname]})
+
+ if res.status_code != 200:
+ return None, res.text
+ return res.status_code, res.text
+ except requests.exceptions.ConnectionError as e:
+ return None, 'Failed to connect to Lando: %s' % e
+ except requests.exceptions.RequestException as e:
+ return None, 'Failed to update Lando: %s' % e
--- a/testing/docker/builder-autoland/config.json
+++ b/testing/docker/builder-autoland/config.json
@@ -9,16 +9,20 @@
"tree": "test"
}
},
"pingback": {
"example.com": {
"type": "mozreview",
"user": "admin@example.com",
"password": "password"
+ },
+ "lando.example.com": {
+ "type": "lando",
+ "api-key": "WinnerWinnerChickenDinner"
}
},
"patch_url_buckets": {
"example-bucket": {
"aws_access_key_id": "DEADBEEFF00D",
"aws_secret_access_key": "secret"
}
}