Skip to content

Commit

Permalink
Strengthen the consistency check: the Check must be in the correct Co…
Browse files Browse the repository at this point in the history
…ntainer.
  • Loading branch information
tonyandrewmeyer committed Jul 24, 2024
1 parent 0c160d5 commit e5e454c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scenario/consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ def check_containers_consistency(
meta_containers = list(map(normalize_name, meta.get("containers", {})))
state_containers = [normalize_name(c.name) for c in state.containers]
all_notices = {notice.id for c in state.containers for notice in c.notices}
all_checks = {check.name for c in state.containers for check in c.check_infos}
all_checks = {
(c.name, check.name) for c in state.containers for check in c.check_infos
}
errors = []

# it's fine if you have containers in meta that are not in state.containers (yet), but it's
Expand All @@ -585,10 +587,13 @@ def check_containers_consistency(
f"the event being processed concerns notice {event.notice!r}, but that "
"notice is not in any of the containers present in the state.",
)
if event.check_info and event.check_info.name not in all_checks:
if (
event.check_info
and (evt_container_name, event.check_info.name) not in all_checks
):
errors.append(
f"the event being processed concerns check {event.check_info.name}, but that "
"check is not in any of the containers present in the state.",
"check is not the {evt_container_name} container.",
)

# - a container in state.containers is not in meta.containers
Expand Down
15 changes: 15 additions & 0 deletions tests/test_consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ def test_workload_event_without_container():
),
_CharmSpec(MyCharm, {"containers": {"foo": {}}}),
)
# Ensure the check is in the correct container.
assert_inconsistent(
State(containers={Container("foo", check_infos={check}), Container("bar")}),
_Event(
"foo-pebble-check-recovered", container=Container("bar"), check_info=check
),
_CharmSpec(MyCharm, {"containers": {"foo": {}, "bar": {}}}),
)
assert_inconsistent(
State(containers={Container("foo", check_infos={check}), Container("bar")}),
_Event(
"bar-pebble-check-recovered", container=Container("bar"), check_info=check
),
_CharmSpec(MyCharm, {"containers": {"foo": {}, "bar": {}}}),
)


def test_container_meta_mismatch():
Expand Down

0 comments on commit e5e454c

Please sign in to comment.