Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed juju-info network #165

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 36 additions & 0 deletions tests/test_e2e/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,39 @@ def test_no_relation_error(mycharm):
) as mgr:
with pytest.raises(RelationNotFoundError):
net = 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"
)
Loading