Make tcpsocket readiness and liveness configurable
[osm/devops.git] / installers / charm / nbi / tests / test_charm.py
index 92c2980..59a27fb 100644 (file)
@@ -155,6 +155,42 @@ class TestCharm(unittest.TestCase):
         # Verifying status
         self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
 
+    def test_config_liveness_probe_with_relations(
+        self,
+    ) -> NoReturn:
+        "Test configuration of liveness probe with relations"
+        self.initialize_nbi_with_keystone()
+        self.config_liveness_probe()
+        # Verifying status
+        self.assertIsInstance(self.harness.charm.unit.status, ActiveStatus)
+
+    def test_wrong_config_liveness_probe_with_relations(
+        self,
+    ) -> NoReturn:
+        "Test wrong configuration of liveness probe with relations"
+        self.initialize_nbi_with_keystone()
+        self.wrong_config_liveness_probe()
+        # Verifying status
+        self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
+
+    def test_config_readiness_probe_with_relations(
+        self,
+    ) -> NoReturn:
+        "Test configuration of readiness probe with relations"
+        self.initialize_nbi_with_keystone()
+        self.config_readiness_probe()
+        # Verifying status
+        self.assertIsInstance(self.harness.charm.unit.status, ActiveStatus)
+
+    def test_wrong_config_readiness_probe_with_relations(
+        self,
+    ) -> NoReturn:
+        "Test wrong configuration of readiness probe with relations"
+        self.initialize_nbi_with_keystone()
+        self.wrong_config_readiness_probe()
+        # Verifying status
+        self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
+
     def initialize_kafka_relation(self):
         kafka_relation_id = self.harness.add_relation("kafka", "kafka")
         self.harness.add_relation_unit(kafka_relation_id, "kafka/0")
@@ -165,6 +201,33 @@ class TestCharm(unittest.TestCase):
     def initialize_mongo_config(self):
         self.harness.update_config({"mongodb_uri": "mongodb://mongo:27017"})
 
+    def initialize_nbi_with_keystone(self):
+        self.harness.update_config({"auth_backend": "keystone"})
+        self.initialize_kafka_relation()
+        self.initialize_mongo_relation()
+        self.initialize_prometheus_relation()
+        self.initialize_keystone_relation()
+
+    def config_liveness_probe(self):
+        self.harness.update_config(
+            {"tcpsocket_liveness_probe": '{"initial_delay_seconds": 10}'}
+        )
+
+    def wrong_config_liveness_probe(self):
+        self.harness.update_config(
+            {"tcpsocket_liveness_probe": "{initial_delay_seconds: 10}"}
+        )
+
+    def wrong_config_readiness_probe(self):
+        self.harness.update_config(
+            {"tcpsocket_readiness_probe": "{initial_delay_seconds: 10}"}
+        )
+
+    def config_readiness_probe(self):
+        self.harness.update_config(
+            {"tcpsocket_readiness_probe": '{"initial_delay_seconds": 10}'}
+        )
+
     def initialize_mongo_relation(self):
         mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb")
         self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0")