Fix bug 2142: Debug mode in Pebble Charms is not working
[osm/devops.git] / installers / charm / osm-nbi / src / charm.py
index 964050a..23ab054 100755 (executable)
@@ -40,8 +40,9 @@ from charms.osm_libs.v0.utils import (
     check_container_ready,
     check_service_active,
 )
     check_container_ready,
     check_service_active,
 )
+from charms.osm_nbi.v0.nbi import NbiProvides
 from lightkube.models.core_v1 import ServicePort
 from lightkube.models.core_v1 import ServicePort
-from ops.charm import ActionEvent, CharmBase
+from ops.charm import ActionEvent, CharmBase, RelationJoinedEvent
 from ops.framework import StoredState
 from ops.main import main
 from ops.model import ActiveStatus, Container
 from ops.framework import StoredState
 from ops.main import main
 from ops.model import ActiveStatus, Container
@@ -80,6 +81,7 @@ class OsmNbiCharm(CharmBase):
             },
         )
         self.kafka = KafkaRequires(self)
             },
         )
         self.kafka = KafkaRequires(self)
+        self.nbi = NbiProvides(self)
         self.mongodb_client = MongoClient(self, "mongodb")
         self.prometheus_client = PrometheusClient(self, "prometheus")
         self.keystone_client = KeystoneClient(self, "keystone")
         self.mongodb_client = MongoClient(self, "mongodb")
         self.prometheus_client = PrometheusClient(self, "prometheus")
         self.keystone_client = KeystoneClient(self, "keystone")
@@ -111,9 +113,10 @@ class OsmNbiCharm(CharmBase):
             # Eventually it will become ready after the first pebble-ready event.
             check_container_ready(self.container)
 
             # Eventually it will become ready after the first pebble-ready event.
             check_container_ready(self.container)
 
-            self._configure_service(self.container)
+            if not self.debug_mode.started:
+                self._configure_service(self.container)
             self._update_ingress_config()
             self._update_ingress_config()
-
+            self._update_nbi_relation()
             # Update charm status
             self._on_update_status()
         except CharmError as e:
             # Update charm status
             self._on_update_status()
         except CharmError as e:
@@ -145,6 +148,11 @@ class OsmNbiCharm(CharmBase):
         finally:
             self._on_update_status()
 
         finally:
             self._on_update_status()
 
+    def _update_nbi_relation(self, event: RelationJoinedEvent = None) -> None:
+        """Handler for the nbi-relation-joined event."""
+        if self.unit.is_leader():
+            self.nbi.set_host_info(self.app.name, SERVICE_PORT, event.relation if event else None)
+
     def _on_get_debug_mode_information_action(self, event: ActionEvent) -> None:
         """Handler for the get-debug-mode-information action event."""
         if not self.debug_mode.started:
     def _on_get_debug_mode_information_action(self, event: ActionEvent) -> None:
         """Handler for the get-debug-mode-information action event."""
         if not self.debug_mode.started:
@@ -173,6 +181,7 @@ class OsmNbiCharm(CharmBase):
             self.on["kafka"].relation_broken: self._on_required_relation_broken,
             # Action events
             self.on.get_debug_mode_information_action: self._on_get_debug_mode_information_action,
             self.on["kafka"].relation_broken: self._on_required_relation_broken,
             # Action events
             self.on.get_debug_mode_information_action: self._on_get_debug_mode_information_action,
+            self.on.nbi_relation_joined: self._update_nbi_relation,
         }
         for relation in [self.on[rel_name] for rel_name in ["mongodb", "prometheus", "keystone"]]:
             event_handler_mapping[relation.relation_changed] = self._on_config_changed
         }
         for relation in [self.on[rel_name] for rel_name in ["mongodb", "prometheus", "keystone"]]:
             event_handler_mapping[relation.relation_changed] = self._on_config_changed
@@ -275,6 +284,11 @@ class OsmNbiCharm(CharmBase):
                         "OSMNBI_AUTHENTICATION_SERVICE_USERNAME": self.keystone_client.username,
                         "OSMNBI_AUTHENTICATION_SERVICE_PASSWORD": self.keystone_client.password,
                         "OSMNBI_AUTHENTICATION_SERVICE_PROJECT": self.keystone_client.service,
                         "OSMNBI_AUTHENTICATION_SERVICE_USERNAME": self.keystone_client.username,
                         "OSMNBI_AUTHENTICATION_SERVICE_PASSWORD": self.keystone_client.password,
                         "OSMNBI_AUTHENTICATION_SERVICE_PROJECT": self.keystone_client.service,
+                        # DISABLING INTERNAL SSL SERVER
+                        "OSMNBI_SERVER_SSL_MODULE": "",
+                        "OSMNBI_SERVER_SSL_CERTIFICATE": "",
+                        "OSMNBI_SERVER_SSL_PRIVATE_KEY": "",
+                        "OSMNBI_SERVER_SSL_PASS_PHRASE": "",
                     },
                 }
             },
                     },
                 }
             },