From f662de3d8b35df08f93b247121605dfddc78e7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 28 Dec 2023 09:11:48 +0100 Subject: [PATCH] Fix jobs.json to use cert_path --- src/ert/scheduler/scheduler.py | 9 +++++++-- tests/unit_tests/scheduler/test_scheduler.py | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ert/scheduler/scheduler.py b/src/ert/scheduler/scheduler.py index 18fb27a3f6a..3b5d83145d2 100644 --- a/src/ert/scheduler/scheduler.py +++ b/src/ert/scheduler/scheduler.py @@ -7,6 +7,7 @@ import ssl from collections import defaultdict from dataclasses import asdict +from pathlib import Path from typing import ( TYPE_CHECKING, Any, @@ -21,6 +22,7 @@ from websockets.client import connect from ert.async_utils import background_tasks +from ert.constant_filenames import CERT_FILE from ert.job_queue.queue import EVTYPE_ENSEMBLE_CANCELLED, EVTYPE_ENSEMBLE_STOPPED from ert.scheduler.driver import Driver, JobEvent from ert.scheduler.job import Job @@ -161,17 +163,20 @@ async def _process_event_queue(self) -> None: self._jobs[iens].aborted.set() def _update_jobs_json(self, iens: int, runpath: str) -> None: + cert_path = f"{runpath}/{CERT_FILE}" + if self._ee_cert is not None: + Path(cert_path).write_text(self._ee_cert, encoding="utf-8") jobs = _JobsJson( experiment_id=None, ens_id=self._ens_id, real_id=iens, dispatch_url=self._ee_uri, ee_token=self._ee_token, - ee_cert_path=self._ee_cert, + ee_cert_path=cert_path if self._ee_cert is not None else None, ) jobs_path = os.path.join(runpath, "jobs.json") with open(jobs_path, "r") as fp: data = json.load(fp) with open(jobs_path, "w") as fp: data.update(asdict(jobs)) - json.dump(data, fp) + json.dump(data, fp, indent=4) diff --git a/tests/unit_tests/scheduler/test_scheduler.py b/tests/unit_tests/scheduler/test_scheduler.py index f022c9c32b9..fe05e747f3c 100644 --- a/tests/unit_tests/scheduler/test_scheduler.py +++ b/tests/unit_tests/scheduler/test_scheduler.py @@ -6,6 +6,7 @@ import pytest from cloudevents.http import CloudEvent, from_json +from ert.constant_filenames import CERT_FILE from ert.ensemble_evaluator._builder._realization import Realization from ert.job_queue.queue import EVTYPE_ENSEMBLE_CANCELLED, EVTYPE_ENSEMBLE_STOPPED from ert.run_arg import RunArg @@ -143,14 +144,16 @@ async def test_add_dispatch_information_to_jobs_file(storage, tmp_path: Path): sch.add_dispatch_information_to_jobs_file() for realization in realizations: - job_file_path = Path(realization.run_arg.runpath, "jobs.json") + job_file_path = Path(realization.run_arg.runpath) / "jobs.json" + cert_file_path = Path(realization.run_arg.runpath) / CERT_FILE content: dict = json.loads(job_file_path.read_text(encoding="utf-8")) assert content["ens_id"] == test_ens_id - assert content["real_id"] == str(realization.iens) + assert content["real_id"] == realization.iens assert content["dispatch_url"] == test_ee_uri assert content["ee_token"] == test_ee_token - assert content["ee_cert_path"] == test_ee_cert + assert content["ee_cert_path"] == str(cert_file_path) assert type(content["jobList"]) == list and len(content["jobList"]) == 0 + assert cert_file_path.read_text(encoding="utf-8") == test_ee_cert @pytest.mark.parametrize(