Fix bugs and pin osm bundles
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>
diff --git a/installers/charm/build.sh b/installers/charm/build.sh
index edcad53..b5c0c0b 100755
--- a/installers/charm/build.sh
+++ b/installers/charm/build.sh
@@ -25,7 +25,6 @@
# 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
diff --git a/installers/charm/keystone/src/charm.py b/installers/charm/keystone/src/charm.py
index ef16690..637461e 100755
--- a/installers/charm/keystone/src/charm.py
+++ b/installers/charm/keystone/src/charm.py
@@ -27,8 +27,8 @@
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 @@
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 @@
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,11 +95,17 @@
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 @@
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 @@
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.
diff --git a/installers/charm/ng-ui/src/charm.py b/installers/charm/ng-ui/src/charm.py
index 7510a6c..21102e4 100755
--- a/installers/charm/ng-ui/src/charm.py
+++ b/installers/charm/ng-ui/src/charm.py
@@ -93,10 +93,11 @@
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
diff --git a/installers/charm/release_edge.sh b/installers/charm/release_edge.sh
old mode 100644
new mode 100755
index a3d698e..8790c4d
--- a/installers/charm/release_edge.sh
+++ b/installers/charm/release_edge.sh
@@ -23,7 +23,6 @@
# 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 @@
# 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 @@
# 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}')
diff --git a/installers/charm/ro-k8s/reactive/ro.py b/installers/charm/ro-k8s/reactive/ro.py
index aef1bea..062cc07 100644
--- a/installers/charm/ro-k8s/reactive/ro.py
+++ b/installers/charm/ro-k8s/reactive/ro.py
@@ -109,7 +109,7 @@
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")
diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh
index 75a7259..4d04a91 100755
--- a/installers/charmed_install.sh
+++ b/installers/charmed_install.sh
@@ -24,6 +24,9 @@
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 @@
--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 @@
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..."