From 1d7987fe4880cbf8ebd11a1c5beade57711421d4 Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Wed, 31 Jul 2024 10:42:20 +0200 Subject: [PATCH 1/3] fixed juju-info network --- scenario/consistency_checker.py | 3 +++ scenario/mocking.py | 3 +++ tests/test_e2e/test_network.py | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/scenario/consistency_checker.py b/scenario/consistency_checker.py index 50eb939d..c4397efd 100644 --- a/scenario/consistency_checker.py +++ b/scenario/consistency_checker.py @@ -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 diff --git a/scenario/mocking.py b/scenario/mocking.py index 02d92043..ac56d719 100644 --- a/scenario/mocking.py +++ b/scenario/mocking.py @@ -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( diff --git a/tests/test_e2e/test_network.py b/tests/test_e2e/test_network.py index 07808e1d..0a7089e4 100644 --- a/tests/test_e2e/test_network.py +++ b/tests/test_e2e/test_network.py @@ -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" + ) From 385dbea680551b65d33179adde5e7b938b19763c Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Wed, 31 Jul 2024 10:44:42 +0200 Subject: [PATCH 2/3] vbump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ac35451c..0d16c44a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "pietro.pasotti@canonical.com" } From 90cd3427a2ed3b02dc5d7e25d3d4d98f540e83d6 Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Wed, 31 Jul 2024 12:53:45 +0200 Subject: [PATCH 3/3] fmt --- tests/test_e2e/test_network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_e2e/test_network.py b/tests/test_e2e/test_network.py index 0a7089e4..07223475 100644 --- a/tests/test_e2e/test_network.py +++ b/tests/test_e2e/test_network.py @@ -117,7 +117,7 @@ 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):