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,17 +1316,20 @@ def relate_cdash_builds(spec_map, cdash_base_url, job_build_id, cdash_project,
request = Request(cdash_api_url, data=enc_data, headers=headers) request = Request(cdash_api_url, data=enc_data, headers=headers)
response = opener.open(request) try:
response_code = response.getcode() response = opener.open(request)
response_code = response.getcode()
if response_code != 200 and response_code != 201: if response_code != 200 and response_code != 201:
msg = 'Relate builds ({0} -> {1}) failed (resp code = {2})'.format( msg = 'Relate builds ({0} -> {1}) failed (resp code = {2})'.format(
job_build_id, dep_build_id, response_code) job_build_id, dep_build_id, response_code)
tty.warn(msg) tty.warn(msg)
return return
response_text = response.read() response_text = response.read()
tty.debug('Relate builds response: {0}'.format(response_text)) 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): def write_cdashid_to_mirror(cdashid, spec, mirror_url):

View File

@ -425,18 +425,21 @@ def upload(self, filename):
if self.authtoken: if self.authtoken:
request.add_header('Authorization', request.add_header('Authorization',
'Bearer {0}'.format(self.authtoken)) 'Bearer {0}'.format(self.authtoken))
# By default, urllib2 only support GET and POST. try:
# CDash needs expects this file to be uploaded via PUT. # By default, urllib2 only support GET and POST.
request.get_method = lambda: 'PUT' # CDash needs expects this file to be uploaded via PUT.
response = opener.open(request) request.get_method = lambda: 'PUT'
if self.current_package_name not in self.buildIds: response = opener.open(request)
resp_value = response.read() if self.current_package_name not in self.buildIds:
if isinstance(resp_value, bytes): resp_value = response.read()
resp_value = resp_value.decode('utf-8') if isinstance(resp_value, bytes):
match = self.buildid_regexp.search(resp_value) resp_value = resp_value.decode('utf-8')
if match: match = self.buildid_regexp.search(resp_value)
buildid = match.group(1) if match:
self.buildIds[self.current_package_name] = buildid 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): def finalize_report(self):
if self.buildIds: if self.buildIds:

View File

@ -12,7 +12,6 @@
import pytest import pytest
from six.moves import builtins from six.moves import builtins
from six.moves.urllib.error import HTTPError, URLError
import llnl.util.filesystem as fs 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 # capfd interferes with Spack's capturing
with capfd.disabled(): with capfd.disabled():
with tmpdir.as_cwd(): with tmpdir.as_cwd():
with pytest.raises((HTTPError, URLError)): with pytest.raises(SpackError):
install( install(
'--log-format=cdash', '--log-format=cdash',
'--log-file=cdash_reports', '--log-file=cdash_reports',