Mongod-exporter charm: fixing connection string in HA
Change-Id: I606a36a373c39d7d15e572d90065acd093506de5
Signed-off-by: sousaedu <eduardo.sousa@canonical.com>
diff --git a/installers/charm/mongodb-exporter/src/pod_spec.py b/installers/charm/mongodb-exporter/src/pod_spec.py
index 781c689..8255b20 100644
--- a/installers/charm/mongodb-exporter/src/pod_spec.py
+++ b/installers/charm/mongodb-exporter/src/pod_spec.py
@@ -122,10 +122,15 @@
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 5fc255e..372886b 100644
--- a/installers/charm/mongodb-exporter/tests/test_charm.py
+++ b/installers/charm/mongodb-exporter/tests/test_charm.py
@@ -37,7 +37,6 @@
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."""