Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Clean up logic in _on_config_changed event #285

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
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def _on_config_changed(self, event: EventBase) -> None:
event.handle,
)
event.defer()
return

if self.cos_agent_related:
jneo8 marked this conversation as resolved.
Show resolved Hide resolved
success, message = self.validate_configs()
Expand Down
47 changes: 26 additions & 21 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,29 +552,34 @@ def test_config_changed(

if not resource_installed:
mock_logger.info.assert_called()
if not cos_agent_related:
self.harness.charm.validate_configs.assert_not_called()
self.harness.charm._on_update_status.assert_not_called()
else:
zxhdaze marked this conversation as resolved.
Show resolved Hide resolved
if not cos_agent_related:
self.harness.charm.validate_configs.assert_not_called()
self.harness.charm._on_update_status.assert_called()
return
if not validate_configs_return[0]:
self.assertEqual(self.harness.charm.unit.status, BlockedStatus("invalid msg"))
self.harness.charm.exporters[0].render_config.assert_not_called()
return
if not all(mock_exporters_render_config_returns):
for mock_exporter, render_config_return in zip(
mock_exporters,
mock_exporters_render_config_returns,
):
if render_config_return:
mock_exporter.restart.assert_called()
else:
message = (
f"Failed to configure {mock_exporter.exporter_name}, "
f"please check if the server is healthy."
)
self.assertEqual(
self.harness.charm.unit.status, BlockedStatus(message)
)
self.harness.charm._on_update_status.assert_called()
gabrielcocenza marked this conversation as resolved.
Show resolved Hide resolved
self.harness.charm._on_update_status.assert_called()
return
if not validate_configs_return[0]:
self.assertEqual(self.harness.charm.unit.status, BlockedStatus("invalid msg"))
self.harness.charm.exporters[0].render_config.assert_not_called()
return
if not all(mock_exporters_render_config_returns):
for mock_exporter, render_config_return in zip(
mock_exporters,
mock_exporters_render_config_returns,
):
if render_config_return:
mock_exporter.restart.assert_called()
else:
message = (
f"Failed to configure {mock_exporter.exporter_name}, "
f"please check if the server is healthy."
)
self.assertEqual(self.harness.charm.unit.status, BlockedStatus(message))
self.harness.charm._on_update_status.assert_called()
self.harness.charm._on_update_status.assert_called()

def test_config_changed_update_alert_rules(self):
"""Test config changed will update alert rule."""
Expand Down
Loading