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
This commit is contained in:
Tomas Janousek 2018-01-16 13:52:36 +01:00
parent f30179db4a
commit cd651c4b80
4 changed files with 49 additions and 1 deletions

View File

@ -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:

View File

@ -0,0 +1,3 @@
- longName: 'Jenkins HipChat Plugin'
shortName: 'hipchat'
version: "2.1.1"

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>desc&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders/>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<token/>
<room>room1</room>
<startNotification>true</startNotification>
<notifySuccess>false</notifySuccess>
<notifyAborted>false</notifyAborted>
<notifyNotBuilt>false</notifyNotBuilt>
<notifyUnstable>false</notifyUnstable>
<notifyFailure>false</notifyFailure>
<notifyBackToNormal>false</notifyBackToNormal>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>
<buildWrappers/>
</project>

View File

@ -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