Add extra test for bad url patterns

Report can have parameters from a job substituted into the message.
If a reporter fails for whatever reason it is logged to zuul and
otherwise ignored quietly to the user.

If bad varaibles are attempted to be substituted into a message
log a warning and fallback to the result url for the reporter to
continue.

This was fixed in b7273ef849 so this
change is to just put in an extra test for it.

Change-Id: I521cfbb5873973014c43f9780722d2f80a7c12f0
This commit is contained in:
Joshua Hesketh 2015-12-22 10:06:54 +11:00
parent a8da150c4a
commit d6dbd68ba3
3 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,21 @@
pipelines:
- name: check
manager: IndependentPipelineManager
trigger:
gerrit:
- event: patchset-created
success:
smtp:
to: me@example.org
jobs:
- name: docs-draft-test
success-pattern: http://docs-draft.example.org/{build.parameters[LOG_PATH]}/publish-docs/
- name: docs-draft-test2
success-pattern: http://docs-draft.example.org/{NOPE}/{build.parameters[BAD]}/publish-docs/
projects:
- name: org/docs
check:
- docs-draft-test:
- docs-draft-test2

View File

@ -4392,3 +4392,38 @@ For CI problems and help debugging, contact ci@example.org"""
self.assertIn('Build failed.', K.messages[0])
# No more messages reported via smtp
self.assertEqual(3, len(self.smtp_messages))
def test_success_pattern(self):
"Ensure bad build params are ignored"
# Use SMTP reporter to grab the result message easier
self.init_repo("org/docs")
self.config.set('zuul', 'layout_config',
'tests/fixtures/layout-success-pattern.yaml')
self.sched.reconfigure(self.config)
self.worker.hold_jobs_in_build = True
self.registerJobs()
A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
# Grab build id
self.assertEqual(len(self.builds), 1)
uuid = self.builds[0].unique[:7]
self.worker.hold_jobs_in_build = False
self.worker.release()
self.waitUntilSettled()
self.assertEqual(len(self.smtp_messages), 1)
body = self.smtp_messages[0]['body'].splitlines()
self.assertEqual('Build succeeded.', body[0])
self.assertIn(
'- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
'docs-draft-test/%s/publish-docs/' % uuid,
body[2])
self.assertIn(
'- docs-draft-test2 https://server/job/docs-draft-test2/1/',
body[3])

View File

@ -13,6 +13,7 @@
# under the License.
import abc
import logging
import six
@ -24,6 +25,8 @@ class BaseReporter(object):
Defines the exact public methods that must be supplied.
"""
log = logging.getLogger("zuul.reporter.BaseReporter")
def __init__(self, reporter_config={}, sched=None, connection=None):
self.reporter_config = reporter_config
self.sched = sched