diff --git a/src/ert/config/parsing/config_schema_item.py b/src/ert/config/parsing/config_schema_item.py index bdcf23cabe9..ff1d5053c50 100644 --- a/src/ert/config/parsing/config_schema_item.py +++ b/src/ert/config/parsing/config_schema_item.py @@ -87,8 +87,10 @@ def token_to_value_with_context( if not self._is_in_allowed_values_for_arg_at_index(token, index): raise ConfigValidationError.with_context( - f"{self.kw!r} argument {index + 1!r} must be one of" - f" {self.indexed_selection_set[index]!r} was {token.value!r}", + ( + f"{self.kw!r} argument {index + 1!r} must be one of" + f" {self.indexed_selection_set[index]!r} was {token.value!r}" + ), token, ) @@ -104,8 +106,7 @@ def token_to_value_with_context( return ContextBool(False, token, keyword) else: raise ConfigValidationError.with_context( - f"{self.kw!r} must have a boolean value" - f" as argument {index + 1!r}", + f"{self.kw!r} must have a boolean value as argument {index + 1!r}", token, ) if val_type == SchemaItemType.INT: @@ -113,8 +114,7 @@ def token_to_value_with_context( return ContextInt(int(token), token, keyword) except ValueError as e: raise ConfigValidationError.with_context( - f"{self.kw!r} must have an integer value" - f" as argument {index + 1!r}", + f"{self.kw!r} must have an integer value as argument {index + 1!r}", token, ) from e if val_type == SchemaItemType.FLOAT: @@ -161,8 +161,7 @@ def token_to_value_with_context( if os.path.isdir(absolute_path): raise ConfigValidationError.with_context( - f"Expected executable file, " - f"but {token.value!r} is a directory.", + f"Expected executable file, but {token.value!r} is a directory.", token, ) diff --git a/src/ert/config/queue_config.py b/src/ert/config/queue_config.py index 7d07c6c7f42..edfff7eaadf 100644 --- a/src/ert/config/queue_config.py +++ b/src/ert/config/queue_config.py @@ -91,6 +91,14 @@ def from_dict(cls, config_dict: ConfigDict) -> QueueConfig: f"Valid choices are {sorted(VALID_QUEUE_OPTIONS[queue_system])}." ) if values: + if option_name == "LSF_SERVER" and values[0].startswith("$"): + raise ConfigValidationError( + "Invalid server name specified for QUEUE_OPTION LSF" + f" LSF_SERVER: {values[0]}. Server name is currently an" + " undefined environment variable. The LSF_SERVER keyword is" + " usually provided by the site-configuration file, beware that" + " you are effectively replacing the default value provided." + ) queue_options[queue_system].append((option_name, values[0])) else: queue_options[queue_system].append(option_name) diff --git a/tests/unit_tests/config/test_queue_config.py b/tests/unit_tests/config/test_queue_config.py index f2bfd54dff1..a76c16c4c12 100644 --- a/tests/unit_tests/config/test_queue_config.py +++ b/tests/unit_tests/config/test_queue_config.py @@ -8,7 +8,12 @@ import pytest from hypothesis import given -from ert.config import ConfigValidationError, ErtConfig, QueueConfig, QueueSystem +from ert.config import ( + ConfigValidationError, + ErtConfig, + QueueConfig, + QueueSystem, +) from ert.job_queue import Driver @@ -160,3 +165,23 @@ def test_overwriting_QUEUE_OPTIONS_warning( f"Overwriting QUEUE_OPTION {queue_system} {queue_system_option}: \n Old value:" " test_0 \n New value: test_1" in caplog.text ) + + +@pytest.mark.usefixtures("use_tmpdir", "set_site_config") +def test_undefined_LSF_SERVER_environment_variable(): + filename = "config.ert" + with open(filename, "w", encoding="utf-8") as f: + f.write("NUM_REALIZATIONS 1\n") + f.write("QUEUE_SYSTEM LSF\n") + f.write("QUEUE_OPTION LSF LSF_SERVER $MY_SERVER\n") + with pytest.raises( + ConfigValidationError, + match=( + r"Invalid server name specified for QUEUE_OPTION LSF LSF_SERVER: " + r"\$MY_SERVER. Server name is currently an undefined environment variable." + r" The LSF_SERVER keyword is usually provided by the site-configuration" + r" file, beware that you are effectively replacing the default value" + r" provided." + ), + ): + ErtConfig.from_file(filename)