X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Ftemporal_libjuju.py;h=a043ba037fad30e95792e21e0e03ae03e5157397;hb=d662528a895d15e718f3a0c3b4a60ecce0d336c6;hp=a4b77520b068fad9e1385cc7248206d2b8b7a91f;hpb=6fac4eb592589a75503722b9341ac661556c59a9;p=osm%2FN2VC.git diff --git a/n2vc/temporal_libjuju.py b/n2vc/temporal_libjuju.py index a4b7752..a043ba0 100644 --- a/n2vc/temporal_libjuju.py +++ b/n2vc/temporal_libjuju.py @@ -17,10 +17,14 @@ from dataclasses import dataclass from typing import List from juju.controller import Controller -from juju.errors import JujuAPIError, JujuError +from juju.errors import JujuError from juju.model import Model -from n2vc.exceptions import JujuApplicationExists, JujuControllerFailedConnecting +from n2vc.exceptions import ( + JujuApplicationExists, + JujuControllerFailedConnecting, + JujuModelAlreadyExists, +) @dataclass @@ -74,24 +78,21 @@ class Libjuju: await model.disconnect() async def add_model(self, model_name: str): + """Exception is raised if model_name already exists""" model = None controller = None try: controller = await self.get_controller() if await self.model_exists(model_name, controller=controller): - return + raise JujuModelAlreadyExists( + "Cannot create model {}".format(model_name) + ) self.logger.debug("Creating model {}".format(model_name)) model = await controller.add_model( model_name, - # config=self.vca_connection.data.model_config, cloud_name=self.connection_info.cloud_name, credential_name=self.connection_info.cloud_credentials, ) - except JujuAPIError as e: - if "already exists" in e.message: - pass - else: - raise e finally: await self.disconnect_model(model) await self.disconnect_controller(controller) @@ -111,7 +112,7 @@ class Libjuju: if need_to_disconnect: await self.disconnect_controller(controller) - async def get_model(self, model_name: str, controller: Controller) -> Model: + async def get_model(self, controller: Controller, model_name: str) -> Model: return await controller.get_model(model_name) async def list_models(self) -> List[str]: