Mongod-exporter charm: fixing connection string in HA 51/10551/3
authorsousaedu <eduardo.sousa@canonical.com>
Thu, 25 Mar 2021 16:19:10 +0000 (17:19 +0100)
committerbeierlm <mark.beierl@canonical.com>
Fri, 26 Mar 2021 11:25:31 +0000 (12:25 +0100)
Change-Id: I606a36a373c39d7d15e572d90065acd093506de5
Signed-off-by: sousaedu <eduardo.sousa@canonical.com>
installers/charm/mongodb-exporter/src/pod_spec.py
installers/charm/mongodb-exporter/tests/test_charm.py

index 781c689..8255b20 100644 (file)
@@ -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
 
 
index 5fc255e..372886b 100644 (file)
@@ -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."""