diff --git a/src/charm.py b/src/charm.py index d021e78e..472bc11a 100755 --- a/src/charm.py +++ b/src/charm.py @@ -143,11 +143,14 @@ def _on_update_status(self, _: EventBase) -> None: # noqa: C901 self.model.unit.status = BlockedStatus(error_msg) return - if self._stored.exporter_installed: # type: ignore[truthy-function] - if not self.exporter.check_active(): - logger.warning("Exporter health check - failed.") - # if restart isn't successful, an ExporterError exception will be raised here - self.restart_exporter() + if not self._stored.exporter_installed: # type: ignore[truthy-function] + logger.warning("Exporter not installed") # type: ignore[unreachable] + return + + if not self.exporter.check_health(): + logger.warning("Exporter health check - failed.") + # if restart isn't successful, an ExporterError exception will be raised here + self.restart_exporter() self.model.unit.status = ActiveStatus("Unit is ready") diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 3b4db824..e51865e0 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -206,6 +206,7 @@ def test_09_update_status_exporter_crashed(self, mock_hw_tool_helper, mock_expor self.harness.add_relation("cos-agent", "grafana-agent") self.harness.begin() self.harness.charm._stored.resource_installed = True + self.harness.charm._stored.exporter_installed = True with self.assertRaises(ExporterError): self.harness.charm.on.update_status.emit()