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 <psakiev@sandia.gov>
This commit is contained in:
jnhealy2 2024-12-19 14:19:44 -07:00 committed by GitHub
parent fd865efe87
commit 6de1ebd71a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 3 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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