From: calvinosanc1 Date: Mon, 8 Mar 2021 14:20:07 +0000 (+0100) Subject: Adding MON relation to Keystone for charmed OSM X-Git-Tag: branch-sol006v331-start~34 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F10464%2F4;p=osm%2Fdevops.git Adding MON relation to Keystone for charmed OSM Change-Id: Icc81251002736a4e25579f42500a5a8f6b3fe74a Signed-off-by: calvinosanc1 --- diff --git a/installers/charm/bundles/osm-ha/bundle.yaml b/installers/charm/bundles/osm-ha/bundle.yaml index 80695431..cb361aeb 100644 --- a/installers/charm/bundles/osm-ha/bundle.yaml +++ b/installers/charm/bundles/osm-ha/bundle.yaml @@ -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 diff --git a/installers/charm/bundles/osm/bundle.yaml b/installers/charm/bundles/osm/bundle.yaml index 58a97073..0783993d 100644 --- a/installers/charm/bundles/osm/bundle.yaml +++ b/installers/charm/bundles/osm/bundle.yaml @@ -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 diff --git a/installers/charm/mon/config.yaml b/installers/charm/mon/config.yaml index 93d77fef..2fffbc5f 100644 --- a/installers/charm/mon/config.yaml +++ b/installers/charm/mon/config.yaml @@ -72,3 +72,7 @@ options: description: Grafana password type: string default: admin + keystone_enabled: + description: MON will use Keystone backend + type: boolean + default: false diff --git a/installers/charm/mon/metadata.yaml b/installers/charm/mon/metadata.yaml index 05aa5477..663315e4 100644 --- a/installers/charm/mon/metadata.yaml +++ b/installers/charm/mon/metadata.yaml @@ -45,3 +45,5 @@ requires: interface: mongodb prometheus: interface: prometheus + keystone: + interface: keystone diff --git a/installers/charm/mon/src/charm.py b/installers/charm/mon/src/charm.py index 98c3297b..26dee3ff 100755 --- a/installers/charm/mon/src/charm.py +++ b/installers/charm/mon/src/charm.py @@ -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 diff --git a/installers/charm/mon/tests/test_charm.py b/installers/charm/mon/tests/test_charm.py index 6fcd6a65..5d6f1a06 100644 --- a/installers/charm/mon/tests/test_charm.py +++ b/installers/charm/mon/tests/test_charm.py @@ -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()