Skip to content

Commit

Permalink
Merge pull request #1699 from fractal-analytics-platform/1680-remove-…
Browse files Browse the repository at this point in the history
…has_sbatch=true-branch-from-tests

Remove `HAS_LOCAL_SBATCH` check
  • Loading branch information
ychiucco authored Jul 31, 2024
2 parents 3a5cd17 + 9cb7036 commit be81d23
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* App:
* `UvicornWorker` is now imported from `uvicorn-worker` (\#1690).
* Testing:
* Remove `HAS_LOCAL_SBATCH` variable and related if-branches (\#1699).

# 2.3.7

Expand Down
3 changes: 0 additions & 3 deletions tests/fixtures_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from fractal_server.ssh._fabric import FractalSSH


HAS_LOCAL_SBATCH = bool(shutil.which("sbatch"))


@pytest.fixture(scope=containers_scope)
def docker_cleanup() -> str:
"""
Expand Down
13 changes: 4 additions & 9 deletions tests/fixtures_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from fractal_server.config import get_settings
from fractal_server.config import Settings
from fractal_server.syringe import Inject
from tests.fixtures_slurm import HAS_LOCAL_SBATCH


try:
Expand Down Expand Up @@ -63,14 +62,10 @@ def get_patched_settings(temp_path: Path):
settings.FRACTAL_API_MAX_JOB_LIST_LENGTH = 1
settings.FRACTAL_GRACEFUL_SHUTDOWN_TIME = 1

# NOTE:
# This variable is set to work with the system interpreter within a docker
# container. If left unset it defaults to `sys.executable`
if not HAS_LOCAL_SBATCH:
INFO = sys.version_info
CURRENT_PY_VERSION = f"{INFO.major}.{INFO.minor}"
PYTHON_BIN = f"/usr/bin/python{CURRENT_PY_VERSION}"
settings.FRACTAL_SLURM_WORKER_PYTHON = PYTHON_BIN
INFO = sys.version_info
CURRENT_PY_VERSION = f"{INFO.major}.{INFO.minor}"
PYTHON_BIN = f"/usr/bin/python{CURRENT_PY_VERSION}"
settings.FRACTAL_SLURM_WORKER_PYTHON = PYTHON_BIN

settings.FRACTAL_SLURM_CONFIG_FILE = temp_path / "slurm_config.json"

Expand Down
3 changes: 0 additions & 3 deletions tests/fixtures_slurm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import shlex
import shutil
import subprocess
from pathlib import Path

Expand All @@ -15,8 +14,6 @@
_run_command_as_user,
)


HAS_LOCAL_SBATCH = bool(shutil.which("sbatch"))
SLURM_USER = "test01"


Expand Down
47 changes: 19 additions & 28 deletions tests/fixtures_tasks_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pydantic import BaseModel
from pydantic import validator

from .fixtures_slurm import HAS_LOCAL_SBATCH
from fractal_server.tasks.v1.endpoint_operations import create_package_dir_pip
from fractal_server.tasks.v1.endpoint_operations import inspect_package
from tests.execute_command import execute_command
Expand Down Expand Up @@ -198,30 +197,22 @@ def relink_python_interpreter_v1(collect_packages, current_py_version: str):
import os
import logging

if not HAS_LOCAL_SBATCH:

logger = logging.getLogger("RELINK")
logger.setLevel(logging.INFO)

task = collect_packages[0]
task_python = Path(task.command.split()[0])
orig_python = os.readlink(task_python)
logger.warning(
f"RELINK: Original status: {task_python=} -> {orig_python}"
)
task_python.unlink()
task_python.symlink_to(f"/usr/bin/python{current_py_version}")
logger.warning(
f"RELINK: Updated status: {task_python=} -> "
f"{os.readlink(task_python.as_posix())}"
)

yield
task_python.unlink()
task_python.symlink_to(orig_python)
logger.warning(
f"RELINK: Restore original: {task_python=} -> "
f"{os.readlink(task_python.as_posix())}"
)
else:
yield
logger = logging.getLogger("RELINK")
logger.setLevel(logging.INFO)
task = collect_packages[0]
task_python = Path(task.command.split()[0])
orig_python = os.readlink(task_python)
logger.warning(f"RELINK: Original status: {task_python=} -> {orig_python}")
task_python.unlink()
task_python.symlink_to(f"/usr/bin/python{current_py_version}")
logger.warning(
f"RELINK: Updated status: {task_python=} -> "
f"{os.readlink(task_python.as_posix())}"
)
yield
task_python.unlink()
task_python.symlink_to(orig_python)
logger.warning(
f"RELINK: Restore original: {task_python=} -> "
f"{os.readlink(task_python.as_posix())}"
)
47 changes: 19 additions & 28 deletions tests/fixtures_tasks_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,23 @@ def relink_python_interpreter_v2(
"""
Rewire python executable in tasks
"""
from .fixtures_slurm import HAS_LOCAL_SBATCH

if not HAS_LOCAL_SBATCH:

logger = logging.getLogger("RELINK")
logger.setLevel(logging.INFO)
task_python = fractal_tasks_mock_collection["python_bin"]
logger.warning(f"Original tasks Python: {task_python.as_posix()}")

actual_task_python = os.readlink(task_python)
logger.warning(
f"Actual tasks Python (after readlink): {actual_task_python}"
)

task_python.unlink()
new_actual_task_python = f"/usr/bin/python{current_py_version}"
task_python.symlink_to(new_actual_task_python)
logger.warning(f"New tasks Python: {new_actual_task_python}")

yield

task_python.unlink()
task_python.symlink_to(actual_task_python)
logger.warning(
f"Restored link from "
f"{task_python.as_posix()} to {os.readlink(task_python)}"
)
else:
yield
logger = logging.getLogger("RELINK")
logger.setLevel(logging.INFO)
task_python = fractal_tasks_mock_collection["python_bin"]
logger.warning(f"Original tasks Python: {task_python.as_posix()}")
actual_task_python = os.readlink(task_python)
logger.warning(
f"Actual tasks Python (after readlink): {actual_task_python}"
)
task_python.unlink()
new_actual_task_python = f"/usr/bin/python{current_py_version}"
task_python.symlink_to(new_actual_task_python)
logger.warning(f"New tasks Python: {new_actual_task_python}")
yield
task_python.unlink()
task_python.symlink_to(actual_task_python)
logger.warning(
f"Restored link from "
f"{task_python.as_posix()} to {os.readlink(task_python)}"
)

0 comments on commit be81d23

Please sign in to comment.