Skip to content

Commit

Permalink
finish apt manager implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 11, 2024
1 parent 0d0c479 commit 97ffd3f
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions lib/charms/hpc_libs/v0/slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _on_install(self, _) -> None:
import os
import socket
import subprocess
import textwrap
from abc import ABC, abstractmethod
from collections.abc import Mapping
from contextlib import contextmanager
Expand All @@ -77,7 +78,6 @@ def _on_install(self, _) -> None:
from typing import Any, Optional, Union

import distro

import dotenv
import yaml
from slurmutils.editors import slurmconfig, slurmdbdconfig
Expand Down Expand Up @@ -512,26 +512,31 @@ def type(self) -> ServiceType:
"""Return the service type of the managed service."""
return self._service


class AptManager(SlurmOpsManager):
"""Slurm ops manager that uses apt as its package manager."""

def install(self) -> None:
"""Install Slurm using the `slurm` snap."""
repositories = apt.RepositoryMapping()
repositories.add(apt.DebianRepository(
enabled=True,
repotype="deb",
uri="https://ppa.launchpadcontent.net/ubuntu-hpc/slurm-wlm-23.02/ubuntu",
release=distro.codename(),
groups=["main"]
))
repositories.add(apt.DebianRepository(
enabled=True,
repotype="deb",
uri="https://ppa.launchpadcontent.net/ubuntu-hpc/experimental/ubuntu",
release=distro.codename(),
groups=["main"]
))
repositories.add(
apt.DebianRepository(
enabled=True,
repotype="deb",
uri="https://ppa.launchpadcontent.net/ubuntu-hpc/slurm-wlm-23.02/ubuntu",
release=distro.codename(),
groups=["main"],
)
)
repositories.add(
apt.DebianRepository(
enabled=True,
repotype="deb",
uri="https://ppa.launchpadcontent.net/ubuntu-hpc/experimental/ubuntu",
release=distro.codename(),
groups=["main"],
)
)

apt.update()
for package in ["slurm-wlm", "mungectl", "prometheus-slurm-exporter"]:
Expand All @@ -542,14 +547,21 @@ def install(self) -> None:
except apt.PackageError as e:
raise SlurmOpsError(f"failed to install package {package}. reason: {e}")

override = Path("/etc/systemd/system/slurmd.service.d/10-slurmd-conf-server.conf")
override.parent.mkdir(exist_ok=True, parents=True)
override.write_text(
textwrap.dedent(
"""
[Service]
ExecStart=/usr/bin/sh -c "/usr/sbin/slurmd -D -s $${SLURMD_CONFIG_SERVER:+--conf-server $$SLURMD_CONFIG_SERVER} $$SLURMD_OPTIONS"
"""
)
)

def version(self) -> str:
"""Get the current version of the `slurm-wlm` installed on the system."""

try:
return apt.DebianPackage.from_installed_package(
"slurm-wlm"
).version.number
return apt.DebianPackage.from_installed_package("slurm-wlm").version.number
except apt.PackageNotFoundError as e:
_logger.error(e)
raise SlurmOpsError(
Expand All @@ -567,7 +579,7 @@ def service_manager_for(self, type: ServiceType) -> ServiceManager:

def _env_manager_for(self, type: ServiceType) -> _EnvManager:
"""Return the `_EnvManager` for the specified `ServiceType`."""
return _EnvManager(file="/var/snap/slurm/common/.env", prefix=type.value)
return _EnvManager(file=f"/etc/default/{type.value}", prefix=type.value)

def munge_key_manager(self) -> MungeKeyManager:
"""Get the `MungekeyManager` class of this ops manager."""
Expand Down

0 comments on commit 97ffd3f

Please sign in to comment.