From: sousaedu Date: Thu, 25 Mar 2021 16:19:10 +0000 (+0100) Subject: Mongod-exporter charm: fixing connection string in HA X-Git-Tag: branch-sol006v331-start~28 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F51%2F10551%2F3;p=osm%2Fdevops.git Mongod-exporter charm: fixing connection string in HA Change-Id: I606a36a373c39d7d15e572d90065acd093506de5 Signed-off-by: sousaedu --- 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."""