X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fpla%2Fsrc%2Fcharm.py;h=785766ded66635bf08894dcb2f7f89f213781c28;hb=1850e4abd7b58d749443ddc5ca5c2cdbb2d067ca;hp=2e199b36652d9eb0017003e1cab59cf4ac068bf5;hpb=de4c92944d0e639458321896e3f58a8ba1f4b2a4;p=osm%2Fdevops.git diff --git a/installers/charm/pla/src/charm.py b/installers/charm/pla/src/charm.py index 2e199b36..785766de 100755 --- a/installers/charm/pla/src/charm.py +++ b/installers/charm/pla/src/charm.py @@ -13,10 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys +from glob import glob import logging - -sys.path.append("lib") +from pathlib import Path +from string import Template +import sys from ops.charm import CharmBase from ops.framework import StoredState, Object @@ -27,9 +28,9 @@ from ops.model import ( WaitingStatus, ) -from glob import glob -from pathlib import Path -from string import Template + +sys.path.append("lib") + logger = logging.getLogger(__name__) @@ -61,7 +62,7 @@ class PLACharm(CharmBase): # Only apply the spec if this unit is a leader. unit = self.model.unit if not unit.is_leader(): - unit.status = ActiveStatus("Ready") + unit.status = ActiveStatus("ready") return if not self.state.kafka_host or not self.state.kafka_port: unit.status = WaitingStatus("Waiting for Kafka") @@ -74,17 +75,17 @@ class PLACharm(CharmBase): new_spec = self.make_pod_spec() if new_spec == self.state.spec: - unit.status = ActiveStatus("Ready") + unit.status = ActiveStatus("ready") return self.framework.model.pod.set_spec(new_spec) self.state.spec = new_spec - unit.status = ActiveStatus("Ready") + unit.status = ActiveStatus("ready") def make_pod_spec(self): config = self.framework.model.config ports = [ - {"name": "port", "containerPort": config["port"], "protocol": "TCP",}, + {"name": "port", "containerPort": config["port"], "protocol": "TCP", }, ] config_spec = { @@ -123,23 +124,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()