Fix juju status in OSM Charms

Change-Id: Iab33813f81c394f2444fb9407b4fab4b70929c90
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/installers/charm/pla/.gitignore b/installers/charm/pla/.gitignore
new file mode 100644
index 0000000..db6d41a
--- /dev/null
+++ b/installers/charm/pla/.gitignore
@@ -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
index 25b1f68..0000000
--- a/installers/charm/pla/hooks/install
+++ /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
index 25b1f68..0000000
--- a/installers/charm/pla/hooks/start
+++ /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
index 25b1f68..0000000
--- a/installers/charm/pla/hooks/upgrade-charm
+++ /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
index d934193..0000000
--- a/installers/charm/pla/lib/ops
+++ /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
index 0000000..10ecdcd
--- /dev/null
+++ b/installers/charm/pla/requirements.txt
@@ -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
diff --git a/installers/charm/pla/src/charm.py b/installers/charm/pla/src/charm.py
index 1fc6386..e137394 100755
--- a/installers/charm/pla/src/charm.py
+++ b/installers/charm/pla/src/charm.py
@@ -84,7 +84,7 @@
         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 @@
         """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()
 
 
diff --git a/installers/charm/pla/tox.ini b/installers/charm/pla/tox.ini
index d2a8c53..678a5ec 100644
--- a/installers/charm/pla/tox.ini
+++ b/installers/charm/pla/tox.ini
@@ -21,10 +21,21 @@
          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 =