From 2cc993a0d5891fa9271b56fbe91fa5aef230747c Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Sun, 8 Sep 2013 16:32:35 +0100 Subject: [PATCH] Add code to download XML unit test reports --- tests/jenkins.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/jenkins.py b/tests/jenkins.py index 88262dc55a..fbd4c28d63 100644 --- a/tests/jenkins.py +++ b/tests/jenkins.py @@ -12,6 +12,7 @@ import re import sys import time import random +import shutil import hashlib import optparse import subprocess @@ -84,6 +85,43 @@ def echo_parseable_environment(platform, provider): sys.stdout.flush() +def download_unittest_reports(vm_name): + if os.path.isdir('xml-test-reports'): + shutil.rmtree('xml-test-reports') + + os.makedirs('xml-test-reports') + + cmds = ( + 'salt {0} archive.tar zcvf /tmp/xml-test-reports.tar.gz \'*.xml\' ' + 'cwd=/tmp/salt-tests-tmpdir/xml-test-reports/', + 'salt {0} cp.push /tmp/xml-test-reports.tar.gz', + 'tar zxvf /var/cache/salt/master/minions/{0}/files/tmp/' + 'xml-test-reports.tar.gz -C xml-test-reports', + 'rm /var/cache/salt/master/minions/{0}/files/tmp/' + 'xml-test-reports.tar.gz' + ) + + for cmd in cmds: + print('Running CMD: {0}'.format(cmd.format(vm_name))) + sys.stdout.flush() + + proc = NonBlockingPopen( + cmd.format(vm_name), + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + stream_stds=True + ) + proc.poll_and_read_until_finish() + proc.communicate() + if proc.returncode != 0: + print( + 'Failed to download unittest data: Exit code: {0}'.format( + proc.returncode + ) + ) + + def run(opts): ''' RUN! @@ -214,6 +252,11 @@ def parse(): default=os.environ.get('JENKINS_SALTCLOUD_VM_NAME', None), help='Delete a running VM' ) + parser.add_option( + '--download-unittest-reports', + default=os.environ.get('JENKINS_SALTCLOUD_VM_NAME', None), + help='Delete a running VM' + ) options, args = parser.parse_args() @@ -221,6 +264,10 @@ def parse(): delete_vm(options.delete_vm) parser.exit(0) + if options.download_unittest_reports is not None and not options.commit: + download_unittest_reports(options.download_unittest_reports) + parser.exit(0) + if not options.platform: parser.exit('--platform is required')