X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fng-ui%2Fsrc%2Fcharm.py;h=d9ad8f2a040091e90b94832ec52a783d0ccb69ff;hb=1850e4abd7b58d749443ddc5ca5c2cdbb2d067ca;hp=33d9ade613ae4cb3b4827f0732d8c47815e522cb;hpb=fa55bd7375b3f018116c5ab7b43d0588e7ec19bd;p=osm%2Fdevops.git diff --git a/installers/charm/ng-ui/src/charm.py b/installers/charm/ng-ui/src/charm.py index 33d9ade6..d9ad8f2a 100755 --- a/installers/charm/ng-ui/src/charm.py +++ b/installers/charm/ng-ui/src/charm.py @@ -13,11 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys -import logging import base64 - -sys.path.append("lib") +from glob import glob +import logging +from pathlib import Path +from string import Template +import sys from ops.charm import CharmBase from ops.framework import StoredState, Object @@ -30,9 +31,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__) @@ -63,7 +64,7 @@ class NGUICharm(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.nbi_host or not self.state.nbi_port: unit.status = WaitingStatus("Waiting for NBI") @@ -72,11 +73,11 @@ class NGUICharm(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 @@ -129,7 +130,7 @@ class NGUICharm(CharmBase): ] port = config["https_port"] if ssl_enabled else config["port"] ports = [ - {"name": "port", "containerPort": port, "protocol": "TCP",}, + {"name": "port", "containerPort": port, "protocol": "TCP", }, ] kubernetes = { @@ -157,7 +158,9 @@ class NGUICharm(CharmBase): }, } ) + logger.debug(files) + spec = { "version": 2, "containers": [ @@ -188,11 +191,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()