Update build_keeper to use convert_mapping_to_xml()

Change-Id: I2cd89c84b308013b16915834af9c037d856fe026
This commit is contained in:
Yolande Amate 2017-07-04 02:08:31 +01:00
parent e3e5a8aabe
commit c4f56f961b

@ -494,50 +494,43 @@ def build_keeper(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/build-keeper0002.yaml
"""
root = XML.SubElement(xml_parent,
'org.jenkins__ci.plugins.build__keeper.BuildKeeper')
valid_policies = ('by-day', 'keep-since', 'build-number',
'keep-first-failed')
policy = data.get('policy')
build_period = str(data.get('build-period', 0))
dont_keep_failed = str(data.get('dont-keep-failed', False)).lower()
mapping = [
('build-period', 'buildPeriod', 0),
('dont-keep-failed', 'dontKeepFailed', False)]
if policy == 'by-day':
policy_element = XML.SubElement(root,
'policy',
{'class': 'org.jenkins_ci.plugins.'
'build_keeper.ByDayPolicy'})
XML.SubElement(policy_element, 'buildPeriod').text = build_period
XML.SubElement(policy_element,
'dontKeepFailed').text = dont_keep_failed
elif policy == 'keep-since':
policy_element = XML.SubElement(root,
'policy',
{'class': 'org.jenkins_ci.plugins.'
'build_keeper.KeepSincePolicy'})
XML.SubElement(policy_element, 'buildPeriod').text = build_period
XML.SubElement(policy_element,
'dontKeepFailed').text = dont_keep_failed
elif policy == 'build-number':
policy_element = XML.SubElement(root,
'policy',
{'class': 'org.jenkins_ci.plugins.'
'build_keeper.BuildNumberPolicy'})
XML.SubElement(policy_element, 'buildPeriod').text = build_period
XML.SubElement(policy_element,
'dontKeepFailed').text = dont_keep_failed
elif policy == 'keep-first-failed':
policy_element = XML.SubElement(root,
'policy',
{'class': 'org.jenkins_ci.plugins.'
'build_keeper.KeepFirstFailedPolicy'})
XML.SubElement(policy_element, 'numberOfFails').text = str(
data.get('number-of-fails', 0))
mapping = [('number-of-fails', 'numberOfFails', 0)]
else:
InvalidAttributeError('policy', policy, valid_policies)
convert_mapping_to_xml(policy_element, data, mapping, fail_required=True)
def live_screenshot(registry, xml_parent, data):
"""yaml: live-screenshot