Fix bugs and pin osm bundles 21/10121/4
authorDavid Garcia <david.garcia@canonical.com>
Wed, 16 Dec 2020 16:25:15 +0000 (17:25 +0100)
committerbeierlm <mark.beierl@canonical.com>
Thu, 17 Dec 2020 00:28:27 +0000 (01:28 +0100)
Keystone charm (bug 1378): Improve the way we handle the relation data from the database
relation
Ro charm (bug 1379): Fix the status of the non-leader units
Ng-ui (bug 1380): Fix the nbi-relation-changed hook for the non-leader
units
Installer: Pin the version of the OSM bundles

Change-Id: Ied07c964b1c85b1c534916eb4b30fd6bc87287a6
Signed-off-by: David Garcia <david.garcia@canonical.com>
installers/charm/build.sh
installers/charm/keystone/src/charm.py
installers/charm/ng-ui/src/charm.py
installers/charm/release_edge.sh [changed mode: 0644->0755]
installers/charm/ro-k8s/reactive/ro.py
installers/charmed_install.sh

index edcad53..b5c0c0b 100755 (executable)
@@ -25,7 +25,6 @@ build 'ro-k8s'
 # build 'ui-k8s'
 
 charms="nbi pla pol mon lcm ng-ui keystone"
-charms="nbi"
 if [ -z `which charmcraft` ]; then
     sudo snap install charmcraft --beta
 fi
index ef16690..637461e 100755 (executable)
@@ -27,8 +27,8 @@ from urllib.parse import urlparse
 
 from cryptography.fernet import Fernet
 
-from ops.charm import CharmBase, EventBase
-from ops.framework import StoredState
+from ops.charm import CharmBase, EventBase, CharmEvents
+from ops.framework import StoredState, EventSource
 from ops.main import main
 from ops.model import (
     ActiveStatus,
@@ -40,7 +40,7 @@ from ops.model import (
 
 LOGGER = logging.getLogger(__name__)
 
-REQUIRED_SETTINGS = []
+REQUIRED_SETTINGS = ["token_expiration"]
 
 # This is hardcoded in the keystone container script
 DATABASE_NAME = "keystone"
@@ -57,10 +57,22 @@ CREDENTIAL_KEYS_PATH = "/etc/keystone/credential-keys"
 FERNET_KEYS_PATH = "/etc/keystone/fernet-keys"
 
 
+class ConfigurePodEvent(EventBase):
+    """Configure Pod event"""
+
+    pass
+
+
+class KeystoneEvents(CharmEvents):
+    """Keystone Events"""
+
+    configure_pod = EventSource(ConfigurePodEvent)
+
 class KeystoneCharm(CharmBase):
     """Keystone K8s Charm"""
 
     state = StoredState()
+    on = KeystoneEvents()
 
     def __init__(self, *args) -> NoReturn:
         """Constructor of the Charm object.
@@ -83,10 +95,16 @@ class KeystoneCharm(CharmBase):
         self.framework.observe(self.on.leader_elected, self.configure_pod)
         self.framework.observe(self.on.update_status, self.configure_pod)
 
+        # Registering custom internal events
+        self.framework.observe(self.on.configure_pod, self.configure_pod)
+
         # Register relation events
         self.framework.observe(
             self.on.db_relation_changed, self._on_db_relation_changed
         )
+        self.framework.observe(
+            self.on.db_relation_departed, self._on_db_relation_departed
+        )
         self.framework.observe(
             self.on.keystone_relation_joined, self._publish_keystone_info
         )
@@ -99,23 +117,22 @@ class KeystoneCharm(CharmBase):
             event (EventBase): Keystone relation event to update NBI.
         """
         config = self.model.config
-        if self.unit.is_leader():
-            rel_data = {
-                "host": f"http://{self.app.name}:{KEYSTONE_PORT}/v3",
-                "port": str(KEYSTONE_PORT),
-                "keystone_db_password": config["keystone_db_password"],
-                "region_id": config["region_id"],
-                "user_domain_name": config["user_domain_name"],
-                "project_domain_name": config["project_domain_name"],
-                "admin_username": config["admin_username"],
-                "admin_password": config["admin_password"],
-                "admin_project_name": config["admin_project"],
-                "username": config["service_username"],
-                "password": config["service_password"],
-                "service": config["service_project"],
-            }
-            for k, v in rel_data.items():
-                event.relation.data[self.model.unit][k] = v
+        rel_data = {
+            "host": f"http://{self.app.name}:{KEYSTONE_PORT}/v3",
+            "port": str(KEYSTONE_PORT),
+            "keystone_db_password": config["keystone_db_password"],
+            "region_id": config["region_id"],
+            "user_domain_name": config["user_domain_name"],
+            "project_domain_name": config["project_domain_name"],
+            "admin_username": config["admin_username"],
+            "admin_password": config["admin_password"],
+            "admin_project_name": config["admin_project"],
+            "username": config["service_username"],
+            "password": config["service_password"],
+            "service": config["service_project"],
+        }
+        for k, v in rel_data.items():
+            event.relation.data[self.model.unit][k] = v
 
     def _on_db_relation_changed(self, event: EventBase) -> NoReturn:
         """Reads information about the DB relation, in order for keystone to
@@ -125,12 +142,45 @@ class KeystoneCharm(CharmBase):
             event (EventBase): DB relation event to access database
                                information.
         """
-        self.state.db_host = event.relation.data[event.unit].get("host")
-        self.state.db_port = event.relation.data[event.unit].get("port", 3306)
-        self.state.db_user = "root"  # event.relation.data[event.unit].get("user")
-        self.state.db_password = event.relation.data[event.unit].get("root_password")
-        if self.state.db_host:
-            self.configure_pod(event)
+        if not event.unit in event.relation.data:
+            return
+        relation_data = event.relation.data[event.unit]
+        db_host = relation_data.get("host")
+        db_port = int(relation_data.get("port", 3306))
+        db_user = "root"
+        db_password = relation_data.get("root_password")
+
+        if (
+            db_host
+            and db_port
+            and db_user
+            and db_password
+            and (
+                self.state.db_host != db_host
+                or self.state.db_port != db_port
+                or self.state.db_user != db_user
+                or self.state.db_password != db_password
+            )
+        ):
+            self.state.db_host = db_host
+            self.state.db_port = db_port
+            self.state.db_user = db_user
+            self.state.db_password = db_password
+            self.on.configure_pod.emit()
+
+
+    def _on_db_relation_departed(self, event: EventBase) -> NoReturn:
+        """Clears data from db relation.
+
+        Args:
+            event (EventBase): DB relation event.
+
+        """
+        self.state.db_host = None
+        self.state.db_port = None
+        self.state.db_user = None
+        self.state.db_password = None
+        self.on.configure_pod.emit()
 
     def _check_settings(self) -> str:
         """Check if there any settings missing from Keystone configuration.
index 7510a6c..21102e4 100755 (executable)
@@ -93,10 +93,11 @@ class NgUiCharm(CharmBase):
         Args:
             event (EventBase): NBI relation event.
         """
-        data_loc = event.unit if event.unit else event.app
-        logger.error(dict(event.relation.data))
-        nbi_host = event.relation.data[data_loc].get("host")
-        nbi_port = event.relation.data[data_loc].get("port")
+        if not event.unit in event.relation.data:
+            return
+        relation_data = event.relation.data[event.unit]
+        nbi_host = relation_data.get("host")
+        nbi_port = relation_data.get("port")
 
         if (
             nbi_host
old mode 100644 (file)
new mode 100755 (executable)
index a3d698e..8790c4d
@@ -23,7 +23,6 @@ tag=testing-daily
 # 2. Release charms
 # Reactive charms
 charms="lcm-k8s mon-k8s pol-k8s ro-k8s"
-charms=""
 for charm in $charms; do
     cs_revision=`charm push $charm/release cs:~charmed-osm/$charm | tail -n +1 | head -1 | awk '{print $2}'`
     charm release --channel $channel $cs_revision
@@ -32,7 +31,6 @@ done
 
 # New charms (with no resources)
 charms="pla keystone"
-charms=""
 for charm in $charms; do
     echo "Releasing $charm charm"
     cs_revision=`charm push $charm/$charm.charm cs:~charmed-osm/$charm | tail -n +1 | head -1 | awk '{print $2}'`
@@ -42,7 +40,6 @@ done
 
 # New charms (with resources)
 charms="ng-ui nbi"
-charms="nbi"
 for charm in $charms; do
     echo "Releasing $charm charm"
     cs_revision=$(charm push $charm/$charm.charm cs:~charmed-osm/$charm | tail -n +1 | head -1 | awk '{print $2}')
index aef1bea..062cc07 100644 (file)
@@ -109,7 +109,7 @@ def configure():
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
-@when("ro-k8s.configured")
+@when("ro-k8s.ready")
 @when_not("leadership.is_leader")
 def non_leaders_active():
     layer.status.active("ready")
index 75a7259..4d04a91 100755 (executable)
@@ -24,6 +24,9 @@ PATH=/snap/bin:${PATH}
 
 MODEL_NAME=osm
 
+OSM_BUNDLE=cs:osm-54
+OSM_HA_BUNDLE=cs:osm-ha-40
+
 function check_arguments(){
     while [ $# -gt 0 ] ; do
         case $1 in
@@ -33,7 +36,7 @@ function check_arguments(){
             --lxd) LXD_CLOUD="$2" ;;
             --lxd-cred) LXD_CREDENTIALS="$2" ;;
             --microstack) MICROSTACK=y ;;
-            --ha) BUNDLE="cs:osm-ha" ;;
+            --ha) BUNDLE=$OSM_HA_BUNDLE ;;
             --tag) TAG="$2" ;;
             --registry) REGISTRY_INFO="$2" ;;
         esac
@@ -242,7 +245,7 @@ function deploy_charmed_osm(){
     if [ -v BUNDLE ]; then
         juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
     else
-        juju deploy -m $MODEL_NAME cs:osm-53 --overlay ~/.osm/vca-overlay.yaml $images_overlay
+        juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
     fi
 
     echo "Waiting for deployment to finish..."