Fix bug 601
This fixes bug 601, where a charm in a broken state would fail to be
removed.
This builds of of the new DestroyNetworkService method, which will
remove a model containing a network service.
There is no way, currently, to resolve errors on an individual charm
through the Juju API (client), but removing the model will force the
removal of a broken charm.
Change-Id: I47f41991ed444395061b5a20e5a51059950e5200
Signed-off-by: Adam Israel <adam.israel@canonical.com>
diff --git a/n2vc/vnf.py b/n2vc/vnf.py
index 6e4aaf3..9cdbb33 100644
--- a/n2vc/vnf.py
+++ b/n2vc/vnf.py
@@ -805,6 +805,10 @@
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):
@@ -1061,10 +1065,20 @@
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])
- return self.models[model_name]
+ return True
async def login(self):
"""Login to the Juju controller."""