spack mirror: skip non-concretizable specs (#31897)

fixes #31736

Catch errors when concretizing specs and report them as
debug messages. The corresponding spec is skipped.

Co-authored-by: Greg Becker <becker33@llnl.gov>
This commit is contained in:
Massimiliano Culpo 2022-08-05 19:19:51 +02:00 committed by GitHub
parent fefab26f01
commit 65a4125dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -632,9 +632,26 @@ def error(self):
def _add_single_spec(spec, mirror, mirror_stats):
"""Add a single spec to a mirror.
Args:
spec (spack.spec.Spec): spec to be added. If not concrete it will
be concretized.
mirror (spack.mirror.Mirror): mirror where to add the spec.
mirror_stats (spack.mirror.MirrorStats): statistics on the current mirror
Return:
True if the spec was added successfully, False otherwise
"""
# Ensure that the spec is concrete, since we'll stage it later
if not spec.concrete:
spec = spec.concretized()
try:
if not spec.concrete:
spec = spec.concretized()
except Exception as e:
msg = "Skipping '{0}', as it fails to concretize [{1}]".format(spec, str(e))
tty.debug(msg)
mirror_stats.error()
return False
tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("{name}{@version}")))
num_retries = 3
@ -662,6 +679,9 @@ def _add_single_spec(spec, mirror, mirror_stats):
getattr(exception, "message", exception),
)
mirror_stats.error()
return False
return True
def push_url_from_directory(output_directory):

View File

@ -311,3 +311,19 @@ def test_get_all_versions(specs, expected_specs):
output_list = [str(x) for x in output_list]
# Compare sets since order is not important
assert set(output_list) == set(expected_specs)
@pytest.mark.regression("31736")
def test_non_concretizable_spec_does_not_raise():
s = Spec("doesnotexist")
class Stats(object):
called = False
def error(self):
self.called = True
mirror_stats = Stats()
result = spack.mirror._add_single_spec(s, mirror=None, mirror_stats=mirror_stats)
assert result is False
assert mirror_stats.called is True