Skip to content

Commit

Permalink
refactor(slurmd): raise FileNotFoundError if /etc/nhc/nhc.conf do…
Browse files Browse the repository at this point in the history
…es not exist

Signed-off-by: Jason C. Nucciarone <[email protected]>
  • Loading branch information
NucciTheBoss committed Nov 18, 2024
1 parent 76048fe commit fe37b1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions charms/slurmd/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ def _on_slurmctld_available(self, event: SlurmctldAvailableEvent) -> None:
logger.debug("'nhc_params' not in event data.")
return

logger.debug(
"#### Storing slurmctld_available event relation data in charm StoredState."
)
logger.debug("#### Storing slurmctld_available event relation data in charm StoredState.")
self._stored.slurmctld_available = True

# Restart munged and slurmd after we write the event data to their respective locations.
Expand Down Expand Up @@ -210,7 +208,10 @@ def _on_node_configured_action(self, _: ActionEvent) -> None:

def _on_show_nhc_config(self, event: ActionEvent) -> None:
"""Show current nhc.conf."""
event.set_results({"nhc.conf": nhc.get_config()})
try:
event.set_results({"nhc.conf": nhc.get_config()})
except FileNotFoundError:
event.set_results({"nhc.conf": "/etc/nhc/nhc.conf not found."})

# TODO: Just use the slurmutils models here.
def _on_node_config_action_event(self, event: ActionEvent) -> None:
Expand Down
13 changes: 9 additions & 4 deletions charms/slurmd/src/utils/nhc.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ def install() -> None:


def get_config() -> str:
"""Get the current NHC configuration."""
"""Get the current NHC configuration.
Raises:
FileNotFoundError: Raised if `/etc/nhc/nhc.conf` is not found on machine.
"""
target = Path("/etc/nhc/nhc.conf")
if target.exists():
try:
return target.read_text()

return f"{target} not found."
except FileNotFoundError:
_logger.warning("%s not found", target)
raise


def generate_config(nhc_config: str) -> None:
Expand Down

0 comments on commit fe37b1d

Please sign in to comment.