1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

Fix error handling and add test cases (#58)

* Fix error handling and add test cases

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
Lukas Kämmerling 2021-02-24 13:37:58 +01:00 committed by GitHub
parent 0a27de6fc6
commit eb45ae014c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 260 additions and 187 deletions

View file

@ -160,7 +160,7 @@ class AnsibleHcloudSubnetwork(Hcloud):
try:
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
self.hcloud_subnetwork = None
except APIException as e:
except Exception as e:
self.module.fail_json(msg=e.message)
def _get_subnetwork(self):
@ -184,7 +184,7 @@ class AnsibleHcloudSubnetwork(Hcloud):
if not self.module.check_mode:
try:
self.hcloud_network.add_subnet(subnet=NetworkSubnet(**params)).wait_until_finished()
except APIException as e:
except Exception as e:
self.module.fail_json(msg=e.message)
self._mark_as_changed()
@ -202,7 +202,10 @@ class AnsibleHcloudSubnetwork(Hcloud):
self._get_subnetwork()
if self.hcloud_subnetwork is not None and self.hcloud_network is not None:
if not self.module.check_mode:
self.hcloud_network.delete_subnet(self.hcloud_subnetwork).wait_until_finished()
try:
self.hcloud_network.delete_subnet(self.hcloud_subnetwork).wait_until_finished()
except Exception as e:
self.module.fail_json(msg=e.message)
self._mark_as_changed()
self.hcloud_subnetwork = None