Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Allow cert to be None
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreso authored and markusdregi committed May 5, 2021
1 parent 36da7b1 commit fbefcd4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 5 deletions.
9 changes: 5 additions & 4 deletions python/res/job_queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,10 @@ def add_ensemble_evaluator_information_to_jobs_file(
self, ee_id, dispatch_url, cert, token
):
for q_index, q_node in enumerate(self.job_list):
cert_path = f"{q_node.run_path}/{CERT_FILE}"
with open(cert_path, "w") as cert_file:
cert_file.write(cert)
if cert is not None:
cert_path = f"{q_node.run_path}/{CERT_FILE}"
with open(cert_path, "w") as cert_file:
cert_file.write(cert)
with open(f"{q_node.run_path}/{JOBS_FILE}", "r+") as jobs_file:
data = json.load(jobs_file)

Expand All @@ -598,7 +599,7 @@ def add_ensemble_evaluator_information_to_jobs_file(
data["step_id"] = 0
data["dispatch_url"] = dispatch_url
data["ee_token"] = token
data["ee_cert_path"] = cert_path
data["ee_cert_path"] = cert_path if cert is not None else None

jobs_file.seek(0)
jobs_file.truncate()
Expand Down
69 changes: 68 additions & 1 deletion tests/res/job_queue/test_job_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tests import ResTest
from tests.utils import wait_until
from ecl.util.test import TestAreaContext
import os, stat, time
import os, stat, time, pathlib, json
from threading import BoundedSemaphore


Expand Down Expand Up @@ -179,3 +179,70 @@ def test_timeout_jobs(self):

for job in job_queue.job_list:
job.wait_for()

def test_add_ensemble_evaluator_info(self):
with TestAreaContext("job_queue_add_ensemble_evaluator_info") as work_area:
job_queue = create_queue(simple_script)
ee_id = "some_id"
dispatch_url = "wss://some_url.com"
cert = "My very nice cert"
token = "my_super_secret_token"
cert_file = ".ee.pem"
runpaths = [
pathlib.Path(dummy_config["run_path"].format(i)) for i in range(10)
]
for runpath in runpaths:
with open(runpath / "jobs.json", "w") as f:
json.dump({}, f)
job_queue.add_ensemble_evaluator_information_to_jobs_file(
ee_id=ee_id,
dispatch_url=dispatch_url,
cert=cert,
token=token,
)

for runpath in runpaths:
job_file_path = runpath / "jobs.json"
with open(job_file_path) as f:
content = json.load(f)
assert content["step_id"] == 0
assert content["dispatch_url"] == dispatch_url
assert content["ee_token"] == token

assert content["ee_cert_path"] == str(runpath / cert_file)
with open(runpath / cert_file) as f:
assert f.read() == cert

def test_add_ensemble_evaluator_info_cert_none(self):
with TestAreaContext(
"job_queue_add_ensemble_evaluator_info_cert_none"
) as work_area:
job_queue = create_queue(simple_script)
ee_id = "some_id"
dispatch_url = "wss://some_url.com"
cert = None
token = None
cert_file = ".ee.pem"
runpaths = [
pathlib.Path(dummy_config["run_path"].format(i)) for i in range(10)
]
for runpath in runpaths:
with open(runpath / "jobs.json", "w") as f:
json.dump({}, f)
job_queue.add_ensemble_evaluator_information_to_jobs_file(
ee_id=ee_id,
dispatch_url=dispatch_url,
cert=cert,
token=token,
)

for runpath in runpaths:
job_file_path = runpath / "jobs.json"
with open(job_file_path) as f:
content = json.load(f)
assert content["step_id"] == 0
assert content["dispatch_url"] == dispatch_url
assert content["ee_token"] == token

assert content["ee_cert_path"] == None
assert not (runpath / cert_file).exists()

0 comments on commit fbefcd4

Please sign in to comment.