Skip to content

Commit

Permalink
Verify logging occur only once
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Oct 2, 2024
1 parent beb4854 commit cc67aa9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/ert/scheduler/lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,9 @@ async def poll(self) -> None:
f"bjobs gave returncode {process.returncode} and error {stderr.decode()}"
)
bjobs_states = _parse_jobs_dict(parse_bjobs(stdout.decode(errors="ignore")))
bjobs_exec_hosts = parse_bjobs_exec_hosts(stdout.decode(errors="ignore"))

for jobid, exec_hosts in bjobs_exec_hosts.items():
if self._jobs[jobid].exec_hosts == "-":
logger.info(
f"Realization {self._jobs[jobid].iens} was assigned to host: {exec_hosts}"
)
self._jobs[jobid].exec_hosts = exec_hosts
self.update_and_log_exec_hosts(
parse_bjobs_exec_hosts(stdout.decode(errors="ignore"))
)

job_ids_found_in_bjobs_output = set(bjobs_states.keys())
if (
Expand Down Expand Up @@ -625,6 +620,14 @@ async def _poll_once_by_bhist(
self._bhist_cache_timestamp = time.time()
return _parse_jobs_dict(jobs)

def update_and_log_exec_hosts(self, bjobs_exec_hosts: Dict[str, str]) -> None:
for job_id, exec_hosts in bjobs_exec_hosts.items():
if self._jobs[job_id].exec_hosts == "-":
logger.info(
f"Realization {self._jobs[job_id].iens} was assigned to host: {exec_hosts}"
)
self._jobs[job_id].exec_hosts = exec_hosts

def _build_resource_requirement_arg(self, realization_memory: int) -> List[str]:
resource_requirement_string = build_resource_requirement_string(
self._exclude_hosts,
Expand Down
14 changes: 14 additions & 0 deletions tests/ert/unit_tests/scheduler/test_lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,20 @@ def not_found_bjobs(monkeypatch, tmp_path):
bjobs_path.chmod(bjobs_path.stat().st_mode | stat.S_IEXEC)


async def test_bjobs_exec_host_logs_only_once(tmp_path, job_name, caplog):
caplog.set_level(logging.INFO)
os.chdir(tmp_path)
driver = LsfDriver()
await driver.submit(0, "sh", "-c", "sleep 1", name=job_name)

job_id = next(iter(driver._jobs.keys()))
driver.update_and_log_exec_hosts({job_id: "COMP-01"})
driver.update_and_log_exec_hosts({job_id: "COMP-02"})

await poll(driver, {0})
assert caplog.text.count("was assigned to host:") == 1


async def test_lsf_stdout_file(tmp_path, job_name):
os.chdir(tmp_path)
driver = LsfDriver()
Expand Down

0 comments on commit cc67aa9

Please sign in to comment.