Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent copying mount point data when setting install_data to a non existing directory #9137

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/everest/config/validation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def check_path_exists(

expanded_paths = expand_geo_id_paths(str(path_source), realizations)
for exp_path in [as_abs_path(p, str(config_dir)) for p in expanded_paths]:
if os.path.ismount(exp_path):
raise ValueError(f"'{exp_path}' is a mount point and can't be handled")
if not os.path.exists(exp_path):
raise ValueError(f"No such file or directory {exp_path}")

Expand Down
56 changes: 56 additions & 0 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from unittest.mock import patch

import pytest
from ruamel.yaml import YAML

import everest
from ert.config import ErtConfig
from ert.config.parsing import ConfigKeys as ErtConfigKeys
from everest import ConfigKeys
from everest import ConfigKeys as CK
from everest.config import EverestConfig
from everest.config.install_data_config import InstallDataConfig
from everest.config.install_job_config import InstallJobConfig
Expand Down Expand Up @@ -560,6 +562,60 @@ def test_install_data(copy_test_data_to_tmp):
)


@pytest.mark.parametrize(
"install_data, expected_error_msg",
[
(
{"source": "r{{ foo }}/", "link": True, "target": "bar.json"},
"'/' is a mount point and can't be handled",
),
(
{"source": "baz/", "link": True, "target": "bar.json"},
"No such file or directory",
),
(
{"source": None, "link": True, "target": "bar.json"},
"Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]",
),
(
{"source": "", "link": "false", "target": "bar.json"},
" false could not be parsed to a boolean",
),
(
{"source": "baz/", "link": True, "target": 3},
"Input should be a valid string [type=string_type, input_value=3, input_type=int]",
),
],
)
def test_install_data_with_invalid_templates(
copy_mocked_test_data_to_tmp,
install_data,
expected_error_msg,
):
"""
Checks for InstallDataConfig's validations instantiating EverestConfig to also
check invalid template rendering (e.g 'r{{ foo }}/) that maps to '/'
"""

config_file = "mocked_multi_batch.yml"

with open(config_file, encoding="utf-8") as f:
raw_config = YAML(typ="safe", pure=True).load(f)

raw_config[CK.INSTALL_DATA] = [install_data]

with open(config_file, "w", encoding="utf-8") as f:
yaml = YAML(typ="safe", pure=True)
yaml.indent = 2
yaml.default_flow_style = False
yaml.dump(raw_config, f)

with pytest.raises(ValueError) as exc_info:
EverestConfig.load_file(config_file)

assert expected_error_msg in str(exc_info.value)


def test_strip_date_job_insertion(copy_test_data_to_tmp):
# Load config file
ever_config = EverestConfig.load_file(SNAKE_CONFIG_PATH)
Expand Down