diff --git a/charms/istio-pilot/src/charm.py b/charms/istio-pilot/src/charm.py index 8ca6617d..95923746 100755 --- a/charms/istio-pilot/src/charm.py +++ b/charms/istio-pilot/src/charm.py @@ -439,6 +439,10 @@ def _get_ingress_auth_data(self, event) -> dict: if app != self.app } + # Go into waiting status if there is no ingress-auth data + if not ingress_auth_data: + raise ErrorWithStatus("Waiting for the auth provider data.", WaitingStatus) + # We only support a single ingress-auth relation, so we can unpack and return just the # contents if len(ingress_auth_data) > 1: diff --git a/charms/istio-pilot/tests/unit/test_charm.py b/charms/istio-pilot/tests/unit/test_charm.py index 0b2efe39..d04b04d9 100644 --- a/charms/istio-pilot/tests/unit/test_charm.py +++ b/charms/istio-pilot/tests/unit/test_charm.py @@ -216,6 +216,8 @@ def test_ingress_auth_and_gateway( harness.begin() + harness.charm.log = MagicMock() + # Do a reconcile harness.charm.on.config_changed.emit() @@ -228,9 +230,18 @@ def test_ingress_auth_and_gateway( # Add "broken" ingress_auth (empty data) and check that we remove the gateway rel_id = harness.add_relation("ingress-auth", "other") + add_data_to_sdi_relation(harness, rel_id, "other", {}) mocked_remove_gateway.assert_called_once mocked_remove_gateway.reset_mock() + assert harness.charm.model.unit.status == WaitingStatus( + "Execution handled 1 errors. See logs for details." + ) + assert ( + "Handled error 0/1: WaitingStatus('Waiting for the auth provider data.')" + in harness.charm.log.info.call_args.args + ) + # Remove ingress_auth relation and check that we re-add the gateway harness.remove_relation(rel_id) assert krh_lightkube_client.apply.call_count == 1 @@ -570,6 +581,17 @@ def test_get_ingress_auth_data_empty( assert len(ingress_auth_data) == 0 + def test_get_ingress_auth_data_empty_error(self, harness): + """Tests that the _get_ingress_auth_data helper returns the correct relation data.""" + harness.begin() + rel_id = harness.add_relation("ingress-auth", "other") + add_data_to_sdi_relation(harness, rel_id, "other", {}) + with pytest.raises(ErrorWithStatus) as err: + harness.charm._get_ingress_auth_data("not-relation-broken-event") + + assert err.value.status_type.name == "waiting" + assert "Waiting for the auth provider data." == err.value.msg + def test_get_ingress_auth_data_too_many_relations( self, harness,