Skip to content

Commit

Permalink
fixup - have new test be usable against actual cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Feb 27, 2025
1 parent a4f8e8c commit 7f9f68b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 deletions.
2 changes: 0 additions & 2 deletions tests/ert/unit_tests/scheduler/bin/bsub
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ name="STDIN"
jobid="${RANDOM}"
jobdir="${PYTEST_TMP_PATH:-.}/mock_jobs/${jobid}"
mkdir -p "${jobdir}"
command_invocation_file="${jobdir}/complete_command_invocation"
echo "$0 $@" > "$command_invocation_file"

while getopts "o:e:J:q:R:n:P:" opt
do
Expand Down
2 changes: 0 additions & 2 deletions tests/ert/unit_tests/scheduler/bin/qsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobid="test${RANDOM}.localhost"
jobdir="${PYTEST_TMP_PATH:-.}/mock_jobs/${jobid}"
mkdir -p "${jobdir}"

command_invocation_file="${jobdir}/complete_command_invocation"
echo "$0 $@" > "$command_invocation_file"
job_env_file="${jobdir}/env"
touch $job_env_file

Expand Down
3 changes: 0 additions & 3 deletions tests/ert/unit_tests/scheduler/bin/sbatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import argparse
import os
import random
import shlex
import subprocess
import sys
from pathlib import Path


Expand Down Expand Up @@ -40,7 +38,6 @@ def main() -> None:
jobdir.mkdir(parents=True, exist_ok=True)
(jobdir / "script").write_text(args.script, encoding="utf-8")
(jobdir / "name").write_text(args.job_name, encoding="utf-8")
(jobdir / "complete_command_invocation").write_text(shlex.join(sys.argv))
env_file = jobdir / "env"
if args.ntasks:
env_file.write_text(
Expand Down
32 changes: 14 additions & 18 deletions tests/ert/unit_tests/scheduler/test_lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,26 +1371,32 @@ async def finished(iens: int, returncode: int):

@pytest.mark.integration_test
@pytest.mark.usefixtures("copy_poly_case")
def test_queue_options_are_propagated_from_config_to_bsub(monkeypatch):
def test_queue_options_are_propagated_from_config_to_bsub():
"""
This end to end test is here to verify that queue_options are correctly
propagated all the way from ert config to the cluster.
"""
mock_bin(monkeypatch, os.getcwd())
expected_queue = "foo_bar_queue"
expected_resource_string = "location=foo_bar_location"
expected_realization_memory = "9GB"
expected_project_code = "foo_bar_project"
expected_excluded_hosts = "foo_host,bar_host"
expected_num_cpu = 98

capture_bsub_cmd = Path("capture_bsub_args")
capture_bsub_cmd.write_text(
'#!/bin/sh\necho "$0 $@" > "captured_bsub_args"\nbsub "$@"',
encoding="utf-8",
)
capture_bsub_cmd.chmod(capture_bsub_cmd.stat().st_mode | stat.S_IEXEC)
with open("poly.ert", "a", encoding="utf-8") as f:
f.write(
dedent(
f"""\
NUM_CPU {expected_num_cpu}
REALIZATION_MEMORY {expected_realization_memory}
QUEUE_SYSTEM LSF
QUEUE_OPTION LSF BSUB_CMD {capture_bsub_cmd.absolute()}
QUEUE_OPTION LSF LSF_QUEUE {expected_queue}
QUEUE_OPTION LSF LSF_RESOURCE {expected_resource_string}
QUEUE_OPTION LSF PROJECT_CODE {expected_project_code}
Expand All @@ -1400,27 +1406,17 @@ def test_queue_options_are_propagated_from_config_to_bsub(monkeypatch):
)
)
run_cli(ENSEMBLE_EXPERIMENT_MODE, "--disable-monitoring", "poly.ert")
mock_jobs_dir = Path(f"{os.environ.get('PYTEST_TMP_PATH')}/mock_jobs")
job_dir = next(
mock_jobs_dir.iterdir()
) # There is only one realization in this test
complete_command_invocation = (job_dir / "complete_command_invocation").read_text(
encoding="utf-8"
)

complete_command_invocation = Path("captured_bsub_args").read_text(encoding="utf-8")
assert f"-q {expected_queue}" in complete_command_invocation
assert f"-P {expected_project_code}" in complete_command_invocation
assert f"-n {str(expected_num_cpu)}" in complete_command_invocation
assert f"-n {expected_num_cpu!s}" in complete_command_invocation

complete_resource_requirement = (job_dir / "resource_requirement").read_text(
encoding="utf-8"
)
assert expected_resource_string in complete_resource_requirement
assert expected_resource_string in complete_command_invocation
assert (
f"rusage[mem={_parse_realization_memory_str(expected_realization_memory) // 1024**2}]"
in complete_resource_requirement
in complete_command_invocation
)
assert (
f"""select[{" && ".join(f"hname!='{host_name}'" for host_name in expected_excluded_hosts.split(","))}]"""
in complete_resource_requirement
)
in complete_command_invocation
)
24 changes: 14 additions & 10 deletions tests/ert/unit_tests/scheduler/test_openpbs_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,24 +611,31 @@ def test_openpbs_driver_with_poly_example_failing_poll_fails_ert_and_propagates_

@pytest.mark.integration_test
@pytest.mark.usefixtures("copy_poly_case")
def test_queue_options_are_propagated_from_config_to_qsub(monkeypatch):
def test_queue_options_are_propagated_from_config_to_qsub():
"""
This end to end test is here to verify that queue_options are correctly
propagated all the way from ert config to the cluster.
"""
mock_bin(monkeypatch, os.getcwd())
expected_queue = "foo_bar_queue"
expected_realization_memory = "9GB"
expected_project_code = "foo_bar_project"
expected_cluster_label = "foo_bar_cluster"
expected_num_cpu = 98

capture_qsub_cmd = Path("capture_qsub_args")
capture_qsub_cmd.write_text(
'#!/bin/sh\necho "$0 $@" > "captured_qsub_args"\nqsub "$@"',
encoding="utf-8",
)
capture_qsub_cmd.chmod(capture_qsub_cmd.stat().st_mode | stat.S_IEXEC)
with open("poly.ert", "a", encoding="utf-8") as f:
f.write(
dedent(
f"""\
NUM_CPU {expected_num_cpu}
REALIZATION_MEMORY {expected_realization_memory}
QUEUE_SYSTEM TORQUE
QUEUE_OPTION TORQUE QSUB_CMD {capture_qsub_cmd.absolute()}
QUEUE_OPTION TORQUE QUEUE {expected_queue}
QUEUE_OPTION TORQUE CLUSTER_LABEL {expected_cluster_label}
QUEUE_OPTION TORQUE PROJECT_CODE {expected_project_code}
Expand All @@ -637,15 +644,12 @@ def test_queue_options_are_propagated_from_config_to_qsub(monkeypatch):
)
)
run_cli(ENSEMBLE_EXPERIMENT_MODE, "--disable-monitoring", "poly.ert")
mock_jobs_dir = Path(f"mock_jobs")
job_dir = next(
mock_jobs_dir.iterdir()
) # There is only one realization in this test
complete_command_invocation = (job_dir / "complete_command_invocation").read_text(
encoding="utf-8"
)
complete_command_invocation = Path("captured_qsub_args").read_text(encoding="utf-8")

assert f"-q {expected_queue}" in complete_command_invocation
assert f"-A {expected_project_code}" in complete_command_invocation
assert f"-l ncpus={expected_num_cpu}:mem={_parse_realization_memory_str(expected_realization_memory) // 1024**2}mb" in complete_command_invocation
assert (
f"-l ncpus={expected_num_cpu}:mem={_parse_realization_memory_str(expected_realization_memory) // 1024**2}mb"
in complete_command_invocation
)
assert f"-l {expected_cluster_label}" in complete_command_invocation
31 changes: 20 additions & 11 deletions tests/ert/unit_tests/scheduler/test_slurm_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,26 +467,34 @@ async def test_slurm_uses_sacct(

@pytest.mark.integration_test
@pytest.mark.usefixtures("copy_poly_case")
def test_queue_options_are_propagated_from_config_to_sbatch(monkeypatch):
def test_queue_options_are_propagated_from_config_to_sbatch():
"""
This end to end test is here to verify that queue_options are correctly
propagated all the way from ert config to the cluster.
"""
mock_bin(monkeypatch, os.getcwd())
expected_partition = "foo_bar_partition"
expected_realization_memory = "9GB"
expected_project_code = "foo_bar_project"
expected_exclude_hosts = "not_foohost,not_barhost"
expected_include_hosts = "foohost,barhost"
expected_max_runtime = 99
expected_num_cpu = 98

capture_sbatch_cmd = Path("capture_sbatch_args")
capture_sbatch_cmd.write_text(
'#!/bin/sh\necho "$0 $@" > "captured_sbatch_args"\nsbatch "$@"',
encoding="utf-8",
)
capture_sbatch_cmd.chmod(capture_sbatch_cmd.stat().st_mode | stat.S_IEXEC)

with open("poly.ert", "a", encoding="utf-8") as f:
f.write(
dedent(
f"""\
NUM_CPU {expected_num_cpu}
REALIZATION_MEMORY {expected_realization_memory}
QUEUE_SYSTEM SLURM
QUEUE_OPTION SLURM SBATCH {capture_sbatch_cmd.absolute()}
QUEUE_OPTION SLURM PARTITION {expected_partition}
QUEUE_OPTION SLURM INCLUDE_HOST {expected_include_hosts}
QUEUE_OPTION SLURM EXCLUDE_HOST {expected_exclude_hosts}
Expand All @@ -497,21 +505,22 @@ def test_queue_options_are_propagated_from_config_to_sbatch(monkeypatch):
)
)
run_cli(ENSEMBLE_EXPERIMENT_MODE, "--disable-monitoring", "poly.ert")
mock_jobs_dir = Path(f"{os.environ.get('PYTEST_TMP_PATH')}/mock_jobs")
job_dir = next(
mock_jobs_dir.iterdir()
) # There is only one realization in this test
complete_command_invocation = (job_dir / "complete_command_invocation").read_text(
complete_command_invocation = Path("captured_sbatch_args").read_text(
encoding="utf-8"
)

assert f"--ntasks={expected_num_cpu}" in complete_command_invocation
assert f"--mem={_parse_realization_memory_str(expected_realization_memory) // 1024**2}M" in complete_command_invocation
assert (
f"--mem={_parse_realization_memory_str(expected_realization_memory) // 1024**2}M"
in complete_command_invocation
)

assert f"--nodelist={expected_include_hosts}" in complete_command_invocation
assert f"--exclude={expected_exclude_hosts}" in complete_command_invocation
assert f"--time={_seconds_to_slurm_time_format(expected_max_runtime
)}" in complete_command_invocation

assert (
f"--time={_seconds_to_slurm_time_format(expected_max_runtime)}"
in complete_command_invocation
)

assert f"--partition={expected_partition}" in complete_command_invocation
assert f"--account={expected_project_code}" in complete_command_invocation

0 comments on commit 7f9f68b

Please sign in to comment.