Skip to content

Commit

Permalink
feat: add method to get the host name
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored and NucciTheBoss committed Jul 12, 2024
1 parent 9cda74e commit b72ce34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/charms/hpc_libs/v0/slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _on_install(self, _) -> None:
import json
import logging
import re
import socket
import subprocess
from collections.abc import Mapping
from enum import Enum
Expand All @@ -83,7 +84,7 @@ def _on_install(self, _) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 3
LIBPATCH = 4

# Charm library dependencies to fetch during `charmcraft pack`.
PYDEPS = ["pyyaml>=6.0.1"]
Expand Down Expand Up @@ -291,3 +292,8 @@ def __init__(self, service: ServiceType) -> None:
self._service = service
self.config = ConfigurationManager(service.config_name)
self.munge = MungeManager()

@property
def hostname(self) -> str:
"""The hostname where this manager is running."""
return socket.gethostname().split(".")[0]
8 changes: 8 additions & 0 deletions tests/unit/test_slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ def test_configure_munge(self, subcmd) -> None:
args = subcmd.call_args[0][0]
self.assertEqual(args, ["snap", "set", "slurm", "munge.max-thread-count=24"])

@patch("charms.hpc_libs.v0.slurm_ops.socket.gethostname")
def test_hostname(self, gethostname, *_) -> None:
"""Test that manager is able to correctly get the host name."""
gethostname.return_value = "machine"
self.assertEqual(self.manager.hostname, "machine")
gethostname.return_value = "machine.domain.com"
self.assertEqual(self.manager.hostname, "machine")


parameters = [
(SlurmManagerBase(ServiceType.SLURMCTLD), "slurm"),
Expand Down

0 comments on commit b72ce34

Please sign in to comment.