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 b7273ef849e7070e21c1d51a9b4190237f385027 so this
change is to just put in an extra test for it.
Change-Id: I521cfbb5873973014c43f9780722d2f80a7c12f0
diff --git a/tests/fixtures/layout-success-pattern.yaml b/tests/fixtures/layout-success-pattern.yaml
new file mode 100644
index 0000000..cea15f1
--- /dev/null
+++ b/tests/fixtures/layout-success-pattern.yaml
@@ -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
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index fe7c7cc..8ac5368 100755
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -4392,3 +4392,38 @@
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])
diff --git a/zuul/reporter/__init__.py b/zuul/reporter/__init__.py
index 0569fbe..0c9a8d8 100644
--- a/zuul/reporter/__init__.py
+++ b/zuul/reporter/__init__.py
@@ -13,6 +13,7 @@
# under the License.
import abc
+import logging
import six
@@ -24,6 +25,8 @@
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