X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=f57070238d7f6cbc073b08a4320485b4ef6b4bcc;hb=05bccf7db9202bf50f7c9c7513c36082e73005e1;hp=9961e1935ebad1e23122f3cae193443240d0a0da;hpb=3061bef8813d539f903d00bdccc023c6683222b4;p=osm%2FN2VC.git diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index 9961e19..f570702 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -345,7 +345,7 @@ class Libjuju: db_dict: dict = None, progress_timeout: float = None, total_timeout: float = None, - series: str = "bionic", + series: str = "focal", wait: bool = True, ) -> (Machine, bool): """ @@ -558,7 +558,7 @@ class Libjuju: controller = await self.get_controller() model = await self.get_model(controller, model_name) try: - await model.deploy(uri) + await model.deploy(uri, trust=True) if wait: await JujuModelWatcher.wait_for_model(model, timeout=timeout) self.log.debug("All units active in model {}".format(model_name)) @@ -642,7 +642,6 @@ class Libjuju: :param: application_name: Application name :param: model_name: Model name :param: machine_id Machine id - :param: db_dict: Dictionary with data of the DB to write the updates :param: total_timeout: Timeout for the entity to be active :return: None @@ -792,6 +791,13 @@ class Libjuju: raise JujuApplicationExists( "Application {} exists".format(application_name) ) + except juju.errors.JujuError as e: + if "already exists" in e.message: + raise JujuApplicationExists( + "Application {} exists".format(application_name) + ) + else: + raise e finally: await self.disconnect_model(model) await self.disconnect_controller(controller) @@ -1146,7 +1152,7 @@ class Libjuju: await self.disconnect_model(model) await self.disconnect_controller(controller) - async def destroy_model(self, model_name: str, total_timeout: float): + async def destroy_model(self, model_name: str, total_timeout: float = 1800): """ Destroy model @@ -1160,42 +1166,50 @@ class Libjuju: if not await self.model_exists(model_name, controller=controller): return - model = await self.get_model(controller, model_name) self.log.debug("Destroying model {}".format(model_name)) - uuid = model.info.uuid + model = await self.get_model(controller, model_name) # Destroy machines that are manually provisioned # and still are in pending state await self._destroy_pending_machines(model, only_manual=True) - - # Disconnect model await self.disconnect_model(model) - await controller.destroy_model(uuid, force=True, max_wait=0) + await self._destroy_model( + model_name, + controller, + timeout=total_timeout, + ) + finally: + if model: + await self.disconnect_model(model) + await self.disconnect_controller(controller) - # Wait until model is destroyed - self.log.debug("Waiting for model {} to be destroyed...".format(model_name)) + async def _destroy_model( + self, model_name: str, controller: Controller, timeout: float = 1800 + ): + """ + Destroy model from controller - if total_timeout is None: - total_timeout = 3600 - end = time.time() + total_timeout - while time.time() < end: - models = await controller.list_models() - if model_name not in models: - self.log.debug( - "The model {} ({}) was destroyed".format(model_name, uuid) - ) - return + :param: model: Model name to be removed + :param: controller: Controller object + :param: timeout: Timeout in seconds + """ + + async def _destroy_model_loop(model_name: str, controller: Controller): + while await self.model_exists(model_name, controller=controller): + await controller.destroy_model( + model_name, destroy_storage=True, force=True, max_wait=0 + ) await asyncio.sleep(5) + + try: + await asyncio.wait_for( + _destroy_model_loop(model_name, controller), timeout=timeout + ) + except asyncio.TimeoutError: 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) async def destroy_application( self, model_name: str, application_name: str, total_timeout: float