Fix juju status in OSM Charms 47/9647/4
authorDavid Garcia <david.garcia@canonical.com>
Tue, 1 Sep 2020 08:12:16 +0000 (10:12 +0200)
committerbeierlm <mark.beierl@canonical.com>
Wed, 23 Sep 2020 12:07:42 +0000 (14:07 +0200)
Change-Id: Iab33813f81c394f2444fb9407b4fab4b70929c90
Signed-off-by: David Garcia <david.garcia@canonical.com>
21 files changed:
installers/charm/bundles/osm-ha/bundle.yaml
installers/charm/lcm-k8s/reactive/lcm.py
installers/charm/mon-k8s/reactive/mon_k8s.py
installers/charm/nbi-k8s/reactive/nbi.py
installers/charm/ng-ui/.gitignore [new file with mode: 0644]
installers/charm/ng-ui/hooks/start [deleted symlink]
installers/charm/ng-ui/lib/ops [deleted symlink]
installers/charm/ng-ui/requirements.txt [new file with mode: 0644]
installers/charm/ng-ui/src/charm.py
installers/charm/ng-ui/tox.ini
installers/charm/pla/.gitignore [new file with mode: 0644]
installers/charm/pla/hooks/install [deleted symlink]
installers/charm/pla/hooks/start [deleted symlink]
installers/charm/pla/hooks/upgrade-charm [deleted symlink]
installers/charm/pla/lib/ops [deleted symlink]
installers/charm/pla/requirements.txt [new file with mode: 0644]
installers/charm/pla/src/charm.py
installers/charm/pla/tox.ini
installers/charm/pol-k8s/reactive/pol_k8s.py
installers/charm/ro-k8s/reactive/ro.py
installers/charm/ui-k8s/reactive/ui.py

index 8928028..f60082e 100644 (file)
@@ -82,7 +82,7 @@ applications:
       gui-x: 0
       gui-y: 50
   nbi-k8s:
-    charm: "cs:~charmed-osm/nbi-k8s"
+    charm: "%(prefix)s/nbi-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
@@ -96,7 +96,7 @@ applications:
       gui-x: 0
       gui-y: -200
   ro-k8s:
-    charm: "cs:~charmed-osm/ro-k8s"
+    charm: "%(prefix)s/ro-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
@@ -110,7 +110,7 @@ applications:
       gui-x: -250
       gui-y: 300
   ui-k8s:
-    charm: "cs:~charmed-osm/ui-k8s"
+    charm: "%(prefix)s/ui-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
@@ -133,7 +133,7 @@ applications:
       gui-x: 500
       gui-y: 100
   lcm-k8s:
-    charm: "cs:~charmed-osm/lcm-k8s"
+    charm: "%(prefix)s/lcm-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
@@ -152,7 +152,7 @@ applications:
       gui-x: -250
       gui-y: 50
   mon-k8s:
-    charm: "cs:~charmed-osm/mon-k8s"
+    charm: "%(prefix)s/mon-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
@@ -174,7 +174,7 @@ applications:
       gui-x: 250
       gui-y: 50
   pol-k8s:
-    charm: "cs:~charmed-osm/pol-k8s"
+    charm: "%(prefix)s/pol-k8s%(suffix)s"
     channel: "%(channel)s"
     scale: 3
     series: kubernetes
index 3ada8cb..313ed63 100644 (file)
@@ -22,6 +22,10 @@ from charmhelpers.core.hookenv import (
 )
 from charms import layer
 import yaml
+import logging
+
+logger = logging.getLogger(__name__)
+
 
 @hook("upgrade-charm")
 @when("leadership.is_leader")
@@ -37,18 +41,21 @@ def restart():
 
 @when_not("kafka.ready")
 @when_not("lcm-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_kafka():
     layer.status.waiting("Waiting for kafka to be ready")
 
 
 @when_not("mongo.ready")
 @when_not("lcm-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_mongo():
     layer.status.waiting("Waiting for mongo to be ready")
 
 
 @when_not("ro.ready")
 @when_not("lcm-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_ro():
     layer.status.waiting("Waiting for ro to be ready")
 
@@ -96,7 +103,14 @@ def configure():
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
+@when("kafka.ready", "mongo.ready", "ro.ready")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("lcm-k8s.configured")
+@when("leadership.is_leader")
 def set_lcm_active():
     layer.status.active("ready")
 
@@ -130,8 +144,8 @@ def make_pod_spec(ro_host, ro_port, kafka_host, kafka_port, mongo_uri):
         "mongo_uri": mongo_uri,
     }
     data.update(cfg)
-
-    spec = yaml.safe_dump(pod_spec_template % data)
+    logs = pod_spec_template % data
+    spec = yaml.safe_load(pod_spec_template % data)
     if "vca_apiproxy" in cfg and cfg["vca_apiproxy"] != "":
         spec["containers"][0]["config"]["OSMLCM_VCA_APIPROXY"] = cfg["vca_apiproxy"]
-    return spec
\ No newline at end of file
+    return spec
index 9eae0b1..79780e0 100644 (file)
@@ -33,18 +33,21 @@ def restart():
 
 @when_not("kafka.ready")
 @when_not("mon-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_kafka():
     layer.status.waiting("Waiting for kafka to be ready")
 
 
 @when_not("mongo.ready")
 @when_not("mon-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_mongo():
     layer.status.waiting("Waiting for mongo to be ready")
 
 
 @when_not("endpoint.prometheus.available")
 @when_not("mon-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_prometheus():
     layer.status.waiting("Waiting for prometheus to be ready")
 
@@ -81,6 +84,12 @@ def configure():
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
+@when("kafka.ready", "mongo.ready", "endpoint.prometheus.available")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("mon-k8s.configured")
 def set_mon_active():
     layer.status.active("ready")
index edcdd4c..855d800 100644 (file)
@@ -46,23 +46,38 @@ def clear_keystone_ready():
 
 @when_not("kafka.ready")
 @when_not("nbi-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_kafka():
     layer.status.waiting("Waiting for kafka to be ready")
 
 
 @when_not("mongo.ready")
 @when_not("nbi-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_mongo():
     layer.status.waiting("Waiting for mongo to be ready")
 
 
 @when_not("endpoint.prometheus.available")
 @when_not("nbi-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_prometheus():
     layer.status.waiting("Waiting for prometheus to be ready")
 
 
 @when_not("keystone.ready")
+@when("leadership.is_leader")
+@when_not("nbi-k8s.configured")
+def waiting_for_keystone():
+    auth_backend = config().get("auth-backend")
+    if auth_backend == "keystone":
+        layer.status.waiting("Waiting for Keystone to be ready")
+    else:
+        set_flag("keystone.ready")
+
+
+@when_not("keystone.ready")
+@when("leadership.is_leader")
 @when_not("nbi-k8s.configured")
 def waiting_for_keystone():
     auth_backend = config().get("auth-backend")
@@ -162,6 +177,12 @@ def configure():
         log("Error: {}".format(traceback.format_exc()))
 
 
+@when("kafka.ready", "mongo.ready", "endpoint.prometheus.available")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("nbi-k8s.configured")
 def set_nbi_active():
     layer.status.active("ready")
diff --git a/installers/charm/ng-ui/.gitignore b/installers/charm/ng-ui/.gitignore
new file mode 100644 (file)
index 0000000..dfaa805
--- /dev/null
@@ -0,0 +1,16 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+.vscode
+build
+ng-ui.charm
\ No newline at end of file
diff --git a/installers/charm/ng-ui/hooks/start b/installers/charm/ng-ui/hooks/start
deleted file mode 120000 (symlink)
index 25b1f68..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/charm.py
\ No newline at end of file
diff --git a/installers/charm/ng-ui/lib/ops b/installers/charm/ng-ui/lib/ops
deleted file mode 120000 (symlink)
index d934193..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../mod/operator/ops
\ No newline at end of file
diff --git a/installers/charm/ng-ui/requirements.txt b/installers/charm/ng-ui/requirements.txt
new file mode 100644 (file)
index 0000000..10ecdcd
--- /dev/null
@@ -0,0 +1,14 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+ops
index ce48927..8e21bcd 100755 (executable)
@@ -157,7 +157,7 @@ class NGUICharm(CharmBase):
                     },
                 }
             )
-        logger.debug(files)
+
         spec = {
             "version": 2,
             "containers": [
@@ -188,11 +188,12 @@ class NGUICharm(CharmBase):
         self.on_start(event)
 
     def on_nbi_relation_changed(self, event):
-        unit = self.model.unit
-        if not unit.is_leader():
-            return
-        self.state.nbi_host = event.relation.data[event.unit].get("host")
-        self.state.nbi_port = event.relation.data[event.unit].get("port")
+        nbi_host = event.relation.data[event.unit].get("host")
+        nbi_port = event.relation.data[event.unit].get("port")
+        if nbi_host and self.state.nbi_host != nbi_host:
+            self.state.nbi_host = nbi_host
+        if nbi_port and self.state.nbi_port != nbi_port:
+            self.state.nbi_port = nbi_port
         self._apply_spec()
 
 
index aafa301..1c22bd5 100644 (file)
@@ -20,10 +20,20 @@ setenv = VIRTUAL_ENV={envdir}
          PYTHONHASHSEED=0
 whitelist_externals = juju
 passenv = HOME TERM CS_API_* OS_* AMULET_*
-deps = -r{toxinidir}/test-requirements.txt
 install_command =
   pip install {opts} {packages}
 
+[testenv:build]
+basepython = python3
+passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
+whitelist_externals = charmcraft
+                      rm
+                      unzip
+commands =
+    rm -rf release
+    charmcraft build
+    unzip ng-ui.charm -d release
+
 [testenv:black]
 basepython = python3
 deps =
diff --git a/installers/charm/pla/.gitignore b/installers/charm/pla/.gitignore
new file mode 100644 (file)
index 0000000..db6d41a
--- /dev/null
@@ -0,0 +1,16 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+.vscode
+build
+pla.charm
\ No newline at end of file
diff --git a/installers/charm/pla/hooks/install b/installers/charm/pla/hooks/install
deleted file mode 120000 (symlink)
index 25b1f68..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/charm.py
\ No newline at end of file
diff --git a/installers/charm/pla/hooks/start b/installers/charm/pla/hooks/start
deleted file mode 120000 (symlink)
index 25b1f68..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/charm.py
\ No newline at end of file
diff --git a/installers/charm/pla/hooks/upgrade-charm b/installers/charm/pla/hooks/upgrade-charm
deleted file mode 120000 (symlink)
index 25b1f68..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/charm.py
\ No newline at end of file
diff --git a/installers/charm/pla/lib/ops b/installers/charm/pla/lib/ops
deleted file mode 120000 (symlink)
index d934193..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../mod/operator/ops
\ No newline at end of file
diff --git a/installers/charm/pla/requirements.txt b/installers/charm/pla/requirements.txt
new file mode 100644 (file)
index 0000000..10ecdcd
--- /dev/null
@@ -0,0 +1,14 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+ops
index 1fc6386..e137394 100755 (executable)
@@ -84,7 +84,7 @@ class PLACharm(CharmBase):
         config = self.framework.model.config
 
         ports = [
-            {"name": "port", "containerPort": config["port"], "protocol": "TCP", },
+            {"name": "port", "containerPort": config["port"], "protocol": "TCP",},
         ]
 
         config_spec = {
@@ -123,23 +123,23 @@ class PLACharm(CharmBase):
         """Upgrade the charm."""
         unit = self.model.unit
         unit.status = MaintenanceStatus("Upgrading charm")
-        self.on_start(event)
+        self._apply_spec()
 
     def on_kafka_relation_changed(self, event):
-        unit = self.model.unit
-        if not unit.is_leader():
-            return
-        self.state.kafka_host = event.relation.data[event.unit].get("host")
-        self.state.kafka_port = event.relation.data[event.unit].get("port")
+        kafka_host = event.relation.data[event.unit].get("host")
+        kafka_port = event.relation.data[event.unit].get("port")
+        if kafka_host and self.state.kafka_host != kafka_host:
+            self.state.kafka_host = kafka_host
+        if kafka_port and self.state.kafka_port != kafka_port:
+            self.state.kafka_port = kafka_port
         self._apply_spec()
 
     def on_mongo_relation_changed(self, event):
-        unit = self.model.unit
-        if not unit.is_leader():
-            return
-        self.state.mongodb_uri = event.relation.data[event.unit].get(
+        mongodb_uri = event.relation.data[event.unit].get(
             "connection_string"
         )
+        if mongodb_uri and self.state.mongodb_uri != mongodb_uri:
+            self.state.mongodb_uri = mongodb_uri
         self._apply_spec()
 
 
index d2a8c53..678a5ec 100644 (file)
@@ -21,10 +21,21 @@ setenv = VIRTUAL_ENV={envdir}
          PYTHONHASHSEED=0
 whitelist_externals = juju
 passenv = HOME TERM CS_API_* OS_* AMULET_*
-deps = -r{toxinidir}/test-requirements.txt
 install_command =
   pip install {opts} {packages}
 
+
+[testenv:build]
+basepython = python3
+passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
+whitelist_externals = charmcraft
+                      rm
+                      unzip
+commands =
+    rm -rf release
+    charmcraft build
+    unzip pla.charm -d release
+
 [testenv:black]
 basepython = python3
 deps =
index c31a323..5629b4b 100644 (file)
@@ -32,12 +32,14 @@ def restart():
 
 
 @when_not("kafka.ready")
+@when("leadership.is_leader")
 @when_not("pol-k8s.configured")
 def waiting_for_kafka():
     layer.status.waiting("Waiting for kafka to be ready")
 
 
 @when_not("mongo.ready")
+@when("leadership.is_leader")
 @when_not("pol-k8s.configured")
 def waiting_for_mongo():
     layer.status.waiting("Waiting for mongo to be ready")
@@ -69,6 +71,12 @@ def configure():
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
+@when("kafka.ready", "mongo.ready")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("pol-k8s.configured")
 def set_pol_active():
     layer.status.active("ready")
index afd7f45..8ad6f98 100644 (file)
@@ -34,6 +34,7 @@ def restart():
 
 @when_not("mysql.available")
 @when_not("ro-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_mysql():
     layer.status.waiting("Waiting for mysql to be ready")
 
@@ -46,22 +47,29 @@ def configure():
     try:
         mysql = endpoint_from_flag("mysql.available")
 
-        spec = make_pod_spec(
-            mysql.host(),
-            mysql.port(),
-            mysql.user(),
-            mysql.password(),
-            mysql.root_password(),
-        )
-
-        log("set pod spec:\n{}".format(spec))
-        pod_spec_set(spec)
-        layer.status.active("creating container")
-        set_flag("ro-k8s.configured")
+        if mysql.host() is not None:
+            spec = make_pod_spec(
+                mysql.host(),
+                mysql.port(),
+                mysql.user(),
+                mysql.password(),
+                mysql.root_password(),
+            )
+
+            log("set pod spec:\n{}".format(spec))
+            pod_spec_set(spec)
+            layer.status.active("creating container")
+            set_flag("ro-k8s.configured")
     except Exception as e:
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
+@when("mysql.available")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("ro-k8s.configured")
 def set_ro_active():
     layer.status.active("ready")
index 46e5709..5ca8143 100644 (file)
@@ -38,12 +38,14 @@ def restart():
 
 @when_not("mysql.available")
 @when_not("ui-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_mysql():
     layer.status.waiting("Waiting for mysql to be available")
 
 
 @when_not("nbi.ready")
 @when_not("ui-k8s.configured")
+@when("leadership.is_leader")
 def waiting_for_nbi():
     layer.status.waiting("Waiting for nbi to be available")
 
@@ -74,6 +76,12 @@ def configure():
         layer.status.blocked("k8s spec failed to deploy: {}".format(e))
 
 
+@when("mysql.available", "nbi.ready")
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
 @when("ui-k8s.configured")
 def set_ui_active():
     layer.status.active("ready")