From ed17b2c3db4ac6d2da1589dd9ffd8115e5fd6778 Mon Sep 17 00:00:00 2001 From: sousaedu Date: Thu, 25 Mar 2021 17:19:10 +0100 Subject: [PATCH] Mongod-exporter charm: fixing connection string in HA Change-Id: I606a36a373c39d7d15e572d90065acd093506de5 Signed-off-by: sousaedu --- installers/charm/mongodb-exporter/src/pod_spec.py | 7 ++++++- installers/charm/mongodb-exporter/tests/test_charm.py | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/installers/charm/mongodb-exporter/src/pod_spec.py b/installers/charm/mongodb-exporter/src/pod_spec.py index 781c6892..8255b201 100644 --- a/installers/charm/mongodb-exporter/src/pod_spec.py +++ b/installers/charm/mongodb-exporter/src/pod_spec.py @@ -122,10 +122,15 @@ def _make_pod_envconfig( Returns: Dict[str, Any]: pod environment configuration. """ + parsed = urlparse(relation_state.get("mongodb_connection_string")) + envconfig = { - "MONGODB_URI": relation_state.get("mongodb_connection_string"), + "MONGODB_URI": f"mongodb://{parsed.netloc.split(',')[0]}{parsed.path}", } + if parsed.query: + envconfig["MONGODB_URI"] += f"?{parsed.query}" + return envconfig diff --git a/installers/charm/mongodb-exporter/tests/test_charm.py b/installers/charm/mongodb-exporter/tests/test_charm.py index 5fc255ef..372886b4 100644 --- a/installers/charm/mongodb-exporter/tests/test_charm.py +++ b/installers/charm/mongodb-exporter/tests/test_charm.py @@ -37,7 +37,6 @@ class TestCharm(unittest.TestCase): self.harness = Harness(MongodbExporterCharm) self.harness.set_leader(is_leader=True) self.harness.begin() - self.harness.update_config(self.config) def test_on_start_without_relations(self) -> NoReturn: """Test installation without any relation.""" -- 2.25.1