From 5e5baa114f8d8503f8ef6543ef17fd5fbdfa6b00 Mon Sep 17 00:00:00 2001 From: John Fragoulis Date: Wed, 14 Feb 2018 12:13:47 +0200 Subject: [PATCH] Support version 2.0 and greater of the Priority Sorter Plugin The Priority Sorter Plugin changed the xml specification after 2.0. The commit reflects that change but also keeps support for version 1.0. References: [1] https://storyboard.openstack.org/#!/story/2001534 [2] https://wiki.jenkins.io/display/JENKINS/Priority+Sorter+Plugin Change-Id: I2f861265dfa64cde930c6a8e66c967bf1e6fc831 Closes-Bug: 2001534 --- jenkins_jobs/modules/properties.py | 28 +++++++++++++++---- .../priority_sorter001.plugins_info.yaml | 3 ++ ...rity_sorter.xml => priority_sorter001.xml} | 0 ...ty_sorter.yaml => priority_sorter001.yaml} | 0 .../priority_sorter002.plugins_info.yaml | 3 ++ .../fixtures/priority_sorter002.xml | 9 ++++++ .../fixtures/priority_sorter002.yaml | 3 ++ 7 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 tests/properties/fixtures/priority_sorter001.plugins_info.yaml rename tests/properties/fixtures/{priority_sorter.xml => priority_sorter001.xml} (100%) rename tests/properties/fixtures/{priority_sorter.yaml => priority_sorter001.yaml} (100%) create mode 100644 tests/properties/fixtures/priority_sorter002.plugins_info.yaml create mode 100644 tests/properties/fixtures/priority_sorter002.xml create mode 100644 tests/properties/fixtures/priority_sorter002.yaml diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 65a10c3d4..ae794f5ae 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -497,17 +497,33 @@ def priority_sorter(registry, xml_parent, data): `. :arg int priority: Priority of the job. Higher value means higher - priority, with 100 as the standard priority. (required) + priority, with 3 as the default priority. (required) Example: - .. literalinclude:: /../../tests/properties/fixtures/priority_sorter.yaml + .. literalinclude:: + /../../tests/properties/fixtures/priority_sorter002.yaml :language: yaml """ - priority_sorter_tag = XML.SubElement(xml_parent, - 'hudson.queueSorter.' - 'PrioritySorterJobProperty') - mapping = [('priority', 'priority', None)] + plugin_info = registry.get_plugin_info('Priority Sorter Plugin') + version = pkg_resources.parse_version(plugin_info.get('version', '0')) + + if version >= pkg_resources.parse_version("2.0"): + priority_sorter_tag = XML.SubElement(xml_parent, + 'jenkins.advancedqueue.priority.' + 'strategy.PriorityJobProperty') + + mapping = [ + ('use', 'useJobPriority', True), + ('priority', 'priority', None) + ] + else: + priority_sorter_tag = XML.SubElement(xml_parent, + 'hudson.queueSorter.' + 'PrioritySorterJobProperty') + + mapping = [('priority', 'priority', None)] + helpers.convert_mapping_to_xml( priority_sorter_tag, data, mapping, fail_required=True) diff --git a/tests/properties/fixtures/priority_sorter001.plugins_info.yaml b/tests/properties/fixtures/priority_sorter001.plugins_info.yaml new file mode 100644 index 000000000..c1adba087 --- /dev/null +++ b/tests/properties/fixtures/priority_sorter001.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Priority Sorter Plugin' + shortName: 'PrioritySorter' + version: '1.0' diff --git a/tests/properties/fixtures/priority_sorter.xml b/tests/properties/fixtures/priority_sorter001.xml similarity index 100% rename from tests/properties/fixtures/priority_sorter.xml rename to tests/properties/fixtures/priority_sorter001.xml diff --git a/tests/properties/fixtures/priority_sorter.yaml b/tests/properties/fixtures/priority_sorter001.yaml similarity index 100% rename from tests/properties/fixtures/priority_sorter.yaml rename to tests/properties/fixtures/priority_sorter001.yaml diff --git a/tests/properties/fixtures/priority_sorter002.plugins_info.yaml b/tests/properties/fixtures/priority_sorter002.plugins_info.yaml new file mode 100644 index 000000000..d4045458e --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Priority Sorter Plugin' + shortName: 'PrioritySorter' + version: '2.0' diff --git a/tests/properties/fixtures/priority_sorter002.xml b/tests/properties/fixtures/priority_sorter002.xml new file mode 100644 index 000000000..1e569759c --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.xml @@ -0,0 +1,9 @@ + + + + + true + 3 + + + diff --git a/tests/properties/fixtures/priority_sorter002.yaml b/tests/properties/fixtures/priority_sorter002.yaml new file mode 100644 index 000000000..10c53ad9b --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.yaml @@ -0,0 +1,3 @@ +properties: + - priority-sorter: + priority: 3