Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid KeyError with warnings on old unsupported Slurm version #345

Merged
merged 2 commits into from
Aug 30, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Changed
- frontend: Add intermediate cluster list width to 80% on large screens, before
going down to 60% on even larger screens.
- agent: Check Slurm version returned from `slurmrestd` against hard-coded
minimal version and log error if not greater or equal.
- pkgs: Add requirement on RFL.core and RFL.authentication >= 1.0.3.
- docs: Update configuration reference documentation.

Expand All @@ -44,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
interpreted by frontend and emit clear error message in logs (#321).
- Detect responses from slurmrestd not formatted in JSON, translated into JSON
error for frontend and emit clear error message in logs (#333).
- Detect absence of _warnings_ key in `slurmrestd` responses and emit warning
log instead of crashing (#316).
- genjwt: fix portability to Python < 3.8 in debug message.
- ldap-check: fix usage of `user_name_attribute` configuration parameter (#340).
- frontend:
Expand Down
31 changes: 28 additions & 3 deletions slurmweb/views/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from ..errors import SlurmwebCacheError, SlurmwebRestdError
from . import SlurmrestdUnixAdapter

# Tuple used for comparaison with Slurm version retrieved from slurmrestd and
# check for minimal supported version.
MINIMAL_SLURM_VERSION = (23, 2, 0)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -92,7 +95,13 @@ def slurmrest(query, key, handle_errors=True):
error["description"],
error["source"],
)
if len(result["warnings"]):
if "warnings" not in result:
logger.error(
"Unable to extract warnings from slurmrestd response to %s, unsupported "
"Slurm version?",
query,
)
elif len(result["warnings"]):
logger.warning("slurmrestd query %s warnings: %s", query, result["warnings"])
return result[key]

Expand Down Expand Up @@ -131,7 +140,7 @@ def _cached_data(cache_key: str, expiration: int, func: Callable, *args: List[An
def _get_version():
return slurmrest(f"/slurm/v{current_app.settings.slurmrestd.version}/ping", "meta")[
"Slurm"
]["release"]
]


def _cached_version():
Expand Down Expand Up @@ -278,6 +287,22 @@ def _cached_accounts():
def stats():
total = 0
running = 0

version = _cached_version()
logger.info("Retrieved version %s", version)
# Check Slurm version is supported or fail with HTTP/500
if (
not (
version["version"]["major"],
version["version"]["minor"],
version["version"]["micro"],
)
>= MINIMAL_SLURM_VERSION
):
error = f"Unsupported Slurm version {version['release']}"
logger.error(error)
abort(500, error)

for job in _cached_jobs():
total += 1
if "RUNNING" in job["job_state"]:
Expand All @@ -290,7 +315,7 @@ def stats():
cores += node["cpus"]
return jsonify(
{
"version": _cached_version(),
"version": version["release"],
"resources": {"nodes": nodes, "cores": cores},
"jobs": {"running": running, "total": total},
}
Expand Down
Loading