Add guard-rail and unit-test (not working)

This commit is contained in:
psakiev 2022-11-08 22:41:09 -07:00
parent 0ac6dfa8f3
commit d50c8f1727
2 changed files with 29 additions and 1 deletions

View File

@ -1039,9 +1039,19 @@ def env_file_config_scope(self):
[spack.config.first_existing(self.raw_yaml, spack.schema.env.keys)],
)
def _check_disallowed_env_config_mods(scopes):
for scope in scopes:
with spack.config.override(scope):
if spack.config.get("config:environments_root"):
raise SpackEnvironmentError("Need a good message")
else:
spack.config.print_section("config")
def config_scopes(self):
"""A list of all configuration scopes for this environment."""
return self.included_config_scopes() + [self.env_file_config_scope()]
return _check_disallowed_env_config_mods(
self.included_config_scopes() + [self.env_file_config_scope()]
)
def destroy(self):
"""Remove this environment from Spack entirely."""

View File

@ -1463,3 +1463,21 @@ def test_environment_errors_if_root_missing(mutable_config, tmpdir):
with pytest.raises(ev.SpackEnvironmentError, match=env_dir):
env("create", "test")
def test_environment_cant_modify_environments_root(tmpdir):
filename = tmpdir.join("spack.yaml")
with open(filename, "w") as f:
f.write(
"""\
spack:
config:
environments_root: /a/black/hole
view: false
specs: []
"""
)
with tmpdir.as_cwd():
env("create", "-d", tmpdir.strpath)
with pytest.raises(ev.SpackEnvironmentError):
env("activate", "-d", tmpdir.strpath)