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:
Jonas L 2023-08-16 16:14:55 +02:00 committed by GitHub
parent 0506fd76d1
commit e461a890fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 29 additions and 16 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "`*_info` - Consistently fail on invalid ID in `*_info` modules."

View file

@ -1,2 +0,0 @@
bugfixes:
- hcloud_location_info - Do not error when querying a location using an invalid id.

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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: