diff --git a/src/charm.py b/src/charm.py index 972c57cd..1a13fb1d 100755 --- a/src/charm.py +++ b/src/charm.py @@ -88,6 +88,7 @@ database_integration_exists, leader_unit, peer_integration_exists, + public_ingress_integration_exists, ) logger = logging.getLogger(__name__) @@ -480,12 +481,16 @@ def _holistic_handler(self, event: HookEvent) -> None: self.unit.status = BlockedStatus(f"Missing integration {DATABASE_INTEGRATION_NAME}") return - if not self.public_ingress.is_ready(): + if not public_ingress_integration_exists(self): self.unit.status = BlockedStatus( f"Missing required relation with {PUBLIC_INGRESS_INTEGRATION_NAME}" ) return + if not self.public_ingress.is_ready(): + self.unit.status = WaitingStatus("Waiting for ingress to be ready") + return + if not self.database_requirer.is_resource_created(): self.unit.status = WaitingStatus("Waiting for database creation") return diff --git a/src/utils.py b/src/utils.py index 772127ad..da52a466 100644 --- a/src/utils.py +++ b/src/utils.py @@ -6,7 +6,12 @@ from ops.charm import CharmBase -from constants import DATABASE_INTEGRATION_NAME, PEER_INTEGRATION_NAME, WORKLOAD_CONTAINER +from constants import ( + DATABASE_INTEGRATION_NAME, + PEER_INTEGRATION_NAME, + PUBLIC_INGRESS_INTEGRATION_NAME, + WORKLOAD_CONTAINER, +) CharmEventHandler = TypeVar("CharmEventHandler", bound=Callable[..., Any]) Condition = Callable[[CharmBase], bool] @@ -36,6 +41,7 @@ def wrapped(charm: CharmBase) -> bool: peer_integration_exists = integration_existence(PEER_INTEGRATION_NAME) database_integration_exists = integration_existence(DATABASE_INTEGRATION_NAME) +public_ingress_integration_exists = integration_existence(PUBLIC_INGRESS_INTEGRATION_NAME) def container_connectivity(charm: CharmBase) -> bool: diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 8097262a..cccc0975 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -655,7 +655,7 @@ def test_when_database_integration_missing( f"Missing integration {DATABASE_INTEGRATION_NAME}" ) - def test_when_public_ingress_not_ready( + def test_when_no_public_ingress_integration( self, harness: Harness, mocked_event: MagicMock, @@ -670,10 +670,25 @@ def test_when_public_ingress_not_ready( f"Missing required relation with " f"{PUBLIC_INGRESS_INTEGRATION_NAME}" ) + def test_when_public_ingress_not_ready( + self, + harness: Harness, + mocked_event: MagicMock, + mocked_pebble_service: MagicMock, + public_ingress_integration: MagicMock, + ) -> None: + with patch("charm.IngressPerAppRequirer.is_ready", return_value=False): + harness.charm._holistic_handler(mocked_event) + + mocked_pebble_service.push_config_file.assert_not_called() + mocked_pebble_service.plan.assert_not_called() + assert harness.charm.unit.status == WaitingStatus("Waiting for ingress to be ready") + def test_when_database_not_ready( self, harness: Harness, mocked_event: MagicMock, + public_ingress_integration_data: MagicMock, mocked_pebble_service: MagicMock, ) -> None: with patch("charm.DatabaseRequires.is_resource_created", return_value=False): @@ -687,6 +702,7 @@ def test_when_migration_is_needed( self, harness: Harness, mocked_event: MagicMock, + public_ingress_integration_data: MagicMock, mocked_pebble_service: MagicMock, ) -> None: with patch( @@ -704,6 +720,7 @@ def test_when_secrets_not_ready( self, harness: Harness, mocked_event: MagicMock, + public_ingress_integration_data: MagicMock, mocked_pebble_service: MagicMock, mocked_secrets: MagicMock, ) -> None: @@ -718,8 +735,8 @@ def test_when_pebble_plan_failed( self, harness: Harness, mocked_event: MagicMock, + public_ingress_integration_data: MagicMock, mocked_pebble_service: MagicMock, - mocked_public_ingress_data: MagicMock, ) -> None: with ( patch("charm.ConfigFile.from_sources", return_value="config"), @@ -736,8 +753,8 @@ def test_when_succeeds( self, harness: Harness, mocked_event: MagicMock, + public_ingress_integration_data: MagicMock, mocked_pebble_service: MagicMock, - mocked_public_ingress_data: MagicMock, ) -> None: with patch("charm.ConfigFile.from_sources", return_value="config"): harness.charm._holistic_handler(mocked_event)