Continue reporting on URL format KeyError
If a report success/failure URL format string refers to a build parameter or other dict key which does not exist, log the exception and continue reporting but print the raw format string instead. Previously Zuul would just fail to report entirely. Story: #147 Change-Id: Id936921dc6db919e28dea8ca83648b5ebd017b5c
This commit is contained in:
parent
ae6b9ee599
commit
25d4c4f79e
|
@ -0,0 +1,33 @@
|
|||
pipelines:
|
||||
- name: gate
|
||||
manager: DependentPipelineManager
|
||||
trigger:
|
||||
gerrit:
|
||||
- event: comment-added
|
||||
approval:
|
||||
- approved: 1
|
||||
success:
|
||||
gerrit:
|
||||
verified: 2
|
||||
submit: true
|
||||
failure:
|
||||
gerrit:
|
||||
verified: -2
|
||||
start:
|
||||
gerrit:
|
||||
verified: 0
|
||||
precedence: high
|
||||
|
||||
jobs:
|
||||
- name: log-path
|
||||
success-pattern: foo{build.parameters[LOG_PATH]}bar
|
||||
- name: nonexistent
|
||||
success-pattern: foo{build.parameters[NONEXISTENT]}bar
|
||||
|
||||
projects:
|
||||
- name: org/project1
|
||||
gate:
|
||||
- log-path
|
||||
- name: org/project2
|
||||
gate:
|
||||
- nonexistent
|
|
@ -2683,6 +2683,44 @@ For CI problems and help debugging, contact ci@example.org"""
|
|||
self.assertEqual('The merge failed! For more information...',
|
||||
self.smtp_messages[0]['body'])
|
||||
|
||||
def test_build_parameter_in_report(self):
|
||||
"""Check that a message is sent to a reporter when embedding a build
|
||||
parameter"""
|
||||
self.config.set('zuul', 'layout_config',
|
||||
'tests/fixtures/layout-build-parameters.yaml')
|
||||
self.sched.reconfigure(self.config)
|
||||
self.registerJobs()
|
||||
|
||||
# Check the reported message is valid
|
||||
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
|
||||
A.addApproval('CRVW', 2)
|
||||
self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(1, len(self.history)) # 1 job
|
||||
self.assertEqual(2, len(A.messages)) # 2 messages
|
||||
|
||||
self.assertIn('gate/log-path', A.messages[1])
|
||||
|
||||
def test_nonexistent_build_parameter_in_report(self):
|
||||
"""Check that a message is sent to a reporter even when embedding a
|
||||
nonexistent build parameter"""
|
||||
self.config.set('zuul', 'layout_config',
|
||||
'tests/fixtures/layout-build-parameters.yaml')
|
||||
self.sched.reconfigure(self.config)
|
||||
self.registerJobs()
|
||||
|
||||
# Check the reported message is valid
|
||||
A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
|
||||
A.addApproval('CRVW', 2)
|
||||
self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(1, len(self.history)) # 1 job
|
||||
self.assertEqual(2, len(A.messages)) # 2 messages
|
||||
|
||||
self.assertIn('NONEXISTENT', A.messages[1])
|
||||
|
||||
def test_swift_instructions(self):
|
||||
"Test that the correct swift instructions are sent to the workers"
|
||||
self.config.set('zuul', 'layout_config',
|
||||
|
|
|
@ -1461,10 +1461,15 @@ class BasePipelineManager(object):
|
|||
if job.failure_pattern:
|
||||
pattern = job.failure_pattern
|
||||
if pattern:
|
||||
url = pattern.format(change=item.change,
|
||||
pipeline=self.pipeline,
|
||||
job=job,
|
||||
build=build)
|
||||
try:
|
||||
url = pattern.format(change=item.change,
|
||||
pipeline=self.pipeline,
|
||||
job=job,
|
||||
build=build)
|
||||
except KeyError:
|
||||
self.log.exception("Unknown key while formatting url %s" %
|
||||
pattern)
|
||||
url = pattern
|
||||
else:
|
||||
url = build.url or job.name
|
||||
if not job.voting:
|
||||
|
|
Loading…
Reference in New Issue