From dd14a86a9b0c70f6a41b2fc4f6b50b36f098019c Mon Sep 17 00:00:00 2001 From: Benjamin Staffin Date: Mon, 24 Mar 2014 18:32:29 -0700 Subject: [PATCH] Add support for Slave Utilization plugin Change-Id: I4243fddf2f08a09671757b503fae2a890f2d820e --- jenkins_jobs/modules/properties.py | 30 +++++++++++++++++++ setup.cfg | 1 + .../fixtures/slave-utilization1.xml | 10 +++++++ .../fixtures/slave-utilization1.yaml | 4 +++ .../fixtures/slave-utilization2.xml | 10 +++++++ .../fixtures/slave-utilization2.yaml | 3 ++ 6 files changed, 58 insertions(+) create mode 100644 tests/properties/fixtures/slave-utilization1.xml create mode 100644 tests/properties/fixtures/slave-utilization1.yaml create mode 100644 tests/properties/fixtures/slave-utilization2.xml create mode 100644 tests/properties/fixtures/slave-utilization2.yaml diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 73b0c6ae5..c34cc1a4f 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -533,6 +533,36 @@ def heavy_job(parser, xml_parent, data): data.get('weight', 1)) +def slave_utilization(parser, xml_parent, data): + """yaml: slave-utilization + This plugin allows you to specify the percentage of a slave's capacity a + job wants to use. + + Requires the Jenkins `Slave Utilization Plugin. + `_ + + :arg int slave-percentage: Specify the percentage of a slave's execution + slots that this job should occupy (default: 0) + :arg bool single-instance-per-slave: Control whether concurrent instances + of this job will be permitted to run in parallel on a single slave + (default: False) + + Example: + + .. literalinclude:: \ + /../../tests/properties/fixtures/slave-utilization1.yaml + """ + utilization = XML.SubElement( + xml_parent, 'com.suryagaddipati.jenkins.SlaveUtilizationProperty') + percent = int(data.get('slave-percentage', 0)) + XML.SubElement(utilization, 'needsExclusiveAccessToNode' + ).text = 'true' if percent else 'false' + XML.SubElement(utilization, 'slaveUtilizationPercentage' + ).text = str(percent) + XML.SubElement(utilization, 'singleInstancePerSlave').text = str( + data.get('single-instance-per-slave', False)).lower() + + def delivery_pipeline(parser, xml_parent, data): """yaml: delivery-pipeline Requires the Jenkins `Delivery Pipeline Plugin. diff --git a/setup.cfg b/setup.cfg index 7c700f566..c260fa1f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -68,6 +68,7 @@ jenkins_jobs.properties = ownership=jenkins_jobs.modules.properties:ownership priority-sorter=jenkins_jobs.modules.properties:priority_sorter promoted-build=jenkins_jobs.modules.properties:promoted_build + slave-utilization=jenkins_jobs.modules.properties:slave_utilization throttle=jenkins_jobs.modules.properties:throttle zeromq-event=jenkins_jobs.modules.properties:zeromq_event jenkins_jobs.parameters = diff --git a/tests/properties/fixtures/slave-utilization1.xml b/tests/properties/fixtures/slave-utilization1.xml new file mode 100644 index 000000000..256614e00 --- /dev/null +++ b/tests/properties/fixtures/slave-utilization1.xml @@ -0,0 +1,10 @@ + + + + + true + 40 + false + + + diff --git a/tests/properties/fixtures/slave-utilization1.yaml b/tests/properties/fixtures/slave-utilization1.yaml new file mode 100644 index 000000000..e79ce0fd6 --- /dev/null +++ b/tests/properties/fixtures/slave-utilization1.yaml @@ -0,0 +1,4 @@ +properties: + - slave-utilization: + slave-percentage: 40 + single-instance-per-slave: false diff --git a/tests/properties/fixtures/slave-utilization2.xml b/tests/properties/fixtures/slave-utilization2.xml new file mode 100644 index 000000000..4f8f36b8b --- /dev/null +++ b/tests/properties/fixtures/slave-utilization2.xml @@ -0,0 +1,10 @@ + + + + + false + 0 + true + + + diff --git a/tests/properties/fixtures/slave-utilization2.yaml b/tests/properties/fixtures/slave-utilization2.yaml new file mode 100644 index 000000000..7313717fd --- /dev/null +++ b/tests/properties/fixtures/slave-utilization2.yaml @@ -0,0 +1,3 @@ +properties: + - slave-utilization: + single-instance-per-slave: true