Merge "Fix bug 564"
[osm/N2VC.git] / n2vc / vnf.py
index 6e4aaf3..1bdfe2f 100644 (file)
@@ -769,11 +769,11 @@ class N2VC:
 
                 await self.disconnect_model(self.monitors[model_name])
 
 
                 await self.disconnect_model(self.monitors[model_name])
 
-                # Notify the callback that this charm has been removed.
                 self.notify_callback(
                     model_name,
                     application_name,
                     "removed",
                 self.notify_callback(
                     model_name,
                     application_name,
                     "removed",
+                    "Removing charm {}".format(application_name),
                     callback,
                     *callback_args,
                 )
                     callback,
                     *callback_args,
                 )
@@ -805,6 +805,10 @@ class N2VC:
             except JujuError as e:
                 if "already exists" not in e.message:
                     raise e
             except JujuError as e:
                 if "already exists" not in e.message:
                     raise e
+
+            # Create an observer for this model
+            await self.create_model_monitor(ns_uuid)
+
         return True
 
     async def DestroyNetworkService(self, ns_uuid):
         return True
 
     async def DestroyNetworkService(self, ns_uuid):
@@ -819,7 +823,7 @@ class N2VC:
 
         # Do not delete the default model. The default model was used by all
         # Network Services, prior to the implementation of a model per NS.
 
         # Do not delete the default model. The default model was used by all
         # Network Services, prior to the implementation of a model per NS.
-        if ns_uuid.lower() is "default":
+        if ns_uuid.lower() == "default":
             return False
 
         if not self.authenticated:
             return False
 
         if not self.authenticated:
@@ -832,7 +836,7 @@ class N2VC:
 
         try:
             await self.controller.destroy_models(ns_uuid)
 
         try:
             await self.controller.destroy_models(ns_uuid)
-        except JujuError as e:
+        except JujuError:
             raise NetworkServiceDoesNotExist(
                 "The Network Service '{}' does not exist".format(ns_uuid)
             )
             raise NetworkServiceDoesNotExist(
                 "The Network Service '{}' does not exist".format(ns_uuid)
             )
@@ -1061,10 +1065,20 @@ class N2VC:
             self.refcount['model'] += 1
 
             # Create an observer for this model
             self.refcount['model'] += 1
 
             # Create an observer for this model
+            await self.create_model_monitor(model_name)
+
+        return self.models[model_name]
+
+    async def create_model_monitor(self, model_name):
+        """Create a monitor for the model, if none exists."""
+        if not self.authenticated:
+            await self.login()
+
+        if model_name not in self.monitors:
             self.monitors[model_name] = VCAMonitor(model_name)
             self.models[model_name].add_observer(self.monitors[model_name])
 
             self.monitors[model_name] = VCAMonitor(model_name)
             self.models[model_name].add_observer(self.monitors[model_name])
 
-        return self.models[model_name]
+        return True
 
     async def login(self):
         """Login to the Juju controller."""
 
     async def login(self):
         """Login to the Juju controller."""