From cc96758fdc933b1e0801cca4bc8543729f384421 Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Mon, 30 Dec 2019 18:54:56 -0500 Subject: Add support for authenticated CDash uploads (#14200) --- lib/spack/spack/cmd/install.py | 9 ++++++++- lib/spack/spack/report.py | 3 ++- lib/spack/spack/reporters/cdash.py | 13 ++++++++++++- lib/spack/spack/test/cmd/install.py | 13 +++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index f39522ff59..d4e011b142 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -7,6 +7,7 @@ import argparse import os import shutil import sys +import textwrap import llnl.util.filesystem as fs import llnl.util.tty as tty @@ -246,7 +247,13 @@ def install_spec(cli_args, kwargs, abstract_spec, spec): def install(parser, args, **kwargs): if args.help_cdash: - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=textwrap.dedent('''\ +environment variables: + SPACK_CDASH_AUTH_TOKEN + authentication token to present to CDash + ''')) add_cdash_args(parser, True) parser.print_help() return diff --git a/lib/spack/spack/report.py b/lib/spack/spack/report.py index 292eeffd8c..a958ae1d03 100644 --- a/lib/spack/spack/report.py +++ b/lib/spack/spack/report.py @@ -146,8 +146,9 @@ class InfoCollector(object): # An InstallError is considered a failure (the recipe # didn't work correctly) package['result'] = 'failure' - package['stdout'] = fetch_package_log(pkg) package['message'] = e.message or 'Installation failure' + package['stdout'] = fetch_package_log(pkg) + package['stdout'] += package['message'] package['exception'] = e.traceback except (Exception, BaseException) as e: diff --git a/lib/spack/spack/reporters/cdash.py b/lib/spack/spack/reporters/cdash.py index 592209aca4..cc0b6c1500 100644 --- a/lib/spack/spack/reporters/cdash.py +++ b/lib/spack/spack/reporters/cdash.py @@ -17,6 +17,7 @@ from six.moves.urllib.request import build_opener, HTTPHandler, Request from six.moves.urllib.parse import urlencode from llnl.util.filesystem import working_dir +import llnl.util.tty as tty from ordereddict_backport import OrderedDict import spack.build_environment import spack.fetch_strategy @@ -58,6 +59,7 @@ class CDash(Reporter): def __init__(self, args): Reporter.__init__(self, args) + tty.set_verbose(args.verbose) self.template_dir = os.path.join('reports', 'cdash') self.cdash_upload_url = args.cdash_upload_url @@ -65,6 +67,11 @@ class CDash(Reporter): self.buildid_regexp = re.compile("([0-9]+)") self.phase_regexp = re.compile(r"Executing phase: '(.*)'") + self.authtoken = None + if 'SPACK_CDASH_AUTH_TOKEN' in os.environ: + tty.verbose("Using CDash auth token from environment") + self.authtoken = os.environ.get('SPACK_CDASH_AUTH_TOKEN') + if args.package: packages = args.package else: @@ -225,7 +232,8 @@ class CDash(Reporter): # from the binary cache. spec['packages'] = [ x for x in spec['packages'] - if not x['installed_from_binary_cache'] + if 'installed_from_binary_cache' not in x or + not x['installed_from_binary_cache'] ] for package in spec['packages']: if 'stdout' in package: @@ -297,6 +305,9 @@ class CDash(Reporter): request = Request(url, data=f) request.add_header('Content-Type', 'text/xml') request.add_header('Content-Length', os.path.getsize(filename)) + if self.authtoken: + request.add_header('Authorization', + 'Bearer {0}'.format(self.authtoken)) # By default, urllib2 only support GET and POST. # CDash needs expects this file to be uploaded via PUT. request.get_method = lambda: 'PUT' diff --git a/lib/spack/spack/test/cmd/install.py b/lib/spack/spack/test/cmd/install.py index e8240a87b1..05f9eaae98 100644 --- a/lib/spack/spack/test/cmd/install.py +++ b/lib/spack/spack/test/cmd/install.py @@ -673,3 +673,16 @@ def test_install_help_cdash(capsys): install_cmd = SpackCommand('install') out = install_cmd('--help-cdash') assert 'CDash URL' in out + + +@pytest.mark.disable_clean_stage_check +def test_cdash_auth_token(tmpdir, capfd): + # capfd interferes with Spack's capturing + with capfd.disabled(): + os.environ['SPACK_CDASH_AUTH_TOKEN'] = 'asdf' + out = install( + '-v', + '--log-file=cdash_reports', + '--log-format=cdash', + 'a') + assert 'Using CDash auth token from environment' in out -- cgit v1.2.3-70-g09d2