blob: 1084a8dfe2792f51a3ceeccdb81bca90e93b24e0 [file] [edit]
############################################################################
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
############################################################################
"""Test the slurmctld and slurmd HTTP probes and their endpoint index.
The probes are /readyz, /livez and /healthz, all listed by GET /.
Ticket 24651: slurmctld /readyz reported not ready (HTTP 500) while it was
already answering RPCs, until its first write to StateSaveLocation.
"""
import pytest
import requests
import atf
REASON = "Issue 50189: slurmctld and slurmd HTTP probes added in 25.11"
ENDPOINTS = {"readyz": "READY", "livez": "LIVE", "healthz": "HEALTHY"}
COMPONENTS = [
"sbin/slurmctld",
pytest.param(
"sbin/slurmd",
marks=pytest.mark.skipif(
atf.get_version("sbin/slurmd") < (25, 11), reason=REASON
),
),
]
@pytest.fixture(scope="module", autouse=True)
def setup():
atf.require_version((25, 11), "sbin/slurmctld", reason=REASON)
atf.require_config_parameter_excludes("CommunicationParameters", "disable_http")
atf.require_slurm_running()
@pytest.fixture
def all_nodes_drained():
nodes = list(atf.get_nodes(fatal=True))
atf.run_command(
f"scontrol update NodeName={','.join(nodes)} State=DRAIN Reason=test_180_3",
user=atf.properties["slurm-user"],
fatal=True,
)
atf.wait_for_node_state(nodes, "DRAIN", fatal=True)
yield
atf.run_command(
f"scontrol update NodeName={','.join(nodes)} State=RESUME",
user=atf.properties["slurm-user"],
fatal=True,
)
atf.wait_for_node_state(nodes, "DRAIN", reverse=True, fatal=True)
def _targets(component):
"""Map each daemon of the component to the node to probe it on."""
if component == "sbin/slurmctld":
return {"slurmctld": None}
nodes = atf.get_nodes(fatal=True)
assert nodes, "No nodes found in cluster"
return {f"slurmd on {node}": node for node in nodes}
def _succeeded(r, endpoint, version):
"""Whether a probe response is the documented success."""
# Ticket 25321: probes return 200 with a status body since 26.11
if version >= (26, 11):
return r.status_code == 200 and r.text == ENDPOINTS[endpoint]
return r.ok
def _wait_ready(component):
"""Wait for /readyz of every daemon of the component to report ready.
The listener refuses connections while the daemon restarts.
"""
version = atf.get_version(component)
for node in _targets(component).values():
for _ in atf.timer(fatal=True):
try:
r = atf.request_component(component, "readyz", node=node)
except requests.exceptions.ConnectionError:
continue
if _succeeded(r, "readyz", version):
break
def _assert_probes(component, context):
version = atf.get_version(component)
for daemon, node in _targets(component).items():
for endpoint in ENDPOINTS:
r = atf.request_component(component, endpoint, node=node)
assert _succeeded(
r, endpoint, version
), f"{daemon} /{endpoint} returned {r.status_code} {r.text!r} {context}"
@pytest.mark.parametrize("component", COMPONENTS)
def test_index(component):
"""GET / lists every probe."""
for daemon, node in _targets(component).items():
r = atf.request_component(component, "", node=node)
assert r.ok, f"{daemon} / returned {r.status_code}"
for endpoint in ENDPOINTS:
assert f"/{endpoint}" in r.text, f"{daemon} / does not list /{endpoint}"
@pytest.mark.parametrize("component", COMPONENTS)
def test_probes(component):
"""Every probe of a running daemon reports it ready."""
_assert_probes(component, "in steady state")
@pytest.mark.parametrize("component", COMPONENTS)
def test_probes_with_all_nodes_drained(component, all_nodes_drained):
"""Node states do not affect the probes, even with every node DRAIN."""
_assert_probes(component, "while all nodes are DRAIN")
@pytest.mark.parametrize("component", COMPONENTS)
def test_probes_after_reconfigure(component):
"""Every probe reports ready again after scontrol reconfigure."""
atf.run_command(
"scontrol reconfigure", user=atf.properties["slurm-user"], fatal=True
)
_wait_ready(component)
assert atf.is_slurmctld_running(), "scontrol ping failed after reconfigure"
_assert_probes(component, "after scontrol reconfigure")
def test_slurmctld_probes_after_restart():
"""Every probe reports ready again after restarting slurmctld."""
atf.restart_slurmctld()
_wait_ready("sbin/slurmctld")
_assert_probes("sbin/slurmctld", "after restarting slurmctld")