Skip to content

Commit

Permalink
Fix jobs.json to use cert_path
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 2, 2024
1 parent 1d90e3c commit f662de3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/ert/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ssl
from collections import defaultdict
from dataclasses import asdict
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -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
Expand Down Expand Up @@ -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)
9 changes: 6 additions & 3 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f662de3

Please sign in to comment.