diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 30ae3d870..03631f3b5 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -27,7 +27,6 @@ the build is complete. import logging import pkg_resources -import random import xml.etree.ElementTree as XML import six @@ -4199,12 +4198,14 @@ def plot(registry, xml_parent, data): Xpath which selects the values that should be plotted. - Example: + Minimal Example: - .. literalinclude:: /../../tests/publishers/fixtures/plot004.yaml + .. literalinclude:: /../../tests/publishers/fixtures/plot-minimal.yaml :language: yaml - .. literalinclude:: /../../tests/publishers/fixtures/plot005.yaml + Full Example: + + .. literalinclude:: /../../tests/publishers/fixtures/plot-full.yaml :language: yaml """ top = XML.SubElement(xml_parent, 'hudson.plugins.plot.PlotPublisher') @@ -4219,14 +4220,43 @@ def plot(registry, xml_parent, data): 'exclude-by-string': 'EXCLUDE_BY_STRING', 'include-by-column': 'INCLUDE_BY_COLUMN', 'exclude-by-column': 'EXCLUDE_BY_COLUMN'} + + style_list = ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', + 'stackedbar', 'stackedbar3d', 'waterfall'] + + plot_mappings = [ + ('title', 'title', ''), + ('yaxis', 'yaxis', ''), + ('width', 'width', '750'), + ('height', 'height', '450'), + ('csv-file-name', 'csvFileName', ''), + ('group', 'group', None), + ('use-description', 'useDescr', False), + ('exclude-zero-yaxis', 'exclZero', False), + ('logarithmic-yaxis', 'logarithmic', False), + ('keep-records', 'keepRecords', False), + ('num-builds', 'numBuilds', ''), + ('style', 'style', 'line', style_list), + ] + + plot_csv_mappings = [ + ('inclusion-flag', 'inclusionFlag', 'off', inclusion_dict), + ('exclude', 'exclusionValues', ''), + ('url', 'url', ''), + ('display-table', 'displayTableFlag', False) + ] + + plot_xml_mappings = [ + ('url', 'url', ''), + ('xpath', 'xpathString', ''), + ('xpath-type', 'nodeTypeString', 'node', xpath_dict) + ] + for plot in data: plugin = XML.SubElement(plots, 'hudson.plugins.plot.Plot') - XML.SubElement(plugin, 'title').text = plot.get('title', '') - XML.SubElement(plugin, 'yaxis').text = plot['yaxis'] - XML.SubElement(plugin, 'width').text = str(plot.get('width', '750')) - XML.SubElement(plugin, 'height').text = str(plot.get('height', '450')) - XML.SubElement(plugin, 'csvFileName').text = \ - plot.get('csv-file-name', '%s.csv' % random.randrange(2 << 32)) + helpers.convert_mapping_to_xml( + plugin, plot, plot_mappings, fail_required=True) + topseries = XML.SubElement(plugin, 'series') series = plot['series'] for serie in series: @@ -4240,56 +4270,19 @@ def plot(registry, xml_parent, data): if format_data == 'properties': XML.SubElement(subserie, 'label').text = serie.get('label', '') if format_data == 'csv': - inclusion_flag = serie.get('inclusion-flag', 'off') - if inclusion_flag not in inclusion_dict: - raise JenkinsJobsException("Inclusion flag result entered " - "is not valid, must be one of: " - "%s" - % ", ".join(inclusion_dict)) - XML.SubElement(subserie, 'inclusionFlag').text = \ - inclusion_dict.get(inclusion_flag) - XML.SubElement(subserie, 'exclusionValues').text = \ - serie.get('exclude', '') + helpers.convert_mapping_to_xml( + subserie, serie, plot_csv_mappings, fail_required=True) if serie.get('exclude', ''): exclude_strings = serie.get('exclude', '').split(',') exclusionset = XML.SubElement(subserie, 'strExclusionSet') for exclude_string in exclude_strings: XML.SubElement(exclusionset, 'string').text = \ exclude_string - XML.SubElement(subserie, 'url').text = serie.get('url', '') - XML.SubElement(subserie, 'displayTableFlag').text = \ - str(serie.get('display-table', False)).lower() if format_data == 'xml': - XML.SubElement(subserie, 'url').text = serie.get('url', '') - XML.SubElement(subserie, 'xpathString').text = \ - serie.get('xpath') - xpathtype = serie.get('xpath-type', 'node') - if xpathtype not in xpath_dict: - raise JenkinsJobsException("XPath result entered is not " - "valid, must be one of: %s" % - ", ".join(xpath_dict)) - XML.SubElement(subserie, 'nodeTypeString').text = \ - xpath_dict.get(xpathtype) + helpers.convert_mapping_to_xml( + subserie, serie, plot_xml_mappings, fail_required=True) XML.SubElement(subserie, 'fileType').text = serie.get('format') - mappings = [ - ('group', 'group', None), - ('use-description', 'useDescr', False), - ('exclude-zero-yaxis', 'exclZero', False), - ('logarithmic-yaxis', 'logarithmic', False), - ('keep-records', 'keepRecords', False), - ('num-builds', 'numBuilds', '')] - helpers.convert_mapping_to_xml( - plugin, plot, mappings, fail_required=True) - - style_list = ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', - 'stackedbar', 'stackedbar3d', 'waterfall'] - style = plot.get('style', 'line') - if style not in style_list: - raise JenkinsJobsException("style entered is not valid, must be " - "one of: %s" % ", ".join(style_list)) - XML.SubElement(plugin, 'style').text = style - def git(registry, xml_parent, data): """yaml: git diff --git a/tests/publishers/fixtures/plot-full.xml b/tests/publishers/fixtures/plot-full.xml new file mode 100644 index 000000000..e358c1fbe --- /dev/null +++ b/tests/publishers/fixtures/plot-full.xml @@ -0,0 +1,66 @@ + + + + + + + MyPlot + Y + 900 + 1000 + myplot.csv + PlotGroup + true + true + true + true + 1 + + + + graph-me-second.properties + + properties + + + graph-me-first.csv + INCLUDE_BY_STRING + Column 1,Column 2,Column 3 + http://srv1 + true + + Column 1 + Column 2 + Column 3 + + csv + + + + + MyPlot2 + Y + 750 + 450 + myplot2.csv + PlotGroup + false + false + false + false + + + + + graph-me-third.xml + http://srv2 + /* + STRING + xml + + + + + + + diff --git a/tests/publishers/fixtures/plot-full.yaml b/tests/publishers/fixtures/plot-full.yaml new file mode 100644 index 000000000..b690b8835 --- /dev/null +++ b/tests/publishers/fixtures/plot-full.yaml @@ -0,0 +1,36 @@ +publishers: + - plot: + - title: MyPlot + yaxis: Y + width: 900 + height: 1000 + csv-file-name: myplot.csv + group: PlotGroup + num-builds: '1' + style: line + exclude-zero-yaxis: true + logarithmic-yaxis: true + use-description: true + keep-records: true + series: + - file: graph-me-second.properties + label: MyLabel + format: properties + - file: graph-me-first.csv + url: 'http://srv1' + inclusion-flag: 'include-by-string' + exclude: 'Column 1,Column 2,Column 3' + display-table: true + format: csv + - title: MyPlot2 + yaxis: Y + csv-file-name: myplot2.csv + group: PlotGroup + style: bar + use-description: false + series: + - file: graph-me-third.xml + url: 'http://srv2' + format: xml + xpath-type: 'string' + xpath: '/*' diff --git a/tests/publishers/fixtures/plot-minimal.xml b/tests/publishers/fixtures/plot-minimal.xml new file mode 100644 index 000000000..b448574c3 --- /dev/null +++ b/tests/publishers/fixtures/plot-minimal.xml @@ -0,0 +1,33 @@ + + + + + + + + <yaxis/> + <width>750</width> + <height>450</height> + <csvFileName/> + <group>bench</group> + <useDescr>false</useDescr> + <exclZero>false</exclZero> + <logarithmic>false</logarithmic> + <keepRecords>false</keepRecords> + <numBuilds/> + <style>line</style> + <series> + <hudson.plugins.plot.CSVSeries> + <file>data.csv</file> + <inclusionFlag>OFF</inclusionFlag> + <exclusionValues/> + <url/> + <displayTableFlag>false</displayTableFlag> + <fileType>csv</fileType> + </hudson.plugins.plot.CSVSeries> + </series> + </hudson.plugins.plot.Plot> + </plots> + </hudson.plugins.plot.PlotPublisher> + </publishers> +</project> diff --git a/tests/publishers/fixtures/plot-minimal.yaml b/tests/publishers/fixtures/plot-minimal.yaml new file mode 100644 index 000000000..54bd3f0ac --- /dev/null +++ b/tests/publishers/fixtures/plot-minimal.yaml @@ -0,0 +1,7 @@ +publishers: + - plot: + - yaxis: '' + group: 'bench' + series: + - file: 'data.csv' + format: 'csv' diff --git a/tests/publishers/fixtures/plot001.xml b/tests/publishers/fixtures/plot001.xml index f0e9b8275..2bc9c3a84 100644 --- a/tests/publishers/fixtures/plot001.xml +++ b/tests/publishers/fixtures/plot001.xml @@ -9,6 +9,13 @@ <width>750</width> <height>450</height> <csvFileName>persisted.csv</csvFileName> + <group>bench</group> + <useDescr>false</useDescr> + <exclZero>false</exclZero> + <logarithmic>false</logarithmic> + <keepRecords>true</keepRecords> + <numBuilds/> + <style>line</style> <series> <hudson.plugins.plot.CSVSeries> <file>data.csv</file> @@ -19,13 +26,6 @@ <fileType>csv</fileType> </hudson.plugins.plot.CSVSeries> </series> - <group>bench</group> - <useDescr>false</useDescr> - <exclZero>false</exclZero> - <logarithmic>false</logarithmic> - <keepRecords>true</keepRecords> - <numBuilds/> - <style>line</style> </hudson.plugins.plot.Plot> </plots> </hudson.plugins.plot.PlotPublisher> diff --git a/tests/publishers/fixtures/plot002.xml b/tests/publishers/fixtures/plot002.xml index 21c0b5aa8..59e0ea72f 100644 --- a/tests/publishers/fixtures/plot002.xml +++ b/tests/publishers/fixtures/plot002.xml @@ -9,13 +9,6 @@ <width>750</width> <height>450</height> <csvFileName>persisted.csv</csvFileName> - <series> - <hudson.plugins.plot.PropertiesSeries> - <file>data.properties</file> - <label/> - <fileType>properties</fileType> - </hudson.plugins.plot.PropertiesSeries> - </series> <group>bench</group> <useDescr>false</useDescr> <exclZero>false</exclZero> @@ -23,6 +16,13 @@ <keepRecords>false</keepRecords> <numBuilds/> <style>line</style> + <series> + <hudson.plugins.plot.PropertiesSeries> + <file>data.properties</file> + <label/> + <fileType>properties</fileType> + </hudson.plugins.plot.PropertiesSeries> + </series> </hudson.plugins.plot.Plot> </plots> </hudson.plugins.plot.PlotPublisher> diff --git a/tests/publishers/fixtures/plot003.xml b/tests/publishers/fixtures/plot003.xml index e4f11d652..09b440962 100644 --- a/tests/publishers/fixtures/plot003.xml +++ b/tests/publishers/fixtures/plot003.xml @@ -9,6 +9,13 @@ <width>750</width> <height>450</height> <csvFileName>persisted.csv</csvFileName> + <group>bench</group> + <useDescr>false</useDescr> + <exclZero>false</exclZero> + <logarithmic>false</logarithmic> + <keepRecords>false</keepRecords> + <numBuilds/> + <style>line</style> <series> <hudson.plugins.plot.XMLSeries> <file>data.xml</file> @@ -18,13 +25,6 @@ <fileType>xml</fileType> </hudson.plugins.plot.XMLSeries> </series> - <group>bench</group> - <useDescr>false</useDescr> - <exclZero>false</exclZero> - <logarithmic>false</logarithmic> - <keepRecords>false</keepRecords> - <numBuilds/> - <style>line</style> </hudson.plugins.plot.Plot> </plots> </hudson.plugins.plot.PlotPublisher> diff --git a/tests/publishers/fixtures/plot004.xml b/tests/publishers/fixtures/plot004.xml index dd2c1eb78..29c7ec69c 100644 --- a/tests/publishers/fixtures/plot004.xml +++ b/tests/publishers/fixtures/plot004.xml @@ -9,6 +9,13 @@ <width>750</width> <height>450</height> <csvFileName>myplot.csv</csvFileName> + <group>PlotGroup</group> + <useDescr>false</useDescr> + <exclZero>true</exclZero> + <logarithmic>true</logarithmic> + <keepRecords>false</keepRecords> + <numBuilds/> + <style>line</style> <series> <hudson.plugins.plot.PropertiesSeries> <file>graph-me-second.properties</file> @@ -24,13 +31,6 @@ <fileType>csv</fileType> </hudson.plugins.plot.CSVSeries> </series> - <group>PlotGroup</group> - <useDescr>false</useDescr> - <exclZero>true</exclZero> - <logarithmic>true</logarithmic> - <keepRecords>false</keepRecords> - <numBuilds/> - <style>line</style> </hudson.plugins.plot.Plot> <hudson.plugins.plot.Plot> <title>MyPlot2 @@ -38,6 +38,13 @@ 750 450 myplot2.csv + PlotGroup + false + false + false + false + + graph-me-third.xml @@ -47,13 +54,6 @@ xml - PlotGroup - false - false - false - false - - diff --git a/tests/publishers/fixtures/plot005.xml b/tests/publishers/fixtures/plot005.xml index d8b8fd9e6..4a2d7be4e 100644 --- a/tests/publishers/fixtures/plot005.xml +++ b/tests/publishers/fixtures/plot005.xml @@ -9,21 +9,6 @@ 750 450 persisted.csv - - - data.csv - INCLUDE_BY_STRING - Column 1,Column 2,Column 3 - - Column 1 - Column 2 - Column 3 - - - false - csv - - bench false false @@ -31,6 +16,21 @@ false + + + data.csv + INCLUDE_BY_STRING + Column 1,Column 2,Column 3 + + false + + Column 1 + Column 2 + Column 3 + + csv + + diff --git a/tests/publishers/fixtures/plot006.xml b/tests/publishers/fixtures/plot006.xml index dc67a6e7c..9d7a65865 100644 --- a/tests/publishers/fixtures/plot006.xml +++ b/tests/publishers/fixtures/plot006.xml @@ -9,6 +9,13 @@ 900 1000 persisted.csv + bench + false + false + false + true + + data.csv @@ -19,13 +26,6 @@ csv - bench - false - false - false - true - -