From d35cdef56782a9fa1c6806c6eedddc33885fef30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Tue, 4 Jun 2024 14:04:14 +0200 Subject: [PATCH 1/5] Sumo auth validation --- .../config_jobs/{SIM2SUMO => SIM2SUMO_CONFIG} | 0 .../sumo/sim2sumo/forward_models/__init__.py | 46 +++++++++++++++++++ .../sim2sumo/hook_implementations/jobs.py | 8 ++++ 3 files changed, 54 insertions(+) rename src/fmu/sumo/sim2sumo/config_jobs/{SIM2SUMO => SIM2SUMO_CONFIG} (100%) create mode 100644 src/fmu/sumo/sim2sumo/forward_models/__init__.py diff --git a/src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO b/src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG similarity index 100% rename from src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO rename to src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG diff --git a/src/fmu/sumo/sim2sumo/forward_models/__init__.py b/src/fmu/sumo/sim2sumo/forward_models/__init__.py new file mode 100644 index 00000000..dfd1c8fa --- /dev/null +++ b/src/fmu/sumo/sim2sumo/forward_models/__init__.py @@ -0,0 +1,46 @@ +import subprocess +from ert.config.forward_model_step import ( + ForwardModelStep, + ForwardModelStepJSON, +) + + +class Sim2Sumo(ForwardModelStep): + def __init__(self): + super().__init__( + name="SIM2SUMO", + executable="sim2sumo", + arglist=[ + '"--config_path"', + "", + '"--env"', + "", + ], + min_arg=5, + max_arg=5, + arg_types=[ + "STRING", + "STRING", + "STRING", + "STRING", + "STRING", + ], + ) + + def validate_pre_realization_run( + self, fm_step_json: ForwardModelStepJSON + ) -> ForwardModelStepJSON: + return fm_step_json + + def validate_pre_experiment(self) -> None: + try: + env = self.private_args[""] + except KeyError: + env = "prod" + + command = f"sumo_login -e {env} -m silent" + return_code = subprocess.call(command, shell=True) + + assert ( + return_code == 0 + ), "Your config uses Sumo, run sumo_login to authenticate." diff --git a/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py b/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py index 3edfdd5a..9a6ee30f 100644 --- a/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py +++ b/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py @@ -7,6 +7,8 @@ from ert.shared.plugins.plugin_manager import hook_implementation from ert.shared.plugins.plugin_response import plugin_response +from fmu.sumo.sim2sumo.forward_models import Sim2Sumo + DESCRIPTION = """ Makes result simulator (Eclipse, OPM, IX) available in sumo. This is done by SIM2SUMO in a three step process: @@ -98,3 +100,9 @@ def job_documentation(job_name): "examples": EXAMPLES, "category": "export", } + + +@hook_implementation +@plugin_response(plugin_name="fmu_sumo_uploader") +def installable_forward_model_steps(): + return [Sim2Sumo] From 0446b2f2bc5e412b16935b12802118ac281c9db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Tue, 11 Jun 2024 10:53:25 +0200 Subject: [PATCH 2/5] update to latest version of ForwardModelStepPlugin --- .../sumo/sim2sumo/forward_models/__init__.py | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/fmu/sumo/sim2sumo/forward_models/__init__.py b/src/fmu/sumo/sim2sumo/forward_models/__init__.py index dfd1c8fa..0bbf2020 100644 --- a/src/fmu/sumo/sim2sumo/forward_models/__init__.py +++ b/src/fmu/sumo/sim2sumo/forward_models/__init__.py @@ -1,30 +1,22 @@ import subprocess -from ert.config.forward_model_step import ( - ForwardModelStep, - ForwardModelStepJSON, -) +from ert import ForwardModelStepJSON, ForwardModelStepPlugin -class Sim2Sumo(ForwardModelStep): +class Sim2Sumo(ForwardModelStepPlugin): def __init__(self): super().__init__( name="SIM2SUMO", - executable="sim2sumo", - arglist=[ - '"--config_path"', + command=[ + "sim2sumo", + "--config_path", "", - '"--env"', - "", - ], - min_arg=5, - max_arg=5, - arg_types=[ - "STRING", - "STRING", - "STRING", - "STRING", - "STRING", + "--env", + "", ], + default_mapping={ + "": "fmuconfig/output/global_variables.yml", + "": "prod", + }, ) def validate_pre_realization_run( @@ -32,15 +24,18 @@ def validate_pre_realization_run( ) -> ForwardModelStepJSON: return fm_step_json - def validate_pre_experiment(self) -> None: - try: - env = self.private_args[""] - except KeyError: - env = "prod" - + def validate_pre_experiment( + self, fm_step_json: ForwardModelStepJSON + ) -> None: + env = fm_step_json["argList"][3] command = f"sumo_login -e {env} -m silent" return_code = subprocess.call(command, shell=True) - assert ( - return_code == 0 - ), "Your config uses Sumo, run sumo_login to authenticate." + err_msg = ( + "\n\nYour config uses Sumo" + ", please authenticate using:\n\n\t" + f"sumo_login{f' -e {env}' if env != 'prod' else ''}" + "\n\n" + ) + + assert return_code == 0, err_msg From 112251e8a798b942ff26652e1e78c1cc895f652c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Fri, 14 Jun 2024 12:59:19 +0200 Subject: [PATCH 3/5] raise the proper exception instead of crashing ert --- src/fmu/sumo/sim2sumo/forward_models/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fmu/sumo/sim2sumo/forward_models/__init__.py b/src/fmu/sumo/sim2sumo/forward_models/__init__.py index 0bbf2020..be4ae46d 100644 --- a/src/fmu/sumo/sim2sumo/forward_models/__init__.py +++ b/src/fmu/sumo/sim2sumo/forward_models/__init__.py @@ -1,5 +1,9 @@ import subprocess -from ert import ForwardModelStepJSON, ForwardModelStepPlugin +from ert import ( + ForwardModelStepJSON, + ForwardModelStepPlugin, + ForwardModelStepValidationError, +) class Sim2Sumo(ForwardModelStepPlugin): @@ -32,10 +36,10 @@ def validate_pre_experiment( return_code = subprocess.call(command, shell=True) err_msg = ( - "\n\nYour config uses Sumo" - ", please authenticate using:\n\n\t" + "Your config uses Sumo" + ", please authenticate using:" f"sumo_login{f' -e {env}' if env != 'prod' else ''}" - "\n\n" ) - assert return_code == 0, err_msg + if return_code != 0: + raise ForwardModelStepValidationError(err_msg) From 5c190f19cffe5e7792dc9f7ac172aa66c57f8fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Fri, 14 Jun 2024 12:59:59 +0200 Subject: [PATCH 4/5] deprecate config file --- .../config_jobs/{SIM2SUMO_CONFIG => SIM2SUMO_CONFIG_DEPRECATED} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/fmu/sumo/sim2sumo/config_jobs/{SIM2SUMO_CONFIG => SIM2SUMO_CONFIG_DEPRECATED} (100%) diff --git a/src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG b/src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG_DEPRECATED similarity index 100% rename from src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG rename to src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG_DEPRECATED From 5ca0df4710dab985cf07e246c538c7634b4142fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Tue, 25 Jun 2024 12:01:05 +0200 Subject: [PATCH 5/5] add stderr and stdout file arguments --- src/fmu/sumo/sim2sumo/forward_models/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fmu/sumo/sim2sumo/forward_models/__init__.py b/src/fmu/sumo/sim2sumo/forward_models/__init__.py index be4ae46d..4808c230 100644 --- a/src/fmu/sumo/sim2sumo/forward_models/__init__.py +++ b/src/fmu/sumo/sim2sumo/forward_models/__init__.py @@ -21,6 +21,8 @@ def __init__(self): "": "fmuconfig/output/global_variables.yml", "": "prod", }, + stderr_file="sim2sumo.stderr", + stdout_file="sim2sumo.stdout", ) def validate_pre_realization_run(