Give a warning when removing a cloud that does not exist 75/11075/1
authorDavid Garcia <david.garcia@canonical.com>
Tue, 27 Jul 2021 13:07:42 +0000 (15:07 +0200)
committerDavid Garcia <david.garcia@canonical.com>
Tue, 27 Jul 2021 13:07:42 +0000 (15:07 +0200)
Fixes bug 1608

Change-Id: Ide9040f5e97ba07952062f23c9217e227af375d0
Signed-off-by: David Garcia <david.garcia@canonical.com>
n2vc/libjuju.py

index 3dcb7f9..1cb1e9e 100644 (file)
@@ -18,7 +18,7 @@ import typing
 
 import time
 
-from juju.errors import JujuAPIError
+import juju.errors
 from juju.model import Model
 from juju.machine import Machine
 from juju.application import Application
@@ -174,7 +174,7 @@ class Libjuju:
                     cloud_name=cloud.name,
                     credential_name=cloud.credential_name,
                 )
-        except JujuAPIError as e:
+        except juju.errors.JujuAPIError as e:
             if "already exists" in e.message:
                 pass
             else:
@@ -759,7 +759,7 @@ class Libjuju:
         db_dict: dict = None,
         progress_timeout: float = None,
         total_timeout: float = None,
-        **kwargs
+        **kwargs,
     ):
         """Execute action
 
@@ -921,7 +921,7 @@ class Libjuju:
         # Add relation
         try:
             await model.add_relation(endpoint_1, endpoint_2)
-        except JujuAPIError as e:
+        except juju.errors.JujuAPIError as e:
             if "not found" in e.message:
                 self.log.warning("Relation not found: {}".format(e.message))
                 return
@@ -1302,6 +1302,11 @@ class Libjuju:
         controller = await self.get_controller()
         try:
             await controller.remove_cloud(name)
+        except juju.errors.JujuError as e:
+            if len(e.errors) == 1 and f'cloud "{name}" not found' == e.errors[0]:
+                self.log.warning(f"Cloud {name} not found, so it could not be deleted.")
+            else:
+                raise e
         finally:
             await self.disconnect_controller(controller)