Skip to content

Commit

Permalink
Merge pull request #165 from canonical/fix-juju-info-network-get
Browse files Browse the repository at this point in the history
fixed juju-info network
  • Loading branch information
PietroPasotti authored Jul 31, 2024
2 parents 58e514e + 90cd342 commit 7242fdd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ops-scenario"

version = "6.1.3"
version = "6.1.4"

authors = [
{ name = "Pietro Pasotti", email = "[email protected]" }
Expand Down
3 changes: 3 additions & 0 deletions scenario/consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ def check_network_consistency(
errors = []

meta_bindings = set(charm_spec.meta.get("extra-bindings", ()))
# add the implicit juju-info binding so we can override its network without
# having to declare a relation for it in metadata
meta_bindings.add("juju-info")
all_relations = charm_spec.get_all_relations()
non_sub_relations = {
endpoint
Expand Down
3 changes: 3 additions & 0 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ def network_get(self, binding_name: str, relation_id: Optional[int] = None):
"cannot pass relation_id to network_get if the binding name is "
"that of an extra-binding. Extra-bindings are not mapped to relation IDs.",
)
elif binding_name == "juju-info":
# implicit relation that always exists
pass
# - verify that the binding is a relation endpoint name, but not a subordinate one
elif binding_name not in non_sub_relations:
logger.error(
Expand Down
38 changes: 37 additions & 1 deletion tests/test_e2e/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,40 @@ def test_no_relation_error(mycharm):
),
) as mgr:
with pytest.raises(RelationNotFoundError):
net = mgr.charm.model.get_binding("foo").network
mgr.charm.model.get_binding("foo").network


def test_juju_info_network_default(mycharm):
ctx = Context(
mycharm,
meta={"name": "foo"},
)

with ctx.manager(
"update_status",
State(),
) as mgr:
# we have a network for the relation
assert (
str(mgr.charm.model.get_binding("juju-info").network.bind_address)
== "192.0.2.0"
)


def test_juju_info_network_override(mycharm):
ctx = Context(
mycharm,
meta={"name": "foo"},
)

with ctx.manager(
"update_status",
State(
networks={"juju-info": Network.default(private_address="4.4.4.4")},
),
) as mgr:
# we have a network for the relation
assert (
str(mgr.charm.model.get_binding("juju-info").network.bind_address)
== "4.4.4.4"
)

0 comments on commit 7242fdd

Please sign in to comment.