mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
fix: consistently fail on invalid ID in *_info
modules (#301)
* fix: consistently fail on invalid ID in `*_info` modules * remove unused import
This commit is contained in:
parent
0506fd76d1
commit
e461a890fa
20 changed files with 29 additions and 16 deletions
2
changelogs/fragments/consistently-fail-on-invalid-id.yml
Normal file
2
changelogs/fragments/consistently-fail-on-invalid-id.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "`*_info` - Consistently fail on invalid ID in `*_info` modules."
|
|
@ -1,2 +0,0 @@
|
|||
bugfixes:
|
||||
- hcloud_location_info - Do not error when querying a location using an invalid id.
|
|
@ -16,6 +16,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the certificate you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -20,6 +20,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the datacenter you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -20,6 +20,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the Floating IP you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
label_selector:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the image you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -22,6 +22,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the ISO image you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the Load Balancers you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the Load Balancer type you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the location you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
@ -78,7 +79,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ..module_utils.hcloud import AnsibleHCloud
|
||||
from ..module_utils.vendor.hcloud import APIException, HCloudException
|
||||
from ..module_utils.vendor.hcloud import HCloudException
|
||||
|
||||
|
||||
class AnsibleHCloudLocationInfo(AnsibleHCloud):
|
||||
|
@ -105,12 +106,7 @@ class AnsibleHCloudLocationInfo(AnsibleHCloud):
|
|||
def get_locations(self):
|
||||
try:
|
||||
if self.module.params.get("id") is not None:
|
||||
try:
|
||||
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
|
||||
except APIException as exception:
|
||||
self.hcloud_location_info = []
|
||||
if exception.code != "not_found":
|
||||
raise exception
|
||||
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
|
||||
elif self.module.params.get("name") is not None:
|
||||
self.hcloud_location_info = [self.client.locations.get_by_name(self.module.params.get("name"))]
|
||||
else:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the network you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the Primary IP you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the server you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -21,6 +21,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the server type you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -16,6 +16,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the ssh key you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -20,6 +20,7 @@ options:
|
|||
id:
|
||||
description:
|
||||
- The ID of the Volume you want to get.
|
||||
- The module will fail if the provided ID is invalid.
|
||||
type: int
|
||||
name:
|
||||
description:
|
||||
|
|
|
@ -49,7 +49,8 @@
|
|||
hetzner.hcloud.hcloud_location_info:
|
||||
id: 4711
|
||||
register: result
|
||||
ignore_errors: true
|
||||
- name: Verify hcloud_location_info with wrong id
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result.hcloud_location_info | list | count == 0
|
||||
- result is failed
|
||||
|
|
|
@ -103,12 +103,13 @@
|
|||
|
||||
- name: test gather hcloud network info with wrong id
|
||||
hetzner.hcloud.hcloud_network_info:
|
||||
name: "4711"
|
||||
id: "4711"
|
||||
register: hcloud_network
|
||||
ignore_errors: true
|
||||
- name: verify test gather hcloud network with wrong id
|
||||
assert:
|
||||
that:
|
||||
- hcloud_network.hcloud_network_info | list | count == 0
|
||||
- hcloud_network is failed
|
||||
|
||||
- name: cleanup
|
||||
hetzner.hcloud.hcloud_network:
|
||||
|
|
|
@ -82,12 +82,13 @@
|
|||
|
||||
- name: test gather hcloud server infos with wrong id
|
||||
hetzner.hcloud.hcloud_server_info:
|
||||
name: "4711"
|
||||
id: "4711"
|
||||
register: server
|
||||
ignore_errors: true
|
||||
- name: verify test gather hcloud server infos with wrong id
|
||||
assert:
|
||||
that:
|
||||
- server.hcloud_server_info | list | count == 0
|
||||
- server is failed
|
||||
|
||||
- name: cleanup
|
||||
hetzner.hcloud.hcloud_server:
|
||||
|
|
|
@ -83,12 +83,13 @@
|
|||
|
||||
- name: test gather hcloud volume infos with wrong id
|
||||
hetzner.hcloud.hcloud_volume_info:
|
||||
name: "4711"
|
||||
id: "4711"
|
||||
register: hcloud_volume
|
||||
ignore_errors: true
|
||||
- name: verify test gather hcloud volume infos with wrong id
|
||||
assert:
|
||||
that:
|
||||
- hcloud_volume.hcloud_volume_info | list | count == 0
|
||||
- hcloud_volume is failed
|
||||
|
||||
- name: cleanup
|
||||
hetzner.hcloud.hcloud_volume:
|
||||
|
|
Loading…
Reference in a new issue