Minor improvements to libjuju.py
- Increase default timeout to connect to the controller
- Minor fix in destroy_model function
- Fix unit tests. Now they run faster :-)
Change-Id: Ia2cbcb3e052fe91f4e712ea572ecf444b1d5894f
Signed-off-by: David Garcia <david.garcia@canonical.com>
(cherry picked from commit 435b86410c96c0e034a892ac5df9ebc9547e3b7d)
diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py
index a79d00d..bf356f4 100644
--- a/n2vc/libjuju.py
+++ b/n2vc/libjuju.py
@@ -117,7 +117,7 @@
def _create_health_check_task(self):
return self.loop.create_task(self.health_check())
- async def get_controller(self, timeout: float = 5.0) -> Controller:
+ async def get_controller(self, timeout: float = 15.0) -> Controller:
"""
Get controller
@@ -853,8 +853,9 @@
"""
controller = await self.get_controller()
- model = await self.get_model(controller, model_name)
+ model = None
try:
+ model = await self.get_model(controller, model_name)
self.log.debug("Destroying model {}".format(model_name))
uuid = model.info.uuid
@@ -888,6 +889,10 @@
raise Exception(
"Timeout waiting for model {} to be destroyed".format(model_name)
)
+ except Exception as e:
+ if model:
+ await self.disconnect_model(model)
+ raise e
finally:
await self.disconnect_controller(controller)