Adding MON relation to Keystone for charmed OSM 64/10464/4
authorcalvinosanc1 <guillermo.calvino@canonical.com>
Mon, 8 Mar 2021 14:20:07 +0000 (15:20 +0100)
committerbeierlm <mark.beierl@canonical.com>
Mon, 15 Mar 2021 10:46:30 +0000 (11:46 +0100)
Change-Id: Icc81251002736a4e25579f42500a5a8f6b3fe74a
Signed-off-by: calvinosanc1 <guillermo.calvino@canonical.com>
installers/charm/bundles/osm-ha/bundle.yaml
installers/charm/bundles/osm/bundle.yaml
installers/charm/mon/config.yaml
installers/charm/mon/metadata.yaml
installers/charm/mon/src/charm.py
installers/charm/mon/tests/test_charm.py

index 8069543..cb361ae 100644 (file)
@@ -112,6 +112,7 @@ applications:
     options:
       database_commonkey: osm
       log_level: DEBUG
+      keystone_enabled: true
     annotations:
       gui-x: 250
       gui-y: 50
@@ -199,3 +200,5 @@ relations:
     - prometheus:prometheus
   - - ng-ui:nbi
     - nbi:nbi
+  - - mon:keystone
+    - keystone:keystone
index 58a9707..0783993 100644 (file)
@@ -106,6 +106,7 @@ applications:
     options:
       database_commonkey: osm
       log_level: DEBUG
+      keystone_enabled: true
     annotations:
       gui-x: 250
       gui-y: 50
@@ -193,3 +194,5 @@ relations:
     - prometheus:prometheus
   - - ng-ui:nbi
     - nbi:nbi
+  - - mon:keystone
+    - keystone:keystone
index 93d77fe..2fffbc5 100644 (file)
@@ -72,3 +72,7 @@ options:
     description: Grafana password
     type: string
     default: admin
+  keystone_enabled:
+    description: MON will use Keystone backend
+    type: boolean
+    default: false
index 05aa547..663315e 100644 (file)
@@ -45,3 +45,5 @@ requires:
     interface: mongodb
   prometheus:
     interface: prometheus
+  keystone:
+    interface: keystone
index 98c3297..26dee3f 100755 (executable)
@@ -43,6 +43,7 @@ from opslib.osm.validator import (
 from opslib.osm.interfaces.kafka import KafkaClient
 from opslib.osm.interfaces.mongo import MongoClient
 from opslib.osm.interfaces.prometheus import PrometheusClient
+from opslib.osm.interfaces.keystone import KeystoneClient
 
 
 logger = logging.getLogger(__name__)
@@ -51,6 +52,7 @@ PORT = 8000
 
 
 class ConfigModel(ModelValidator):
+    keystone_enabled: bool
     vca_host: str
     vca_user: str
     vca_password: str
@@ -92,6 +94,10 @@ class MonCharm(CharmedOsmBase):
             self.on["prometheus"].relation_broken, self.configure_pod
         )
 
+        self.keystone_client = KeystoneClient(self, "keystone")
+        self.framework.observe(self.on["keystone"].relation_changed, self.configure_pod)
+        self.framework.observe(self.on["keystone"].relation_broken, self.configure_pod)
+
     def _check_missing_dependencies(self, config: ConfigModel):
         missing_relations = []
 
@@ -101,6 +107,9 @@ class MonCharm(CharmedOsmBase):
             missing_relations.append("mongodb")
         if self.prometheus_client.is_missing_data_in_app():
             missing_relations.append("prometheus")
+        if config.keystone_enabled:
+            if self.keystone_client.is_missing_data_in_app():
+                missing_relations.append("keystone")
 
         if missing_relations:
             raise RelationsMissing(missing_relations)
@@ -144,6 +153,18 @@ class MonCharm(CharmedOsmBase):
                 "OSMMON_GRAFANA_PASSWORD": config.grafana_password,
             }
         )
+        if config.keystone_enabled:
+            container_builder.add_envs(
+                {
+                    "OSMMON_KEYSTONE_ENABLED": True,
+                    "OSMMON_KEYSTONE_URL": self.keystone_client.host,
+                    "OSMMON_KEYSTONE_DOMAIN_NAME": self.keystone_client.user_domain_name,
+                    "OSMMON_KEYSTONE_PROJECT_DOMAIN_NAME": self.keystone_client.project_domain_name,
+                    "OSMMON_KEYSTONE_SERVICE_USER": self.keystone_client.username,
+                    "OSMMON_KEYSTONE_SERVICE_PASSWORD": self.keystone_client.password,
+                    "OSMMON_KEYSTONE_SERVICE_PROJECT": self.keystone_client.service,
+                }
+            )
 
         container = container_builder.build()
         # Add container to pod spec
index 6fcd6a6..5d6f1a0 100644 (file)
@@ -49,6 +49,7 @@ class TestCharm(unittest.TestCase):
             "global_request_timeout": 10,
             "collector_interval": 30,
             "evaluator_interval": 30,
+            "keystone_enabled": True,
         }
         self.harness.update_config(self.config)
 
@@ -64,7 +65,7 @@ class TestCharm(unittest.TestCase):
         self.assertTrue(
             all(
                 relation in self.harness.charm.unit.status.message
-                for relation in ["mongodb", "kafka", "prometheus"]
+                for relation in ["mongodb", "kafka", "prometheus", "keystone"]
             )
         )
 
@@ -85,6 +86,7 @@ class TestCharm(unittest.TestCase):
         self.initialize_kafka_relation()
         self.initialize_mongo_relation()
         self.initialize_prometheus_relation()
+        self.initialize_keystone_relation()
         # Verifying status
         self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus)
 
@@ -113,6 +115,28 @@ class TestCharm(unittest.TestCase):
             {"hostname": "prometheus", "port": 9090},
         )
 
+    def initialize_keystone_relation(self):
+        keystone_relation_id = self.harness.add_relation("keystone", "keystone")
+        self.harness.add_relation_unit(keystone_relation_id, "keystone/0")
+        self.harness.update_relation_data(
+            keystone_relation_id,
+            "keystone",
+            {
+                "host": "host",
+                "port": 5000,
+                "user_domain_name": "ud",
+                "project_domain_name": "pd",
+                "username": "u",
+                "password": "p",
+                "service": "s",
+                "keystone_db_password": "something",
+                "region_id": "something",
+                "admin_username": "something",
+                "admin_password": "something",
+                "admin_project_name": "something",
+            },
+        )
+
 
 if __name__ == "__main__":
     unittest.main()