X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=191821aea470120634a703df16ef56fc90c9480b;hp=a79d00d8c8a46b56da6b1242a02a27612512f8c5;hb=435b86410c96c0e034a892ac5df9ebc9547e3b7d;hpb=f6e9b00b6f7cd35e45ace4c84b53fe8d12b2438c diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index a79d00d..191821a 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -117,7 +117,7 @@ class Libjuju: 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 @@ -455,6 +455,7 @@ class Libjuju: nonce=params.nonce, machine_id=machine_id, proxy=self.api_proxy, + series=params.series, ) ) @@ -853,8 +854,9 @@ class Libjuju: """ 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 +890,10 @@ class Libjuju: 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) @@ -926,33 +932,6 @@ class Libjuju: machine = model.machines[machine_id] await machine.destroy(force=True) - # async def destroy_machine( - # self, model: Model, machine_id: str, total_timeout: float = 3600 - # ): - # """ - # Destroy machine - - # :param: model: Model object - # :param: machine_id: Machine id - # :param: total_timeout: Timeout in seconds - # """ - # machines = await model.get_machines() - # if machine_id in machines: - # machine = machines[machine_id] - # await machine.destroy(force=True) - # # max timeout - # end = time.time() + total_timeout - - # # wait for machine removal - # machines = await model.get_machines() - # while machine_id in machines and time.time() < end: - # self.log.debug("Waiting for machine {} is destroyed".format(machine_id)) - # await asyncio.sleep(0.5) - # machines = await model.get_machines() - # self.log.debug("Machine destroyed: {}".format(machine_id)) - # else: - # self.log.debug("Machine not found: {}".format(machine_id)) - async def configure_application( self, model_name: str, application_name: str, config: dict = None ):