Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Go to WaitingStatus if ingress not ready #264

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
database_integration_exists,
leader_unit,
peer_integration_exists,
public_ingress_integration_exists,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -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"),
Expand All @@ -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)
Expand Down