From 4f183cdb1b89477065ce7cbd5b40ba67f27f7fdb Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Tue, 18 Oct 2016 00:49:36 -0700 Subject: [PATCH] Update performance plugin - update performance plugin to use convert xml - add new parameters for performance plugin - update test cases - add plugin="performance" attribute Change-Id: Ice3420d3413d85daf4e6f678011382788e2bdd97 --- jenkins_jobs/modules/publishers.py | 153 ++++++++++++------ .../fixtures/performance-complete.xml | 36 +++++ .../fixtures/performance-complete.yaml | 22 +++ .../fixtures/performance-minimal.xml | 23 +++ .../fixtures/performance-minimal.yaml | 2 + tests/publishers/fixtures/performance001.xml | 17 -- tests/publishers/fixtures/performance001.yaml | 7 - tests/publishers/fixtures/performance002.xml | 17 -- tests/publishers/fixtures/performance002.yaml | 7 - tests/publishers/fixtures/performance003.xml | 23 --- tests/publishers/fixtures/performance003.yaml | 9 -- 11 files changed, 190 insertions(+), 126 deletions(-) create mode 100644 tests/publishers/fixtures/performance-complete.xml create mode 100644 tests/publishers/fixtures/performance-complete.yaml create mode 100644 tests/publishers/fixtures/performance-minimal.xml create mode 100644 tests/publishers/fixtures/performance-minimal.yaml delete mode 100644 tests/publishers/fixtures/performance001.xml delete mode 100644 tests/publishers/fixtures/performance001.yaml delete mode 100644 tests/publishers/fixtures/performance002.xml delete mode 100644 tests/publishers/fixtures/performance002.yaml delete mode 100644 tests/publishers/fixtures/performance003.xml delete mode 100644 tests/publishers/fixtures/performance003.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 1a4ebf8eb..a080d815c 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -28,7 +28,6 @@ the build is complete. import logging import pkg_resources import random -import sys import xml.etree.ElementTree as XML import six @@ -2529,65 +2528,127 @@ def performance(registry, xml_parent, data): `. :arg int failed-threshold: Specify the error percentage threshold that - set the build failed. A negative value means - don't use this threshold (default 0) + set the build failed. A negative value means don't use this threshold + (default 0) :arg int unstable-threshold: Specify the error percentage threshold that - set the build unstable. A negative value means - don't use this threshold (default 0) + set the build unstable. A negative value means don't use this threshold + (default 0) + :arg str unstable-response-time-threshold: Average response time threshold + (default '') + :arg float failed-threshold-positive: Maximum failed percentage for build + comparison (default 0.0) + :arg float failed-threshold-negative: Minimum failed percentage for build + comparison (default 0.0) + :arg float unstable-threshold-positive: Maximum unstable percentage for + build comparison (default 0.0) + :arg float unstable-threshold-negative: Minimum unstable percentage for + build comparison (default 0.0) + :arg int nth-build-number: Build number for build comparison (default 0) + :arg bool mode-relative-thresholds: Relative threshold mode (default false) + :arg str config-type: Compare based on (default 'ART') + + :config-type values: + * **ART** -- Average Response Time + * **MRT** -- Median Response Time + * **PRT** -- Percentile Response Time + + :arg bool mode-of-threshold: Mode of threshold, true for relative threshold + and false for error threshold (default false) + :arg bool fail-build: Fail build when result files are not present + (default false) + :arg bool compare-build-previous: Compare with previous build + (default false) + :arg bool mode-performance-per-test-case: Performance Per Test Case Mode + (default true) + :arg bool mode-thoughput: Show Throughput Chart (default false) + :arg dict report: - :(jmeter or junit): (`dict` or `str`): Specify a custom report file + :(jmeter or junit): (`dict` or `str`): Specify a custom report file (optional; jmeter default \**/*.jtl, junit default **/TEST-\*.xml) - Examples: + Minimal Example: - .. literalinclude:: /../../tests/publishers/fixtures/performance001.yaml + .. literalinclude:: + /../../tests/publishers/fixtures/performance-minimal.yaml :language: yaml - .. literalinclude:: /../../tests/publishers/fixtures/performance002.yaml - :language: yaml + Full Example: - .. literalinclude:: /../../tests/publishers/fixtures/performance003.yaml + .. literalinclude:: + /../../tests/publishers/fixtures/performance-complete.yaml :language: yaml """ - logger = logging.getLogger(__name__) - perf = XML.SubElement(xml_parent, 'hudson.plugins.performance.' 'PerformancePublisher') - XML.SubElement(perf, 'errorFailedThreshold').text = str(data.get( - 'failed-threshold', 0)) - XML.SubElement(perf, 'errorUnstableThreshold').text = str(data.get( - 'unstable-threshold', 0)) + perf.set('plugin', 'performance') + types = ['ART', 'MRT', 'PRT'] + mappings = [ + ('failed-threshold', 'errorFailedThreshold', 0), + ('unstable-threshold', 'errorUnstableThreshold', 0), + ('unstable-response-time-threshold', + 'errorUnstableResponseTimeThreshold', + ''), + ('failed-threshold-positive', + 'relativeFailedThresholdPositive', + '0.0'), + ('failed-threshold-negative', + 'relativeFailedThresholdNegative', + '0.0'), + ('unstable-threshold-positive', + 'relativeUnstableThresholdPositive', + '0.0'), + ('unstable-threshold-negative', + 'relativeUnstableThresholdNegative', + '0.0'), + ('nth-build-number', 'nthBuildNumber', 0), + ('mode-relative-thresholds', 'modeRelativeThresholds', False), + ('config-type', 'configType', 'ART', types), + ('mode-of-threshold', 'modeOfThreshold', False), + ('fail-build', 'failBuildIfNoResultFile', False), + ('compare-build-previous', 'compareBuildPrevious', False), + ('mode-performance-per-test-case', 'modePerformancePerTestCase', True), + ('mode-thoughput', 'modeThroughput', False) + ] + helpers.convert_mapping_to_xml(perf, data, mappings, fail_required=True) + parsers = XML.SubElement(perf, 'parsers') - for item in data['report']: - if isinstance(item, dict): - item_name = next(iter(item.keys())) - item_values = item.get(item_name, None) - if item_name == 'jmeter': - jmhold = XML.SubElement(parsers, 'hudson.plugins.performance.' - 'JMeterParser') - XML.SubElement(jmhold, 'glob').text = str(item_values) - elif item_name == 'junit': - juhold = XML.SubElement(parsers, 'hudson.plugins.performance.' - 'JUnitParser') - XML.SubElement(juhold, 'glob').text = str(item_values) - else: - logger.fatal("You have not specified jmeter or junit, or " - "you have incorrectly assigned the key value.") - sys.exit(1) - elif isinstance(item, str): - if item == 'jmeter': - jmhold = XML.SubElement(parsers, 'hudson.plugins.performance.' - 'JMeterParser') - XML.SubElement(jmhold, 'glob').text = '**/*.jtl' - elif item == 'junit': - juhold = XML.SubElement(parsers, 'hudson.plugins.performance.' - 'JUnitParser') - XML.SubElement(juhold, 'glob').text = '**/TEST-*.xml' - else: - logger.fatal("You have not specified jmeter or junit, or " - "you have incorrectly assigned the key value.") - sys.exit(1) + if 'report' in data: + for item in data['report']: + if isinstance(item, dict): + item_name = next(iter(item.keys())) + item_values = item.get(item_name, None) + if item_name == 'jmeter': + jmhold = XML.SubElement(parsers, 'hudson.plugins.' + 'performance.' + 'JMeterParser') + XML.SubElement(jmhold, 'glob').text = str(item_values) + elif item_name == 'junit': + juhold = XML.SubElement(parsers, 'hudson.plugins.' + 'performance.' + 'JUnitParser') + XML.SubElement(juhold, 'glob').text = str(item_values) + else: + raise JenkinsJobsException("You have not specified jmeter " + "or junit, or you have " + "incorrectly assigned the key " + "value.") + elif isinstance(item, str): + if item == 'jmeter': + jmhold = XML.SubElement(parsers, 'hudson.plugins.' + 'performance.' + 'JMeterParser') + XML.SubElement(jmhold, 'glob').text = '**/*.jtl' + elif item == 'junit': + juhold = XML.SubElement(parsers, 'hudson.plugins.' + 'performance.' + 'JUnitParser') + XML.SubElement(juhold, 'glob').text = '**/TEST-*.xml' + else: + raise JenkinsJobsException("You have not specified jmeter " + "or junit, or you have " + "incorrectly assigned the key " + "value.") def join_trigger(registry, xml_parent, data): diff --git a/tests/publishers/fixtures/performance-complete.xml b/tests/publishers/fixtures/performance-complete.xml new file mode 100644 index 000000000..8ef80d075 --- /dev/null +++ b/tests/publishers/fixtures/performance-complete.xml @@ -0,0 +1,36 @@ + + + + + 85 + -1 + JMeterResultsOrders.jtl:2000 + 90.0 + 10.0 + 80.0 + 20.0 + 10 + true + PRT + true + true + true + false + true + + + /special/file.jtl + + + /special/file.xml + + + **/*.jtl + + + **/TEST-*.xml + + + + + diff --git a/tests/publishers/fixtures/performance-complete.yaml b/tests/publishers/fixtures/performance-complete.yaml new file mode 100644 index 000000000..ff2839129 --- /dev/null +++ b/tests/publishers/fixtures/performance-complete.yaml @@ -0,0 +1,22 @@ +publishers: + - performance: + failed-threshold: 85 + unstable-threshold: -1 + unstable-response-time-threshold: "JMeterResultsOrders.jtl:2000" + failed-threshold-positive: 90.0 + failed-threshold-negative: 10.0 + unstable-threshold-positive: 80.0 + unstable-threshold-negative: 20.0 + nth-build-number: 10 + mode-relative-thresholds: true + config-type: "PRT" + mode-of-threshold: true + fail-build: true + compare-build-previous: true + mode-performance-per-test-case: false + mode-thoughput: true + report: + - jmeter: "/special/file.jtl" + - junit: "/special/file.xml" + - jmeter + - junit diff --git a/tests/publishers/fixtures/performance-minimal.xml b/tests/publishers/fixtures/performance-minimal.xml new file mode 100644 index 000000000..126efd386 --- /dev/null +++ b/tests/publishers/fixtures/performance-minimal.xml @@ -0,0 +1,23 @@ + + + + + 0 + 0 + + 0.0 + 0.0 + 0.0 + 0.0 + 0 + false + ART + false + false + false + true + false + + + + diff --git a/tests/publishers/fixtures/performance-minimal.yaml b/tests/publishers/fixtures/performance-minimal.yaml new file mode 100644 index 000000000..bedf02bbc --- /dev/null +++ b/tests/publishers/fixtures/performance-minimal.yaml @@ -0,0 +1,2 @@ +publishers: + - performance diff --git a/tests/publishers/fixtures/performance001.xml b/tests/publishers/fixtures/performance001.xml deleted file mode 100644 index 5419d025c..000000000 --- a/tests/publishers/fixtures/performance001.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - 85 - -1 - - - /special/file.jtl - - - /special/file.xml - - - - - diff --git a/tests/publishers/fixtures/performance001.yaml b/tests/publishers/fixtures/performance001.yaml deleted file mode 100644 index 5e717cb8d..000000000 --- a/tests/publishers/fixtures/performance001.yaml +++ /dev/null @@ -1,7 +0,0 @@ -publishers: - - performance: - failed-threshold: 85 - unstable-threshold: -1 - report: - - jmeter: "/special/file.jtl" - - junit: "/special/file.xml" diff --git a/tests/publishers/fixtures/performance002.xml b/tests/publishers/fixtures/performance002.xml deleted file mode 100644 index 7f7d5f061..000000000 --- a/tests/publishers/fixtures/performance002.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - 85 - -1 - - - **/*.jtl - - - **/TEST-*.xml - - - - - diff --git a/tests/publishers/fixtures/performance002.yaml b/tests/publishers/fixtures/performance002.yaml deleted file mode 100644 index b970cd98c..000000000 --- a/tests/publishers/fixtures/performance002.yaml +++ /dev/null @@ -1,7 +0,0 @@ -publishers: - - performance: - failed-threshold: 85 - unstable-threshold: -1 - report: - - jmeter - - junit diff --git a/tests/publishers/fixtures/performance003.xml b/tests/publishers/fixtures/performance003.xml deleted file mode 100644 index b7acfb199..000000000 --- a/tests/publishers/fixtures/performance003.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - 85 - -1 - - - /special/file.jtl - - - /special/file.xml - - - **/*.jtl - - - **/TEST-*.xml - - - - - diff --git a/tests/publishers/fixtures/performance003.yaml b/tests/publishers/fixtures/performance003.yaml deleted file mode 100644 index 478c4e281..000000000 --- a/tests/publishers/fixtures/performance003.yaml +++ /dev/null @@ -1,9 +0,0 @@ -publishers: - - performance: - failed-threshold: 85 - unstable-threshold: -1 - report: - - jmeter: "/special/file.jtl" - - junit: "/special/file.xml" - - jmeter - - junit