From fe37b1d74185aed60ca524f23e3cf0521036df7e Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Mon, 18 Nov 2024 10:22:29 -0500 Subject: [PATCH] refactor(slurmd): raise `FileNotFoundError` if `/etc/nhc/nhc.conf` does not exist Signed-off-by: Jason C. Nucciarone --- charms/slurmd/src/charm.py | 9 +++++---- charms/slurmd/src/utils/nhc.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/charms/slurmd/src/charm.py b/charms/slurmd/src/charm.py index 7b51b3c..4d404de 100755 --- a/charms/slurmd/src/charm.py +++ b/charms/slurmd/src/charm.py @@ -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. @@ -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: diff --git a/charms/slurmd/src/utils/nhc.py b/charms/slurmd/src/utils/nhc.py index 23ed27c..7bd3033 100644 --- a/charms/slurmd/src/utils/nhc.py +++ b/charms/slurmd/src/utils/nhc.py @@ -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: