From 14f3297ccaa8c98b04783397803e46d97f59d5e6 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 18 Jul 2023 23:49:22 +0200 Subject: Ensure the bootstrap store has a padding length of zero (#38975) Without this PR, padded length was propagating from user configuration to bootstrap configuration, and was causing the issue reported in #38963 --- lib/spack/spack/bootstrap/config.py | 8 +++---- lib/spack/spack/test/bootstrap.py | 35 +++++++++++++++++++----------- share/spack/templates/bootstrap/spack.yaml | 1 + 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/spack/spack/bootstrap/config.py b/lib/spack/spack/bootstrap/config.py index 1753810a93..0223024909 100644 --- a/lib/spack/spack/bootstrap/config.py +++ b/lib/spack/spack/bootstrap/config.py @@ -155,13 +155,13 @@ def _ensure_bootstrap_configuration() -> Generator: with spack.environment.no_active_environment(): with spack.platforms.prevent_cray_detection(), spack.platforms.use_platform( spack.platforms.real_host() - ), spack.repo.use_repositories(spack.paths.packages_path), spack.store.use_store( - bootstrap_store_path - ): + ), spack.repo.use_repositories(spack.paths.packages_path): # Default configuration scopes excluding command line # and builtin but accounting for platform specific scopes config_scopes = _bootstrap_config_scopes() - with spack.config.use_configuration(*config_scopes): + with spack.config.use_configuration(*config_scopes), spack.store.use_store( + bootstrap_store_path, extra_data={"padded_length": 0} + ): # We may need to compile code from sources, so ensure we # have compilers for the current platform _add_compilers_if_missing() diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py index 3d1a066d88..d19807457f 100644 --- a/lib/spack/spack/test/bootstrap.py +++ b/lib/spack/spack/test/bootstrap.py @@ -22,20 +22,29 @@ def active_mock_environment(mutable_config, mutable_mock_env_path): @pytest.mark.regression("22294") def test_store_is_restored_correctly_after_bootstrap(mutable_config, tmpdir): - # Prepare a custom store path. This should be in a writeable location - # since Spack needs to initialize the DB. + """Tests that the store is correctly swapped during bootstrapping, and restored afterward.""" user_path = str(tmpdir.join("store")) - # Reassign global variables in spack.store to the value - # they would have at Spack startup. - spack.store.reinitialize() - # Set the custom user path - spack.config.set("config:install_tree:root", user_path) - - # Test that within the context manager we use the bootstrap store - # and that outside we restore the correct location - with spack.bootstrap.ensure_bootstrap_configuration(): - assert spack.store.root == spack.bootstrap.config.store_path() - assert spack.store.root == user_path + with spack.store.use_store(user_path): + assert spack.store.root == user_path + assert spack.config.config.get("config:install_tree:root") == user_path + with spack.bootstrap.ensure_bootstrap_configuration(): + assert spack.store.root == spack.bootstrap.config.store_path() + assert spack.store.root == user_path + assert spack.config.config.get("config:install_tree:root") == user_path + + +@pytest.mark.regression("38963") +def test_store_padding_length_is_zero_during_bootstrapping(mutable_config, tmpdir): + """Tests that, even though padded length is set in user config, the bootstrap store maintains + a padded length of zero. + """ + user_path = str(tmpdir.join("store")) + with spack.store.use_store(user_path, extra_data={"padded_length": 512}): + assert spack.config.config.get("config:install_tree:padded_length") == 512 + with spack.bootstrap.ensure_bootstrap_configuration(): + assert spack.store.root == spack.bootstrap.config.store_path() + assert spack.config.config.get("config:install_tree:padded_length") == 0 + assert spack.config.config.get("config:install_tree:padded_length") == 512 @pytest.mark.parametrize( diff --git a/share/spack/templates/bootstrap/spack.yaml b/share/spack/templates/bootstrap/spack.yaml index 4573bb485e..251977d0c5 100644 --- a/share/spack/templates/bootstrap/spack.yaml +++ b/share/spack/templates/bootstrap/spack.yaml @@ -15,6 +15,7 @@ spack: config: install_tree: root: {{ store_path }} + padded_length: 0 packages: python: -- cgit v1.2.3-60-g2f50