From 828baa7d3eedbec22d2c79c7fc257907b66b9d9a Mon Sep 17 00:00:00 2001 From: Yolande Amate Date: Tue, 4 Jul 2017 02:38:22 +0100 Subject: [PATCH] Update openstack to use convert_mapping_to_xml() Change-Id: I29fdc553512f19c73aef88c42d72f8b5c3d9f003 --- jenkins_jobs/modules/wrappers.py | 22 ++++++++-------------- tests/wrappers/fixtures/openstack001.xml | 4 ++-- tests/wrappers/fixtures/openstack002.xml | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 17f45e7c9..84e6774df 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1144,23 +1144,17 @@ def openstack(registry, xml_parent, data): 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 + instance_mapping = [('cloud-name', 'cloudName', None), + ('count', 'count', 1)] if instance.get('manual-template', False): - XML.SubElement(instances_to_run, - 'manualTemplateName').text = template_name + instance_mapping.append(('template-name', + 'manualTemplateName', None)) else: - XML.SubElement(instances_to_run, - 'templateName').text = template_name - - XML.SubElement(instances_to_run, 'count').text = str( - instance.get('count', 1)) + instance_mapping.append(('template-name', + 'templateName', None)) + convert_mapping_to_xml(instances_to_run, + instance, instance_mapping, fail_required=True) if data.get('single-use', False): XML.SubElement(xml_parent, tag_prefix + 'JCloudsOneOffSlave') diff --git a/tests/wrappers/fixtures/openstack001.xml b/tests/wrappers/fixtures/openstack001.xml index 2da93e389..9a73dc402 100644 --- a/tests/wrappers/fixtures/openstack001.xml +++ b/tests/wrappers/fixtures/openstack001.xml @@ -5,13 +5,13 @@ mycloud1 - jenkins-dev-slave 1 + jenkins-dev-slave mycloud2 - jenkins-test-slave 2 + jenkins-test-slave diff --git a/tests/wrappers/fixtures/openstack002.xml b/tests/wrappers/fixtures/openstack002.xml index 9889d1b63..702338e4d 100644 --- a/tests/wrappers/fixtures/openstack002.xml +++ b/tests/wrappers/fixtures/openstack002.xml @@ -5,8 +5,8 @@ mycloud1 - jenkins-dev-slave 1 + jenkins-dev-slave