Add guard-rail and unit-test (not working)
This commit is contained in:
parent
0ac6dfa8f3
commit
d50c8f1727
@ -1039,9 +1039,19 @@ def env_file_config_scope(self):
|
|||||||
[spack.config.first_existing(self.raw_yaml, spack.schema.env.keys)],
|
[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):
|
def config_scopes(self):
|
||||||
"""A list of all configuration scopes for this environment."""
|
"""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):
|
def destroy(self):
|
||||||
"""Remove this environment from Spack entirely."""
|
"""Remove this environment from Spack entirely."""
|
||||||
|
@ -1463,3 +1463,21 @@ def test_environment_errors_if_root_missing(mutable_config, tmpdir):
|
|||||||
|
|
||||||
with pytest.raises(ev.SpackEnvironmentError, match=env_dir):
|
with pytest.raises(ev.SpackEnvironmentError, match=env_dir):
|
||||||
env("create", "test")
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user