From 6ce5c6a31a90d68acdd5c77e4a60fa9788ec851e Mon Sep 17 00:00:00 2001 From: Ryo Tagami Date: Fri, 15 Apr 2016 19:39:31 +0900 Subject: [PATCH] Add support for Jenkins OpenStack Cloud Plugin This commit adds support for [Openstack Cloud Plugin] (https://wiki.jenkins-ci.org/display/JENKINS/Openstack+Cloud+Plugin). Change-Id: Ic3cf46908113cdb1c0bc50005d470a7da8a86f60 Signed-off-by: Ryo Tagami --- jenkins_jobs/modules/wrappers.py | 61 +++++++++++++++++++++++ tests/wrappers/fixtures/openstack001.xml | 20 ++++++++ tests/wrappers/fixtures/openstack001.yaml | 11 ++++ tests/wrappers/fixtures/openstack002.xml | 14 ++++++ tests/wrappers/fixtures/openstack002.yaml | 6 +++ tests/wrappers/fixtures/openstack003.xml | 6 +++ tests/wrappers/fixtures/openstack003.yaml | 3 ++ 7 files changed, 121 insertions(+) create mode 100644 tests/wrappers/fixtures/openstack001.xml create mode 100644 tests/wrappers/fixtures/openstack001.yaml create mode 100644 tests/wrappers/fixtures/openstack002.xml create mode 100644 tests/wrappers/fixtures/openstack002.yaml create mode 100644 tests/wrappers/fixtures/openstack003.xml create mode 100644 tests/wrappers/fixtures/openstack003.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 926e25273..d9599d12b 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1108,6 +1108,67 @@ def jclouds(parser, xml_parent, data): 'JCloudsOneOffSlave') +def openstack(parser, xml_parent, data): + """yaml: openstack + Provision slaves from OpenStack on demand. Requires the Jenkins + :jenkins-wiki:`Openstack Cloud Plugin `. + + :arg list instances: List of instances to be launched at the beginning of + the build. + + :instances: + * **cloud-name** (`str`) -- The name of the cloud profile which + contains the specified cloud instance template (required). + * **template-name** (`str`) -- The name of the cloud instance + template to create an instance from(required). + * **manual-template** (`bool`) -- If True, instance template name + will be put in 'Specify Template Name as String' option. Not + specifying or specifying False, instance template name will be + put in 'Select Template from List' option. To use parameter + replacement, set this to True. (default: False) + * **count** (`int`) -- How many instances to create (default: 1). + + :arg bool single-use: Whether or not to terminate the slave after use + (default: False). + + Example: + + .. literalinclude:: /../../tests/wrappers/fixtures/openstack001.yaml + """ + tag_prefix = 'jenkins.plugins.openstack.compute.' + + if 'instances' in data: + clouds_build_wrapper = XML.SubElement( + xml_parent, tag_prefix + 'JCloudsBuildWrapper') + instances_wrapper = XML.SubElement( + clouds_build_wrapper, 'instancesToRun') + + for instance in data['instances']: + instances_to_run = XML.SubElement( + instances_wrapper, tag_prefix + 'InstancesToRun') + + try: + cloud_name = instance['cloud-name'] + template_name = instance['template-name'] + except KeyError as exception: + raise MissingAttributeError(exception.args[0]) + + XML.SubElement(instances_to_run, 'cloudName').text = cloud_name + + if instance.get('manual-template', False): + XML.SubElement(instances_to_run, + 'manualTemplateName').text = template_name + else: + XML.SubElement(instances_to_run, + 'templateName').text = template_name + + XML.SubElement(instances_to_run, 'count').text = str( + instance.get('count', 1)) + + if data.get('single-use', False): + XML.SubElement(xml_parent, tag_prefix + 'JCloudsOneOffSlave') + + def build_user_vars(parser, xml_parent, data): """yaml: build-user-vars Set environment variables to the value of the user that started the build. diff --git a/tests/wrappers/fixtures/openstack001.xml b/tests/wrappers/fixtures/openstack001.xml new file mode 100644 index 000000000..2da93e389 --- /dev/null +++ b/tests/wrappers/fixtures/openstack001.xml @@ -0,0 +1,20 @@ + + + + + + + mycloud1 + jenkins-dev-slave + 1 + + + mycloud2 + jenkins-test-slave + 2 + + + + + + diff --git a/tests/wrappers/fixtures/openstack001.yaml b/tests/wrappers/fixtures/openstack001.yaml new file mode 100644 index 000000000..12113b3da --- /dev/null +++ b/tests/wrappers/fixtures/openstack001.yaml @@ -0,0 +1,11 @@ +wrappers: + - openstack: + instances: + - cloud-name: mycloud1 + template-name: jenkins-dev-slave + count: 1 + - cloud-name: mycloud2 + template-name: jenkins-test-slave + manual-template: True + count: 2 + single-use: True diff --git a/tests/wrappers/fixtures/openstack002.xml b/tests/wrappers/fixtures/openstack002.xml new file mode 100644 index 000000000..9889d1b63 --- /dev/null +++ b/tests/wrappers/fixtures/openstack002.xml @@ -0,0 +1,14 @@ + + + + + + + mycloud1 + jenkins-dev-slave + 1 + + + + + diff --git a/tests/wrappers/fixtures/openstack002.yaml b/tests/wrappers/fixtures/openstack002.yaml new file mode 100644 index 000000000..ac2c201de --- /dev/null +++ b/tests/wrappers/fixtures/openstack002.yaml @@ -0,0 +1,6 @@ +wrappers: + - openstack: + instances: + - cloud-name: mycloud1 + template-name: jenkins-dev-slave + count: 1 diff --git a/tests/wrappers/fixtures/openstack003.xml b/tests/wrappers/fixtures/openstack003.xml new file mode 100644 index 000000000..fa05ab93f --- /dev/null +++ b/tests/wrappers/fixtures/openstack003.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/wrappers/fixtures/openstack003.yaml b/tests/wrappers/fixtures/openstack003.yaml new file mode 100644 index 000000000..ed7320b40 --- /dev/null +++ b/tests/wrappers/fixtures/openstack003.yaml @@ -0,0 +1,3 @@ +wrappers: + - openstack: + single-use: True