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

feat: add method to get the host name #17

Merged
merged 1 commit into from
Jul 12, 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
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 @@ -67,6 +67,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 @@ -82,7 +83,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 @@ -278,3 +279,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 @@ -173,6 +173,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