From cd651c4b8033765ab30f4d0cb10289a9580fc2a4 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Tue, 16 Jan 2018 13:52:36 +0100 Subject: [PATCH] hipchat_notif: Fix compatibility dispatch This fixes the following error message that is produced when using the old hipchat module in a real world scenario (as opposed to a synthetic test): jenkins_jobs.errors.JenkinsJobsException: Unknown entry point or macro 'name' for component type: 'publisher'. It works in the tests/hipchat/fixtures/hipchat005.yaml test because the `data` dict contains only the 'hipchat' key, but when used in a job-template, the dict contains a lot more, e.g. 'name', 'project-type', 'description' etc. To make testing more difficult, `data` is not an OrderedDict, but dict (see YamlParser._applyDefaults), so it behaves differently across python versions, due to different order of dict.items (hash randomization, ...). Therefore the test contains seemingly unnecessary fields like 'project-type', 'scm' and 'description'. Without these, it would pass without the fix on at least one of py27, py35, py36, and it's rather likely I haven't covered all possible scenarios (different platforms?). Change-Id: Ie45084f1a4d6405d7e60dde5fce619a66dc026db --- jenkins_jobs/modules/hipchat_notif.py | 3 ++- .../fixtures/hipchat1.plugins_info.yaml | 3 +++ tests/yamlparser/fixtures/hipchat1.xml | 27 +++++++++++++++++++ tests/yamlparser/fixtures/hipchat1.yaml | 17 ++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/yamlparser/fixtures/hipchat1.plugins_info.yaml create mode 100644 tests/yamlparser/fixtures/hipchat1.xml create mode 100644 tests/yamlparser/fixtures/hipchat1.yaml diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py index f631357a0..c342a55ec 100644 --- a/jenkins_jobs/modules/hipchat_notif.py +++ b/jenkins_jobs/modules/hipchat_notif.py @@ -145,7 +145,8 @@ class HipChat(jenkins_jobs.modules.base.Base): "'hipchat' module supports the old plugin versions <1.9, " "newer versions are supported via the 'publishers' module. " "Please upgrade you job definition") - return self.registry.dispatch('publisher', publishers, data) + component = {'hipchat': hipchat} + return self.registry.dispatch('publisher', publishers, component) else: properties = xml_parent.find('properties') if properties is None: diff --git a/tests/yamlparser/fixtures/hipchat1.plugins_info.yaml b/tests/yamlparser/fixtures/hipchat1.plugins_info.yaml new file mode 100644 index 000000000..25ec76fab --- /dev/null +++ b/tests/yamlparser/fixtures/hipchat1.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Jenkins HipChat Plugin' + shortName: 'hipchat' + version: "2.1.1" diff --git a/tests/yamlparser/fixtures/hipchat1.xml b/tests/yamlparser/fixtures/hipchat1.xml new file mode 100644 index 000000000..e5ec0d317 --- /dev/null +++ b/tests/yamlparser/fixtures/hipchat1.xml @@ -0,0 +1,27 @@ + + + + desc<!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + + + room1 + true + false + false + false + false + false + false + + + + diff --git a/tests/yamlparser/fixtures/hipchat1.yaml b/tests/yamlparser/fixtures/hipchat1.yaml new file mode 100644 index 000000000..7a797fc23 --- /dev/null +++ b/tests/yamlparser/fixtures/hipchat1.yaml @@ -0,0 +1,17 @@ +- defaults: + name: global + project-type: freestyle + description: desc + +- project: + name: hipchat1 + jobs: + - 'hipchat1-tpl' + +- job-template: + name: 'hipchat1-tpl' + scm: [] + hipchat: + enabled: true + rooms: [room1] + notify-start: true