canonical / ops-scenario

State-transition testing SDK for Operator Framework Juju charms.
Apache License 2.0
10 stars 7 forks source link

feat: add support for Pebble check events #151

Closed tonyandrewmeyer closed 1 month ago

tonyandrewmeyer commented 2 months ago

Adds support for the {container-name}-pebble-check-failed and {container-name}-pebble-check-recovered events that will be available in Juju 3.6.

Example usage:

ctx = Context(MyCharm)
check_info = CheckInfo("http-check", failures=7, status=ops.pebble.CheckStatus.DOWN)
container = Container("my-container", check_infos={check_info})
state = State(containers={container})

ctx.run(ctx.on.pebble_check_failed(container=container, info=check_info), state)

Also updates the support for Pebble custom notice events to align with the 7.x approach (event from ctx.on, notices are a frozenset).

Updated usage:

ctx = Context(MyCharm)
notices = [
    Notice(key="example.com/a", occurrences=10),
    Notice(key="example.com/b", last_data={"bar": "baz"}),
    Notice(key="example.com/c"),
]
container = Container("my-container", notices=notices)
state = State(containers={container})

ctx.run(ctx.on.pebble_custom_notice(container=container, notice=notices[-1]), state)
tonyandrewmeyer commented 2 months ago

The merge broke the linting check because I forgot to reorder them. I'll fix that later. The test pass if you use ops main - I assume we would not merge this until that's become 2.15 anyway, so will trigger the tests before that.