Skip to content

Commit

Permalink
apptainer_image can be on grid storage
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Aug 6, 2024
1 parent d726f46 commit cee9991
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/bartender/schedulers/dirac.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,14 @@ def _job_script_content(self, description: JobDescription) -> str:

def _command_script(self, description: JobDescription) -> str:
command = description.command
dl_image = ""
if self.config.apptainer_image:
image = self.config.apptainer_image
image = str(self.config.apptainer_image)
if self.config.apptainer_image.is_relative_to(_lfn_user_home(description)):
image = self.config.apptainer_image.name
# Also exclude sif file from in output.tar
lfn_image = self.config.apptainer_image
dl_image = f"dirac-dms-get-file {lfn_image} && echo {image} >> .input_files.txt" # noqa: E501
# TODO if command is complex then qoutes are likely needed
command = f"apptainer run {image} {description.command}"
# added echo so DIRAC
Expand All @@ -265,6 +271,7 @@ def _command_script(self, description: JobDescription) -> str:
return dedent(
f"""\
# Run command
{dl_image}
echo 'Running command for {description.job_dir}'
({command}) > stdout.txt 2> stderr.txt
echo -n $? > returncode
Expand Down Expand Up @@ -302,6 +309,19 @@ async def _jdl_script(self, description: JobDescription, scriptdir: Path) -> str
)


def _lfn_user_home(description: JobDescription) -> Path:
"""Return user's home directory on grid storage.
Args:
description: Description of job.
Returns:
User's home directory on grid storage.
"""
nr_home_dir_parts = 5
return Path(*description.job_dir.parts[:nr_home_dir_parts])


def _relative_output_dir(description: JobDescription) -> Path:
"""Return description.output_dir relative to user's home directory.
Expand Down
6 changes: 4 additions & 2 deletions src/bartender/schedulers/dirac_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class DiracSchedulerConfig(BaseModel):
"""Configuration for DIRAC scheduler.
Args:
apptainer_image: Path on cvmfs to apptainer image.
Will run application command inside apptainer image.
apptainer_image: Path on cvmfs or grid storage to apptainer image.
When set will run application command inside apptainer image.
Image can also be on grid storage,
it will then be downloaded to current directory first.
storage_element: Storage element to upload output files to.
proxy: Proxy configuration.
"""
Expand Down
29 changes: 29 additions & 0 deletions tests_dirac/test_it.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asyncio import sleep
from pathlib import Path
from textwrap import dedent

import pytest

Expand Down Expand Up @@ -306,3 +307,31 @@ async def test_filesystem_delete(
await fs.download(gdescription, description)
finally:
await fs.close()


@pytest.mark.anyio
async def test_apptainer_image_on_lfn() -> None:
sched_config = DiracSchedulerConfig(
storage_element="StorageElementOne",
apptainer_image=Path("/tutoVO/user/c/ciuser/alpine.sif"),
)
scheduler = DiracScheduler(sched_config)

description = JobDescription(
command="echo hello",
job_dir=Path("/tutoVO/user/c/ciuser/bartenderjobs/job1"),
)
script = scheduler._command_script(description) # noqa: WPS437

expected = dedent(
f"""\
# Run command
dirac-dms-get-file /tutoVO/user/c/ciuser/alpine.sif && echo alpine.sif >> .input_files.txt
echo 'Running command for {description.job_dir}'
(apptainer run alpine.sif echo hello) > stdout.txt 2> stderr.txt
echo -n $? > returncode
cat stdout.txt
cat stderr.txt >&2
""", # noqa: E501
)
assert script == expected

0 comments on commit cee9991

Please sign in to comment.