From 70fd92ad2b36ba7939c6984e194fa7024d1743fb Mon Sep 17 00:00:00 2001 From: NucciTheBoss Date: Tue, 25 Apr 2023 16:12:21 -0400 Subject: [PATCH 1/4] feat: Add version file to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a26d707..9ceb2e5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__/ *.py[cod] .idea .vscode/ +version From 6f2fd34974dc4902991d56825f454692ff919b17 Mon Sep 17 00:00:00 2001 From: NucciTheBoss Date: Tue, 25 Apr 2023 16:17:02 -0400 Subject: [PATCH 2/4] feat: Use `juju-reboot` to auto-restart machines --- src/charm.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/charm.py b/src/charm.py index 20e89da..5ea1213 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1,6 +1,11 @@ #!/usr/bin/env python3 +# Copyright 2020 Omnivector Solutions, LLC. +# See LICENSE file for licensing details. + """SlurmrestdCharm.""" + import logging +import subprocess from pathlib import Path from charms.fluentbit.v0.fluentbit import FluentbitClient @@ -8,11 +13,7 @@ from ops.charm import CharmBase from ops.framework import StoredState from ops.main import main -from ops.model import ( - ActiveStatus, - BlockedStatus, - WaitingStatus, -) +from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from slurm_ops_manager import SlurmManager logger = logging.getLogger() @@ -135,7 +136,12 @@ def _on_configure_jwt_rsa(self, event): def _check_status(self) -> bool: if self._slurm_manager.needs_reboot: - self.unit.status = BlockedStatus("Machine needs reboot") + try: + self.unit.status = MaintenanceStatus("Rebooting...") + logger.debug("Scheduling machine reboot") + subprocess.run(["juju-reboot"], check=True) + except subprocess.CalledProcessError: + logger.error("Failed to schedule machine reboot") return False if not self._stored.slurm_installed: From 28fb74392a585c915e4b3b8acd68e07e7ea2e241 Mon Sep 17 00:00:00 2001 From: NucciTheBoss Date: Thu, 27 Apr 2023 14:49:58 -0400 Subject: [PATCH 3/4] refactor: Drop needs_reboot conditional --- src/charm.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/charm.py b/src/charm.py index 5ea1213..c9eac4d 100755 --- a/src/charm.py +++ b/src/charm.py @@ -5,7 +5,6 @@ """SlurmrestdCharm.""" import logging -import subprocess from pathlib import Path from charms.fluentbit.v0.fluentbit import FluentbitClient @@ -13,7 +12,7 @@ from ops.charm import CharmBase from ops.framework import StoredState from ops.main import main -from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus +from ops.model import ActiveStatus, BlockedStatus, WaitingStatus from slurm_ops_manager import SlurmManager logger = logging.getLogger() @@ -135,15 +134,6 @@ def _on_configure_jwt_rsa(self, event): self._slurm_manager.configure_jwt_rsa(jwt_rsa) def _check_status(self) -> bool: - if self._slurm_manager.needs_reboot: - try: - self.unit.status = MaintenanceStatus("Rebooting...") - logger.debug("Scheduling machine reboot") - subprocess.run(["juju-reboot"], check=True) - except subprocess.CalledProcessError: - logger.error("Failed to schedule machine reboot") - return False - if not self._stored.slurm_installed: self.unit.status = BlockedStatus("Error installing slurmrestd") return False From 0981affe4e335f096f5782ae989d4219f9c7357b Mon Sep 17 00:00:00 2001 From: NucciTheBoss Date: Thu, 27 Apr 2023 14:56:27 -0400 Subject: [PATCH 4/4] cleanup: Remove needs_reboot patches from unit tests --- tests/unit/test_charm.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 977c1b6..9b007de 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -39,10 +39,6 @@ def test_config_available_fail(self, defer): "interface_slurmrestd.SlurmrestdRequires.get_stored_slurm_config", return_value={"cluster_name": "test"}, ) - @patch( - "slurm_ops_manager.SlurmManager.needs_reboot", - new_callable=PropertyMock(return_value=False), - ) @patch( "interface_slurmrestd.SlurmrestdRequires.is_joined", new_callable=PropertyMock(return_value=True), @@ -69,10 +65,6 @@ def test_install_fail(self, defer, *_): self.assertFalse(self.harness.charm._stored.slurm_installed) defer.assert_called() - @patch( - "slurm_ops_manager.SlurmManager.needs_reboot", - new_callable=PropertyMock(return_value=False), - ) @patch( "interface_slurmrestd.SlurmrestdRequires.is_joined", new_callable=PropertyMock(return_value=True), @@ -125,10 +117,6 @@ def test_restart_slurmrestd_fail(self, defer): defer.assert_called() @patch("slurm_ops_manager.SlurmManager.restart_slurm_component", lambda _: True) - @patch( - "slurm_ops_manager.SlurmManager.needs_reboot", - new_callable=PropertyMock(return_value=False), - ) @patch( "interface_slurmrestd.SlurmrestdRequires.is_joined", new_callable=PropertyMock(return_value=True), @@ -154,10 +142,6 @@ def test_update_status_fail(self): self.harness.charm.unit.status, BlockedStatus("Error installing slurmrestd") ) - @patch( - "slurm_ops_manager.SlurmManager.needs_reboot", - new_callable=PropertyMock(return_value=False), - ) @patch( "interface_slurmrestd.SlurmrestdRequires.is_joined", new_callable=PropertyMock(return_value=True), @@ -179,10 +163,6 @@ def test_upgrade_fail(self, *_): ) @patch("pathlib.Path.read_text", return_value="v1.0.0") - @patch( - "slurm_ops_manager.SlurmManager.needs_reboot", - new_callable=PropertyMock(return_value=False), - ) @patch( "interface_slurmrestd.SlurmrestdRequires.is_joined", new_callable=PropertyMock(return_value=True),