-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove unnecessary leadership guards in GrafanaCloudConfigRequir…
…er (#13) * fix: remove unnecessary leadership guards in GrafanaCloudConfigRequirer Previously, GrafanaCloudConfigRequirer would only emit a cloud_config_* event on relation changed/broken if this unit is a leader. This caused issues with multi-unit deployments as described in [#12](#12). Since GrafanaCloudConfigRequirer only reads the relation remote's application_data, there is no need for a leadership guard because non-leader units have permission to read this data. The current commit removes these guards.
- Loading branch information
1 parent
cded809
commit 394866d
Showing
4 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
from charms.grafana_cloud_integrator.v0.cloud_config_requirer import ( | ||
CloudConfigAvailableEvent, | ||
CloudConfigRevokedEvent, | ||
GrafanaCloudConfigRequirer, | ||
) | ||
from ops import CharmBase, Framework | ||
from scenario import Context, Relation, State | ||
|
||
|
||
class MyCharm(CharmBase): | ||
def __init__(self, framework: Framework): | ||
super().__init__(framework) | ||
self.cloud = GrafanaCloudConfigRequirer(self) | ||
|
||
|
||
@pytest.fixture() | ||
def mycharm_context(): | ||
"""Returns a Context object with a MyCharm instance.""" | ||
return Context( | ||
charm_type=MyCharm, | ||
meta={ | ||
"name": "my-charm", | ||
"requires": { | ||
"grafana-cloud-config": {"interface": "grafana_cloud_config", "limit": 1} | ||
}, | ||
}, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("is_leader", [(True,), (False,)]) | ||
def test_requirer_emits_cloud_config_available_event_on_relation_changed( | ||
is_leader, mycharm_context | ||
): | ||
# GIVEN a grafana-cloud-config relation and a leadership status | ||
grafana_cloud_config_relation = Relation("grafana-cloud-config") | ||
state = State(leader=is_leader, relations=[grafana_cloud_config_relation]) | ||
|
||
# WHEN the grafana-cloud-config relation changes | ||
mycharm_context.run(grafana_cloud_config_relation.changed_event, state) | ||
|
||
# THEN the CloudConfigAvailableEvent event is emitted | ||
assert any( | ||
event | ||
for event in mycharm_context.emitted_events | ||
if isinstance(event, CloudConfigAvailableEvent) | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("is_leader", [(True,), (False,)]) | ||
def test_requirer_emits_cloud_config_revoked_event_on_relation_broken(is_leader, mycharm_context): | ||
# GIVEN a grafana-cloud-config relation | ||
grafana_cloud_config_relation = Relation("grafana-cloud-config") | ||
# AND GIVEN leadership/non-leadership | ||
state = State(leader=is_leader, relations=[grafana_cloud_config_relation]) | ||
|
||
# WHEN the grafana-cloud-config relation changes | ||
mycharm_context.run(grafana_cloud_config_relation.broken_event, state) | ||
|
||
# THEN the CloudConfigAvailableEvent event is emitted | ||
assert any( | ||
event | ||
for event in mycharm_context.emitted_events | ||
if isinstance(event, CloudConfigRevokedEvent) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters