Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/2170.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that Apptainer image exist for HTCondor submission scripts.
14 changes: 12 additions & 2 deletions src/simtools/job_execution/htcondor_script_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def generate_submission_script(args_dict):
args_dict: dict
Arguments dictionary.
"""
apptainer_image_arg = args_dict["apptainer_image"]
if apptainer_image_arg is None or (
isinstance(apptainer_image_arg, str) and not apptainer_image_arg.strip()
):
raise ValueError("Missing required apptainer_image path.")

apptainer_image = Path(apptainer_image_arg)
if not apptainer_image.is_file():
raise FileNotFoundError(f"Apptainer image file not found: {apptainer_image}")

work_dir = Path(args_dict["output_path"])
log_dir = work_dir / "logs"
work_dir.mkdir(parents=True, exist_ok=True)
Expand All @@ -28,7 +38,7 @@ def generate_submission_script(args_dict):
submit_file_handle.write(
_get_submit_file(
f"{submit_file_name}.sh",
args_dict["apptainer_image"],
apptainer_image,
args_dict["priority"],
Comment thread
GernotMaier marked this conversation as resolved.
+args_dict["number_of_runs"],
)
Expand All @@ -50,7 +60,7 @@ def _get_submit_file(executable, apptainer_image, priority, n_jobs):
----------
executable: str
Name of the executable script.
apptainer_image: str
apptainer_image: Path
Path to the Apptainer image.
priority: int
Priority of the job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
applications:
- application: simtools-simulate-prod-htcondor-generator
configuration:
apptainer_image: test.sif
array_layout_name: test_layout
apptainer_image: tests/resources/dummy_apptainer_image.sif
array_layout_name:
by_version:
"<7.0.0": alpha
">=7.0.0": CTAO-North-Alpha
Comment thread
GernotMaier marked this conversation as resolved.
azimuth_angle: North
core_scatter: 10 500 m
corsika_he_interaction: epos
Expand Down
1 change: 1 addition & 0 deletions tests/resources/dummy_apptainer_image.sif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a dummy apptainer image file used for tests.
16 changes: 15 additions & 1 deletion tests/unit_tests/job_execution/test_htcondor_script_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ def args_dict():
@mock.patch("simtools.job_execution.htcondor_script_generator.Path.mkdir")
@mock.patch("simtools.job_execution.htcondor_script_generator.open", new_callable=mock.mock_open)
@mock.patch("simtools.job_execution.htcondor_script_generator.Path.chmod")
def test_generate_submission_script(mock_chmod, mock_open, mock_mkdir, args_dict):
@mock.patch("simtools.job_execution.htcondor_script_generator.Path.is_file", return_value=True)
def test_generate_submission_script(mock_is_file, mock_chmod, mock_open, mock_mkdir, args_dict):
generate_submission_script(args_dict)

work_dir = Path(args_dict["output_path"])
submit_file_name = "simulate_prod.submit"

mock_is_file.assert_called_once()
mock_mkdir.assert_any_call(parents=True, exist_ok=True)

# Check if files are created and written
Expand All @@ -54,6 +56,18 @@ def test_generate_submission_script(mock_chmod, mock_open, mock_mkdir, args_dict
mock_chmod.assert_called_once_with(0o755)


@mock.patch("simtools.job_execution.htcondor_script_generator.Path.is_file", return_value=False)
@mock.patch("simtools.job_execution.htcondor_script_generator.open", new_callable=mock.mock_open)
def test_generate_submission_script_raises_for_missing_apptainer_image(
mock_open, mock_is_file, args_dict
):
with pytest.raises(FileNotFoundError, match="Apptainer image file not found"):
generate_submission_script(args_dict)

mock_is_file.assert_called_once()
mock_open.assert_not_called()


def test_get_submit_script(args_dict):
# Use abbreviated argument names to avoid overly long lines
e_range_low = args_dict["energy_range"][0].to(u.GeV).value
Expand Down
Loading