Merge "github: gracefully handle unknown event" into feature/zuulv3
This commit is contained in:
commit
4bf2cc3448
|
@ -922,7 +922,7 @@ class FakeGithubConnection(githubconnection.GithubConnection):
|
|||
'http://localhost:%s/connection/%s/payload'
|
||||
% (port, self.connection_name),
|
||||
data=payload, headers=headers)
|
||||
urllib.request.urlopen(req)
|
||||
return urllib.request.urlopen(req)
|
||||
|
||||
def getPull(self, project, number):
|
||||
pr = self.pull_requests[number - 1]
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import re
|
||||
from testtools.matchers import MatchesRegex, StartsWith
|
||||
import urllib
|
||||
import time
|
||||
|
||||
from tests.base import ZuulTestCase, simple_layout, random_sha1
|
||||
|
@ -584,3 +585,18 @@ class TestGithubDriver(ZuulTestCase):
|
|||
new = self.sched.tenant_last_reconfigured.get('tenant-one', 0)
|
||||
# New timestamp should be greater than the old timestamp
|
||||
self.assertLess(old, new)
|
||||
|
||||
@simple_layout('layouts/basic-github.yaml', driver='github')
|
||||
def test_ping_event(self):
|
||||
# Test valid ping
|
||||
pevent = {'repository': {'full_name': 'org/project'}}
|
||||
req = self.fake_github.emitEvent(('ping', pevent))
|
||||
self.assertEqual(req.status, 200, "Ping event didn't succeed")
|
||||
|
||||
# Test invalid ping
|
||||
pevent = {'repository': {'full_name': 'unknown-project'}}
|
||||
self.assertRaises(
|
||||
urllib.error.HTTPError,
|
||||
self.fake_github.emitEvent,
|
||||
('ping', pevent),
|
||||
)
|
||||
|
|
|
@ -75,6 +75,8 @@ class GithubWebhookListener():
|
|||
|
||||
try:
|
||||
self.__dispatch_event(request)
|
||||
except webob.exc.HTTPNotFound:
|
||||
raise
|
||||
except:
|
||||
self.log.exception("Exception handling Github event:")
|
||||
|
||||
|
@ -92,7 +94,8 @@ class GithubWebhookListener():
|
|||
except AttributeError:
|
||||
message = "Unhandled X-Github-Event: {0}".format(event)
|
||||
self.log.debug(message)
|
||||
raise webob.exc.HTTPBadRequest(message)
|
||||
# Returns empty 200 on unhandled events
|
||||
raise webob.exc.HTTPOk()
|
||||
|
||||
try:
|
||||
json_body = request.json_body
|
||||
|
@ -117,6 +120,8 @@ class GithubWebhookListener():
|
|||
|
||||
try:
|
||||
event = method(json_body)
|
||||
except webob.exc.HTTPNotFound:
|
||||
raise
|
||||
except:
|
||||
self.log.exception('Exception when handling event:')
|
||||
event = None
|
||||
|
@ -219,6 +224,14 @@ class GithubWebhookListener():
|
|||
event.action = body.get('action')
|
||||
return event
|
||||
|
||||
def _event_ping(self, body):
|
||||
project_name = body['repository']['full_name']
|
||||
if not self.connection.getProject(project_name):
|
||||
self.log.warning("Ping received for unknown project %s" %
|
||||
project_name)
|
||||
raise webob.exc.HTTPNotFound("Sorry, this project is not "
|
||||
"registered")
|
||||
|
||||
def _event_status(self, body):
|
||||
action = body.get('action')
|
||||
if action == 'pending':
|
||||
|
|
Loading…
Reference in New Issue