diff options
-rw-r--r-- | lib/spack/spack/bootstrap.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/test/bootstrap.py | 17 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py index 20668cf077..26080695ed 100644 --- a/lib/spack/spack/bootstrap.py +++ b/lib/spack/spack/bootstrap.py @@ -456,9 +456,10 @@ def _make_bootstrapper(conf): return _bootstrap_methods[btype](conf) -def _validate_source_is_trusted(conf): +def source_is_enabled_or_raise(conf): + """Raise ValueError if the source is not enabled for bootstrapping""" trusted, name = spack.config.get('bootstrap:trusted'), conf['name'] - if name not in trusted: + if not trusted.get(name, False): raise ValueError('source is not trusted') @@ -529,7 +530,7 @@ def ensure_module_importable_or_raise(module, abstract_spec=None): for current_config in bootstrapping_sources(): with h.forward(current_config['name']): - _validate_source_is_trusted(current_config) + source_is_enabled_or_raise(current_config) b = _make_bootstrapper(current_config) if b.try_import(module, abstract_spec): @@ -571,7 +572,7 @@ def ensure_executables_in_path_or_raise(executables, abstract_spec): for current_config in bootstrapping_sources(): with h.forward(current_config['name']): - _validate_source_is_trusted(current_config) + source_is_enabled_or_raise(current_config) b = _make_bootstrapper(current_config) if b.try_search_path(executables, abstract_spec): diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py index fcb3e6418e..183f0bc6f4 100644 --- a/lib/spack/spack/test/bootstrap.py +++ b/lib/spack/spack/test/bootstrap.py @@ -180,3 +180,20 @@ def test_status_function_find_files( _, missing = spack.bootstrap.status_message('optional') assert missing is expected_missing + + +@pytest.mark.regression('31042') +def test_source_is_disabled(mutable_config): + # Get the configuration dictionary of the current bootstrapping source + conf = next(iter(spack.bootstrap.bootstrapping_sources())) + + # The source is not explicitly enabled or disabled, so the following + # call should raise to skip using it for bootstrapping + with pytest.raises(ValueError): + spack.bootstrap.source_is_enabled_or_raise(conf) + + # Try to explicitly disable the source and verify that the behavior + # is the same as above + spack.config.add('bootstrap:trusted:{0}:{1}'.format(conf['name'], False)) + with pytest.raises(ValueError): + spack.bootstrap.source_is_enabled_or_raise(conf) |