Catch ConnectionError from CDash reporter (#24818)

* Catch ConnectionError from CDash reporter

Catch ConnectionError when attempting to upload the results of `spack install`
to CDash. This follows in the spirit of #24299. We do not want `spack install`
to exit with a non-zero status when something goes wrong while attempting to
report results to CDash.

* Catch HTTP Error 400 (Bad Request) in relate_cdash_builds()
This commit is contained in:
Zack Galbreath 2021-07-29 15:46:17 -04:00 committed by GitHub
parent 095f327f32
commit d7771f190f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 23 deletions

View File

@ -1316,6 +1316,7 @@ def relate_cdash_builds(spec_map, cdash_base_url, job_build_id, cdash_project,
request = Request(cdash_api_url, data=enc_data, headers=headers)
try:
response = opener.open(request)
response_code = response.getcode()
@ -1327,6 +1328,8 @@ def relate_cdash_builds(spec_map, cdash_base_url, job_build_id, cdash_project,
response_text = response.read()
tty.debug('Relate builds response: {0}'.format(response_text))
except Exception as e:
print("Relating builds in CDash failed: {0}".format(e))
def write_cdashid_to_mirror(cdashid, spec, mirror_url):

View File

@ -425,6 +425,7 @@ def upload(self, filename):
if self.authtoken:
request.add_header('Authorization',
'Bearer {0}'.format(self.authtoken))
try:
# By default, urllib2 only support GET and POST.
# CDash needs expects this file to be uploaded via PUT.
request.get_method = lambda: 'PUT'
@ -437,6 +438,8 @@ def upload(self, filename):
if match:
buildid = match.group(1)
self.buildIds[self.current_package_name] = buildid
except Exception as e:
print("Upload to CDash failed: {0}".format(e))
def finalize_report(self):
if self.buildIds:

View File

@ -12,7 +12,6 @@
import pytest
from six.moves import builtins
from six.moves.urllib.error import HTTPError, URLError
import llnl.util.filesystem as fs
@ -491,7 +490,7 @@ def test_cdash_upload_build_error(tmpdir, mock_fetch, install_mockery,
# capfd interferes with Spack's capturing
with capfd.disabled():
with tmpdir.as_cwd():
with pytest.raises((HTTPError, URLError)):
with pytest.raises(SpackError):
install(
'--log-format=cdash',
'--log-file=cdash_reports',