Skip to content

Commit

Permalink
fix(charm): make collect-status a LifeCycleEvent to avoid logging it (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Jan 30, 2024
1 parent 4678130 commit d49fa98
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ops/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
EventSource,
Framework,
Handle,
LifecycleEvent,
Object,
ObjectEvents,
)
Expand Down Expand Up @@ -914,7 +915,7 @@ def defer(self) -> NoReturn:
'this event until you create a new revision.')


class CollectStatusEvent(EventBase):
class CollectStatusEvent(LifecycleEvent):
"""Event triggered at the end of every hook to collect statuses for evaluation.
If the charm wants to provide application or unit status in a consistent
Expand Down
1 change: 1 addition & 0 deletions ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ def _reemit(self, single_event_path: Optional[str] = None):
elif self._event_name and self._event_name != event.handle.kind:
# if the event we are emitting now is not the event being
# dispatched, and it also is not an event we have deferred,
# and is also not a lifecycle (framework-emitted) event,
# it must be a custom event
logger.debug("Emitting custom event %s.", event)

Expand Down
8 changes: 5 additions & 3 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,11 @@ def _call_event(self, rel_path: Path, env: typing.Dict[str, str]):

def test_setup_event_links(self):
"""Test auto-creation of symlinks caused by initial events."""
all_event_hooks = [f"hooks/{name.replace('_', '-')}"
for name, event_source in self.charm_module.Charm.on.events().items()
if issubclass(event_source.event_type, ops.LifecycleEvent)]
all_event_hooks = [
f"hooks/{name.replace('_', '-')}"
for name, event_source in self.charm_module.Charm.on.events().items()
if issubclass(event_source.event_type, (ops.CommitEvent, ops.PreCommitEvent))
]

initial_events = {
EventSpec(ops.InstallEvent, 'install'),
Expand Down

0 comments on commit d49fa98

Please sign in to comment.