Skip to content

Commit cc67aa9

Browse files
committed
Verify logging occur only once
1 parent beb4854 commit cc67aa9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/ert/scheduler/lsf_driver.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,9 @@ async def poll(self) -> None:
452452
f"bjobs gave returncode {process.returncode} and error {stderr.decode()}"
453453
)
454454
bjobs_states = _parse_jobs_dict(parse_bjobs(stdout.decode(errors="ignore")))
455-
bjobs_exec_hosts = parse_bjobs_exec_hosts(stdout.decode(errors="ignore"))
456-
457-
for jobid, exec_hosts in bjobs_exec_hosts.items():
458-
if self._jobs[jobid].exec_hosts == "-":
459-
logger.info(
460-
f"Realization {self._jobs[jobid].iens} was assigned to host: {exec_hosts}"
461-
)
462-
self._jobs[jobid].exec_hosts = exec_hosts
455+
self.update_and_log_exec_hosts(
456+
parse_bjobs_exec_hosts(stdout.decode(errors="ignore"))
457+
)
463458

464459
job_ids_found_in_bjobs_output = set(bjobs_states.keys())
465460
if (
@@ -625,6 +620,14 @@ async def _poll_once_by_bhist(
625620
self._bhist_cache_timestamp = time.time()
626621
return _parse_jobs_dict(jobs)
627622

623+
def update_and_log_exec_hosts(self, bjobs_exec_hosts: Dict[str, str]) -> None:
624+
for job_id, exec_hosts in bjobs_exec_hosts.items():
625+
if self._jobs[job_id].exec_hosts == "-":
626+
logger.info(
627+
f"Realization {self._jobs[job_id].iens} was assigned to host: {exec_hosts}"
628+
)
629+
self._jobs[job_id].exec_hosts = exec_hosts
630+
628631
def _build_resource_requirement_arg(self, realization_memory: int) -> List[str]:
629632
resource_requirement_string = build_resource_requirement_string(
630633
self._exclude_hosts,

tests/ert/unit_tests/scheduler/test_lsf_driver.py

+14
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,20 @@ def not_found_bjobs(monkeypatch, tmp_path):
10101010
bjobs_path.chmod(bjobs_path.stat().st_mode | stat.S_IEXEC)
10111011

10121012

1013+
async def test_bjobs_exec_host_logs_only_once(tmp_path, job_name, caplog):
1014+
caplog.set_level(logging.INFO)
1015+
os.chdir(tmp_path)
1016+
driver = LsfDriver()
1017+
await driver.submit(0, "sh", "-c", "sleep 1", name=job_name)
1018+
1019+
job_id = next(iter(driver._jobs.keys()))
1020+
driver.update_and_log_exec_hosts({job_id: "COMP-01"})
1021+
driver.update_and_log_exec_hosts({job_id: "COMP-02"})
1022+
1023+
await poll(driver, {0})
1024+
assert caplog.text.count("was assigned to host:") == 1
1025+
1026+
10131027
async def test_lsf_stdout_file(tmp_path, job_name):
10141028
os.chdir(tmp_path)
10151029
driver = LsfDriver()

0 commit comments

Comments
 (0)