From 90f4dc0dfe774713351a256fa85966af781b10f8 Mon Sep 17 00:00:00 2001 From: Lukas Bednar Date: Tue, 15 Jul 2014 17:01:10 +0200 Subject: [PATCH] wrappers: fixed locks for empty collection it caused "Locks" checkbox to be checked, and it picked up first lock from selectbox as default. Change-Id: I13fdf104c6c32b783fb539f8947e3e071cb9788c Signed-off-by: Lukas Bednar --- jenkins_jobs/modules/wrappers.py | 25 ++++++++++++------------- tests/wrappers/fixtures/locks001.xml | 4 ++++ tests/wrappers/fixtures/locks001.yaml | 2 ++ tests/wrappers/fixtures/locks002.xml | 15 +++++++++++++++ tests/wrappers/fixtures/locks002.yaml | 4 ++++ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 tests/wrappers/fixtures/locks001.xml create mode 100644 tests/wrappers/fixtures/locks001.yaml create mode 100644 tests/wrappers/fixtures/locks002.xml create mode 100644 tests/wrappers/fixtures/locks002.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 6c660f98c..c755e11a5 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -424,22 +424,21 @@ def locks(parser, xml_parent, data): :arg: list of locks to use - Example:: + Example: - wrappers: - - locks: - - FOO - - FOO2 + .. literalinclude:: /../../tests/wrappers/fixtures/locks002.yaml + :language: yaml """ - lw = XML.SubElement(xml_parent, - 'hudson.plugins.locksandlatches.LockWrapper') - locktop = XML.SubElement(lw, 'locks') locks = data - for lock in locks: - lockwrapper = XML.SubElement(locktop, - 'hudson.plugins.locksandlatches.' - 'LockWrapper_-LockWaitConfig') - XML.SubElement(lockwrapper, 'name').text = lock + if locks: + lw = XML.SubElement(xml_parent, + 'hudson.plugins.locksandlatches.LockWrapper') + locktop = XML.SubElement(lw, 'locks') + for lock in locks: + lockwrapper = XML.SubElement(locktop, + 'hudson.plugins.locksandlatches.' + 'LockWrapper_-LockWaitConfig') + XML.SubElement(lockwrapper, 'name').text = lock def copy_to_slave(parser, xml_parent, data): diff --git a/tests/wrappers/fixtures/locks001.xml b/tests/wrappers/fixtures/locks001.xml new file mode 100644 index 000000000..955631f2d --- /dev/null +++ b/tests/wrappers/fixtures/locks001.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/wrappers/fixtures/locks001.yaml b/tests/wrappers/fixtures/locks001.yaml new file mode 100644 index 000000000..9585c38b2 --- /dev/null +++ b/tests/wrappers/fixtures/locks001.yaml @@ -0,0 +1,2 @@ +wrappers: + - locks: diff --git a/tests/wrappers/fixtures/locks002.xml b/tests/wrappers/fixtures/locks002.xml new file mode 100644 index 000000000..bb7ef6340 --- /dev/null +++ b/tests/wrappers/fixtures/locks002.xml @@ -0,0 +1,15 @@ + + + + + + + FOO + + + FOO2 + + + + + diff --git a/tests/wrappers/fixtures/locks002.yaml b/tests/wrappers/fixtures/locks002.yaml new file mode 100644 index 000000000..cdaa45c4d --- /dev/null +++ b/tests/wrappers/fixtures/locks002.yaml @@ -0,0 +1,4 @@ +wrappers: + - locks: + - FOO + - FOO2