From cc67aa914632fab91e4d73a26a1118b2105efd4c Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Wed, 2 Oct 2024 10:19:14 +0200 Subject: [PATCH] Verify logging occur only once --- src/ert/scheduler/lsf_driver.py | 19 +++++++++++-------- .../unit_tests/scheduler/test_lsf_driver.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/ert/scheduler/lsf_driver.py b/src/ert/scheduler/lsf_driver.py index ac4158b6f1e..e2ae3333a2f 100644 --- a/src/ert/scheduler/lsf_driver.py +++ b/src/ert/scheduler/lsf_driver.py @@ -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 ( @@ -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, diff --git a/tests/ert/unit_tests/scheduler/test_lsf_driver.py b/tests/ert/unit_tests/scheduler/test_lsf_driver.py index ff6617f4527..e970a51268b 100644 --- a/tests/ert/unit_tests/scheduler/test_lsf_driver.py +++ b/tests/ert/unit_tests/scheduler/test_lsf_driver.py @@ -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()