From 30eda8b837940a884cdad850ff6c6e259d450a16 Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Tue, 6 Nov 2018 19:09:47 -0500 Subject: cdash: report clean results to CDash server (#9564) * Record stdout for packages without errors Previously our reporter only stored stdout if something went wrong while installing a package. This prevented us from properly reporting on steps where everything went as expected. * More robustly report all phases to CDash Previously if a phase generated no output it would not be reported to CDash. For example, consider the following output: ==> Executing phase: 'configure' ==> Executing phase: 'build' This would not generate a report for the configure phase. Now it does. * Add test case for CDash reporting clean builds * Fix default directory for CDash reports The default 'cdash_report' directory name was getting overwritten by 'junit-report'. * Upload the build phase first to CDash Older versions of CDash expect Build.xml to be the first file uploaded for any given build. * Define cdash_phase before referring to it --- lib/spack/spack/cmd/install.py | 2 +- lib/spack/spack/report.py | 1 + lib/spack/spack/reporters/cdash.py | 27 ++++++++++++++++----------- lib/spack/spack/test/cmd/install.py | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index b0165c8c30..733f29361b 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -213,7 +213,7 @@ def install(parser, args, **kwargs): if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') - if not args.log_file: + if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter: diff --git a/lib/spack/spack/report.py b/lib/spack/spack/report.py index 0c54e75a46..74e5caf194 100644 --- a/lib/spack/spack/report.py +++ b/lib/spack/spack/report.py @@ -135,6 +135,7 @@ class InfoCollector(object): value = do_install(pkg, *args, **kwargs) package['result'] = 'success' + package['stdout'] = fetch_package_log(pkg) if installed_on_entry: return diff --git a/lib/spack/spack/reporters/cdash.py b/lib/spack/spack/reporters/cdash.py index 16251ce7c7..e27d7e9728 100644 --- a/lib/spack/spack/reporters/cdash.py +++ b/lib/spack/spack/reporters/cdash.py @@ -81,6 +81,7 @@ class CDash(Reporter): for package in spec['packages']: if 'stdout' in package: current_phase = '' + cdash_phase = '' for line in package['stdout'].splitlines(): match = phase_regexp.search(line) if match: @@ -88,20 +89,24 @@ class CDash(Reporter): if current_phase not in map_phases_to_cdash: current_phase = '' continue - beginning_of_phase = True - else: - if beginning_of_phase: - cdash_phase = \ - map_phases_to_cdash[current_phase] - if cdash_phase not in phases_encountered: - phases_encountered.append(cdash_phase) - report_data[cdash_phase]['log'] += \ - text_type("{0} output for {1}:\n".format( - cdash_phase, package['name'])) - beginning_of_phase = False + cdash_phase = \ + map_phases_to_cdash[current_phase] + if cdash_phase not in phases_encountered: + phases_encountered.append(cdash_phase) + report_data[cdash_phase]['log'] += \ + text_type("{0} output for {1}:\n".format( + cdash_phase, package['name'])) + elif cdash_phase: report_data[cdash_phase]['log'] += \ xml.sax.saxutils.escape(line) + "\n" + # Move the build phase to the front of the list if it occurred. + # This supports older versions of CDash that expect this phase + # to be reported before all others. + if "build" in phases_encountered: + build_pos = phases_encountered.index("build") + phases_encountered.insert(0, phases_encountered.pop(build_pos)) + for phase in phases_encountered: errors, warnings = parse_log_events( report_data[phase]['log'].splitlines()) diff --git a/lib/spack/spack/test/cmd/install.py b/lib/spack/spack/test/cmd/install.py index 3a3280ce4b..904472f243 100644 --- a/lib/spack/spack/test/cmd/install.py +++ b/lib/spack/spack/test/cmd/install.py @@ -412,6 +412,26 @@ def test_cdash_upload_build_error(tmpdir, mock_fetch, install_mockery, assert 'configure: error: in /path/to/some/file:' in content +@pytest.mark.disable_clean_stage_check +def test_cdash_upload_clean_build(tmpdir, mock_fetch, install_mockery, + capfd): + # capfd interferes with Spack's capturing + with capfd.disabled(): + with tmpdir.as_cwd(): + with pytest.raises((HTTPError, URLError)): + install( + '--log-file=cdash_reports', + '--cdash-upload-url=http://localhost/fakeurl/submit.php?project=Spack', + 'a') + report_dir = tmpdir.join('cdash_reports') + assert report_dir in tmpdir.listdir() + report_file = report_dir.join('Build.xml') + assert report_file in report_dir.listdir() + content = report_file.open().read() + assert '' in content + assert '' not in content + + @pytest.mark.disable_clean_stage_check def test_build_error_output(tmpdir, mock_fetch, install_mockery, capfd): with capfd.disabled(): -- cgit v1.2.3-70-g09d2