From 6de1ebd71a05d28c04e2ad5c0ec1755e3ced9136 Mon Sep 17 00:00:00 2001 From: jnhealy2 Date: Thu, 19 Dec 2024 14:19:44 -0700 Subject: [PATCH] Fix silent error when reporting builds to CDash (#47939) * Fix silent error when reporting builds to CDash CDash has a 191 char maximum for build names. When this is exceeded, CDash silently fails to correctly process the reported XML. This truncates CDash build names to 190 chars and emits a warning indicating it is doing so to prevent such errors from occuring. * test/reporters.py: add unittest for buildname len issue * test/reporters.py: rename cdash buildname test * ci/common.py: fix syntax causing breaking test It appears that the CDash reporter is expecting a string as the buildname. * Update lib/spack/spack/reporters/cdash.py Fix warning message to reflect actual issue. Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> * ci/common.py: fix function call to actually call function --------- Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Co-authored-by: psakievich --- lib/spack/spack/ci/common.py | 4 ++-- lib/spack/spack/reporters/cdash.py | 7 ++++++- lib/spack/spack/test/reporters.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/ci/common.py b/lib/spack/spack/ci/common.py index 07bb7c5fd93..b014e1b9572 100644 --- a/lib/spack/spack/ci/common.py +++ b/lib/spack/spack/ci/common.py @@ -217,7 +217,7 @@ def args(self): "--cdash-upload-url", win_quote(self.upload_url), "--cdash-build", - win_quote(self.build_name), + win_quote(self.build_name()), "--cdash-site", win_quote(self.site), "--cdash-buildstamp", @@ -351,7 +351,7 @@ def report_skipped(self, spec: spack.spec.Spec, report_dir: str, reason: Optiona configuration = CDashConfiguration( upload_url=self.upload_url, packages=[spec.name], - build=self.build_name, + build=self.build_name(), site=self.site, buildstamp=self.build_stamp, track=None, diff --git a/lib/spack/spack/reporters/cdash.py b/lib/spack/spack/reporters/cdash.py index 0405b3224fa..209876175b8 100644 --- a/lib/spack/spack/reporters/cdash.py +++ b/lib/spack/spack/reporters/cdash.py @@ -10,6 +10,7 @@ import re import socket import time +import warnings import xml.sax.saxutils from typing import Dict, Optional from urllib.parse import urlencode @@ -123,11 +124,15 @@ def __init__(self, configuration: CDashConfiguration): self.multiple_packages = False def report_build_name(self, pkg_name): - return ( + buildname = ( "{0} - {1}".format(self.base_buildname, pkg_name) if self.multiple_packages else self.base_buildname ) + if len(buildname) > 190: + warnings.warn("Build name exceeds CDash 190 character maximum and will be truncated.") + buildname = buildname[:190] + return buildname def build_report_for_package(self, report_dir, package, duration): if "stdout" not in package: diff --git a/lib/spack/spack/test/reporters.py b/lib/spack/spack/test/reporters.py index 55ab019a8a4..41271559a4e 100644 --- a/lib/spack/spack/test/reporters.py +++ b/lib/spack/spack/test/reporters.py @@ -179,3 +179,22 @@ def upload(*args, **kwargs): err = capfd.readouterr()[1] assert "Skipping report for" in err assert "No generated output" in err + + +def test_cdash_reporter_truncates_build_name_if_too_long(): + build_name = "a" * 190 + extra_long_build_name = build_name + "a" + configuration = CDashConfiguration( + upload_url="https://fake-upload", + packages="fake-package", + build=extra_long_build_name, + site="fake-site", + buildstamp=None, + track="fake-track", + ) + + reporter = CDash(configuration=configuration) + new_build_name = reporter.report_build_name("fake-package") + + assert new_build_name != extra_long_build_name + assert new_build_name == build_name