Skip to content

feat!: only provide the Juju default databag keys while the charm runs - #2637

Draft
tonyandrewmeyer wants to merge 4 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2185-juju-default-databag-at-exec
Draft

feat!: only provide the Juju default databag keys while the charm runs#2637
tonyandrewmeyer wants to merge 4 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2185-juju-default-databag-at-exec

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Relation databags (local_unit_data, remote_units_data, remote_unit_data) now default to empty dicts. While the charm is running, Scenario adds the keys that Juju manages itself (egress-subnets, ingress-address, and on Juju 3 private-address) to every unit databag, and removes them again before the output state is returned, so that the output state has the same shape as the input one. A key that the charm wrote to while it was running is left in place.

The values come from the Network for the relation's endpoint, the way Juju does it: ingress-address (and private-address) is the first ingress address, and egress-subnets is the comma-separated list of egress subnets. With the default network that means egress-subnets is now 192.0.2.0/24 rather than 192.0.2.0. I checked this against 3.6.27 and 4.0.12 on LXD, and in both the databag values match network-get exactly (egress-subnets: 10.5.87.59/32, ingress-address: 10.5.87.59), with 4.0 not setting private-address at all.

This is the backwards-incompatible alternative to #2618: instead of stripping private-address from the construction default when the mocked Juju version is 4+, Scenario provides the keys that the real Juju would provide, sort-of for as long as it would provide them.

Fixes #2185.

Relation databags (`local_unit_data`, `remote_units_data`,
`remote_unit_data`) now default to empty dicts. Just before the charm
runs, Scenario injects the keys Juju itself auto-populates
(`egress-subnets`, `ingress-address`, and on Juju 3 `private-address`)
into every unit databag, and they flow through to the output state.

This is the backwards-incompatible alternative to canonical#2618: instead of
stripping `private-address` from the construction default when the
mocked Juju version is 4+, Scenario now matches Juju's own behaviour
and only inserts the keys the real Juju would insert. Tests that read
a `Relation`'s databag before running the charm will see empty dicts.

Fixes canonical#2185.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tonyandrewmeyer tonyandrewmeyer changed the title feat!: inject Juju default databag keys at exec time feat!: only provide the Juju default databag keys while the charm runs Sep 3, 2026
tonyandrewmeyer and others added 2 commits September 3, 2026 18:06
The keys that Juju manages itself (`egress-subnets`, `ingress-address`, and
on Juju 3 `private-address`) are injected into every relation unit databag
just before the charm runs, and removed again before the output state is
returned, so the output state has the same shape as the input one. A key
that the charm wrote to while it was running is left in place.

The values now come from the `Network` for the relation's endpoint, as they
do in Juju: `ingress-address` (and `private-address`) is the first ingress
address, and `egress-subnets` is the comma-separated list of egress subnets.
With the default network that means `egress-subnets` is now `192.0.2.0/24`
rather than `192.0.2.0`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DdyoibByxhQVcn65aavYfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't include private-address in the default Scenario database when mocking Juju 4

1 participant