From 5b3c7169498662aff2eefbeb84bb6313a3f6fa35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= <88316787+adnejacobsen@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:26:19 +0100 Subject: [PATCH] Sumo auth validation (#55) * Sumo auth validation * update to latest version of ForwardModelStepPlugin * raise the proper exception instead of crashing ert * deprecate config file * add stderr and stdout file arguments --------- Co-authored-by: Runar Ask Johannessen <89020325+equinor-ruaj@users.noreply.github.com> --- .../{SIM2SUMO => SIM2SUMO_CONFIG_DEPRECATED} | 0 .../sumo/sim2sumo/forward_models/__init__.py | 47 +++++++++++++++++++ .../sim2sumo/hook_implementations/jobs.py | 8 ++++ 3 files changed, 55 insertions(+) rename src/fmu/sumo/sim2sumo/config_jobs/{SIM2SUMO => SIM2SUMO_CONFIG_DEPRECATED} (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_DEPRECATED similarity index 100% rename from src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO rename to src/fmu/sumo/sim2sumo/config_jobs/SIM2SUMO_CONFIG_DEPRECATED 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..4808c230 --- /dev/null +++ b/src/fmu/sumo/sim2sumo/forward_models/__init__.py @@ -0,0 +1,47 @@ +import subprocess +from ert import ( + ForwardModelStepJSON, + ForwardModelStepPlugin, + ForwardModelStepValidationError, +) + + +class Sim2Sumo(ForwardModelStepPlugin): + def __init__(self): + super().__init__( + name="SIM2SUMO", + command=[ + "sim2sumo", + "--config_path", + "", + "--env", + "", + ], + default_mapping={ + "": "fmuconfig/output/global_variables.yml", + "": "prod", + }, + stderr_file="sim2sumo.stderr", + stdout_file="sim2sumo.stdout", + ) + + def validate_pre_realization_run( + self, fm_step_json: ForwardModelStepJSON + ) -> ForwardModelStepJSON: + return fm_step_json + + 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) + + err_msg = ( + "Your config uses Sumo" + ", please authenticate using:" + f"sumo_login{f' -e {env}' if env != 'prod' else ''}" + ) + + if return_code != 0: + raise ForwardModelStepValidationError(err_msg) diff --git a/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py b/src/fmu/sumo/sim2sumo/hook_implementations/jobs.py index fd5dd819..05fb68af 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]