Skip to content

Commit 8a95ef4

Browse files
authored
Merge pull request #78 from lsst-sqre/tickets/DM-50924
tickets/DM-50924: make scratch path overrideable
2 parents 646a53b + 78f2a1a commit 8a95ef4

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- Delete the sections that don't apply -->
2+
3+
### Other changes
4+
5+
- Allow configuration override of scratch directory.

src/lsst/rsp/startup/constants.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"ETC_PATH",
88
"PREVIOUS_LOGGING_CHECKSUMS",
99
"MAX_NUMBER_OUTPUTS",
10-
"SCRATCH_PATH",
1110
]
1211

1312
APP_NAME = "nublado"
@@ -31,6 +30,3 @@
3130
3231
Used to prevent OOM-killing if some cell generates a lot of output.
3332
"""
34-
35-
SCRATCH_PATH = Path("/scratch")
36-
"""Scratch path, usually /scratch, but overrideable for tests."""

src/lsst/rsp/startup/services/labrunner.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
ETC_PATH,
2424
MAX_NUMBER_OUTPUTS,
2525
PREVIOUS_LOGGING_CHECKSUMS,
26-
SCRATCH_PATH,
2726
)
2827
from ..exceptions import RSPErrorCode, RSPStartupError
2928
from ..models.noninteractive import NonInteractiveExecutor
@@ -172,9 +171,9 @@ def _set_user(self) -> None:
172171

173172
def _check_user_scratch_subdir(self, path: Path) -> Path | None:
174173
# This is very Rubin specific. We generally have a large
175-
# world-writable filesystem in SCRATCH_PATH (`/scratch`).
174+
# world-writable filesystem in a scratch path.
176175
#
177-
# Given a path we well test that SCRATCH_PATH/user/path can be
176+
# Given a path we will test that SCRATCH_PATH/user/path can be
178177
# created as a writable directory (or that it already exists
179178
# as a writable directory). If it can be (or is), we return the
180179
# whole path, and if not, we return None.
@@ -183,17 +182,20 @@ def _check_user_scratch_subdir(self, path: Path) -> Path | None:
183182
# they want to share, but for TMPDIR and DAF_BUTLER_CACHE_DIRECTORY
184183
# they probably should not. The mode will not be reset if the
185184
# directory already exists and is writeable
186-
if not SCRATCH_PATH.is_dir():
185+
186+
scratch_path = Path(os.getenv("SCRATCH_PATH") or "/scratch")
187+
188+
if not scratch_path.is_dir():
187189
self._logger.debug(
188190
# Debug only: not having /scratch is reasonable.
189-
f"{SCRATCH_PATH} is not a directory."
191+
f"{scratch_path} is not a directory."
190192
)
191193
return None
192194
user = self._env.get("USER", "")
193195
if not user:
194196
self._logger.warning("Could not determine user from environment")
195197
return None
196-
user_scratch_path = SCRATCH_PATH / user / path
198+
user_scratch_path = scratch_path / user / path
197199
try:
198200
user_scratch_path.mkdir(parents=True, exist_ok=True, mode=0o700)
199201
except OSError as exc:
@@ -209,14 +211,14 @@ def _check_user_scratch_subdir(self, path: Path) -> Path | None:
209211

210212
def _set_tmpdir_if_scratch_available(self) -> None:
211213
# Assuming that TMPDIR is not already set (e.g. by the spawner),
212-
# we will try to create <SCRATCH_PATH>/<user>/tmp and ensure it is a
214+
# we will try to create <scratch_path>/<user>/tmp and ensure it is a
213215
# writeable directory, and if it is, TMPDIR will be repointed to it.
214216
# This will then reduce our ephemeral storage issues, which have
215217
# caused mass pod eviction and destruction of the prepull cache.
216218
#
217219
# In our tests at the IDF, on a 2CPU/8GiB "Medium", TMPDIR on
218220
# /scratch (NFS) is about 15% slower than on local ephemeral storage.
219-
self._logger.debug(f"Resetting TMPDIR if {SCRATCH_PATH} available")
221+
self._logger.debug("Resetting TMPDIR if scratch storage available")
220222
tmpdir = self._env.get("TMPDIR", "")
221223
if tmpdir:
222224
self._logger.debug(f"Not setting TMPDIR: already set to {tmpdir}")

tests/conftest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ def _rsp_env(
5959
)
6060
t_scratch = Path(fake_root) / "scratch"
6161
t_scratch.mkdir()
62-
with patch(
63-
"lsst.rsp.startup.services.labrunner.SCRATCH_PATH", t_scratch
64-
):
65-
with patch("lsst.rsp.startup.constants.SCRATCH_PATH", t_scratch):
66-
yield
62+
monkeypatch.setenv("SCRATCH_PATH", str(t_scratch))
63+
yield
6764

6865

6966
@pytest.fixture

tests/startup_test.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import shutil
88
from pathlib import Path
9-
from unittest.mock import patch
109

1110
import pytest
1211

@@ -54,19 +53,12 @@ def test_set_tmpdir(monkeypatch: pytest.MonkeyPatch) -> None:
5453
lr._set_tmpdir_if_scratch_available()
5554
assert lr._env["TMPDIR"] == "/preset"
5655
monkeypatch.delenv("TMPDIR")
57-
# Can't write SCRATCH_DIR
58-
with patch(
59-
"lsst.rsp.startup.services.labrunner.SCRATCH_PATH",
60-
(Path("/nonexistent") / "scratch"),
61-
):
62-
with patch(
63-
"lsst.rsp.startup.constants.SCRATCH_PATH",
64-
(Path("nonexistent") / "scratch"),
65-
):
66-
lr = LabRunner()
67-
lr._set_tmpdir_if_scratch_available()
68-
assert "TMPDIR" not in lr._env
69-
# Get rid of user-specific scratch dir too.
56+
# Can't write to scratch dir
57+
monkeypatch.setenv("SCRATCH_PATH", "/nonexistent/scratch")
58+
lr = LabRunner()
59+
lr._set_tmpdir_if_scratch_available()
60+
assert "TMPDIR" not in lr._env
61+
monkeypatch.delenv("SCRATCH_PATH")
7062
scratch_path.parent.rmdir()
7163

7264

0 commit comments

Comments
 (0)