Skip to content

Commit

Permalink
fix: improve actions waiting timeout based on data (ansible-collectio…
Browse files Browse the repository at this point in the history
…ns#488)

##### SUMMARY

Some action waiting time have been set to an arbitrary number, which
could force the users to wait for too long, while we could have raised a
timeout.

This changes the arbitrary numbers with rough estimate based on the
average actions time and some leeway.
  • Loading branch information
jooola authored Apr 15, 2024
1 parent 04835d5 commit 0709552
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 69 deletions.
4 changes: 3 additions & 1 deletion plugins/modules/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def _create_certificate(self):
if not self.module.check_mode:
try:
resp = self.client.certificates.create_managed(**params)
resp.action.wait_until_finished(max_retries=1000)
# Action should take 60 to 90 seconds on average, wait for 5m to
# allow DNS or Let's Encrypt slowdowns.
resp.action.wait_until_finished(max_retries=300)
except HCloudException as exception:
self.fail_json_hcloud(exception)

Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/floating_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def _create_floating_ip(self):

delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None:
self.hcloud_floating_ip.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_floating_ip.change_protection(delete=delete_protection)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down Expand Up @@ -261,7 +262,8 @@ def _update_floating_ip(self):
delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None and delete_protection != self.hcloud_floating_ip.protection["delete"]:
if not self.module.check_mode:
self.hcloud_floating_ip.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_floating_ip.change_protection(delete=delete_protection)
action.wait_until_finished()
self._mark_as_changed()

self._get_floating_ip()
Expand Down
24 changes: 14 additions & 10 deletions plugins/modules/load_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ def _create_load_balancer(self):

if not self.module.check_mode:
resp = self.client.load_balancers.create(**params)
resp.action.wait_until_finished(max_retries=1000)
resp.action.wait_until_finished()

delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None:
self._get_load_balancer()
self.hcloud_load_balancer.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_load_balancer.change_protection(delete=delete_protection)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand All @@ -235,7 +236,8 @@ def _update_load_balancer(self):
delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None and delete_protection != self.hcloud_load_balancer.protection["delete"]:
if not self.module.check_mode:
self.hcloud_load_balancer.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_load_balancer.change_protection(delete=delete_protection)
action.wait_until_finished()
self._mark_as_changed()
self._get_load_balancer()

Expand All @@ -245,9 +247,11 @@ def _update_load_balancer(self):
):
if not self.module.check_mode:
if disable_public_interface is True:
self.hcloud_load_balancer.disable_public_interface().wait_until_finished()
action = self.hcloud_load_balancer.disable_public_interface()
action.wait_until_finished()
else:
self.hcloud_load_balancer.enable_public_interface().wait_until_finished()
action = self.hcloud_load_balancer.enable_public_interface()
action.wait_until_finished()
self._mark_as_changed()

load_balancer_type = self.module.params.get("load_balancer_type")
Expand All @@ -259,17 +263,17 @@ def _update_load_balancer(self):
if not new_load_balancer_type:
self.module.fail_json(msg="unknown load balancer type")
if not self.module.check_mode:
self.hcloud_load_balancer.change_type(
action = self.hcloud_load_balancer.change_type(
load_balancer_type=new_load_balancer_type,
).wait_until_finished(max_retries=1000)
)
action.wait_until_finished()

self._mark_as_changed()

algorithm = self.module.params.get("algorithm")
if algorithm is not None and self.hcloud_load_balancer.algorithm.type != algorithm:
self.hcloud_load_balancer.change_algorithm(
algorithm=LoadBalancerAlgorithm(type=algorithm)
).wait_until_finished()
action = self.hcloud_load_balancer.change_algorithm(algorithm=LoadBalancerAlgorithm(type=algorithm))
action.wait_until_finished()
self._mark_as_changed()

self._get_load_balancer()
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/load_balancer_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _create_load_balancer_network(self):

if not self.module.check_mode:
try:
self.hcloud_load_balancer.attach_to_network(**params).wait_until_finished()
action = self.hcloud_load_balancer.attach_to_network(**params)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)

Expand All @@ -159,9 +160,8 @@ def delete_load_balancer_network(self):
if self.hcloud_load_balancer_network is not None and self.hcloud_load_balancer is not None:
if not self.module.check_mode:
try:
self.hcloud_load_balancer.detach_from_network(
self.hcloud_load_balancer_network.network
).wait_until_finished()
action = self.hcloud_load_balancer.detach_from_network(self.hcloud_load_balancer_network.network)
action.wait_until_finished()
self._mark_as_changed()
except HCloudException as exception:
self.fail_json_hcloud(exception)
Expand Down
15 changes: 6 additions & 9 deletions plugins/modules/load_balancer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ def _create_load_balancer_service(self):

if not self.module.check_mode:
try:
self.hcloud_load_balancer.add_service(LoadBalancerService(**params)).wait_until_finished(
max_retries=1000
)
action = self.hcloud_load_balancer.add_service(LoadBalancerService(**params))
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down Expand Up @@ -464,9 +463,8 @@ def _update_load_balancer_service(self):
changed = True

if not self.module.check_mode:
self.hcloud_load_balancer.update_service(LoadBalancerService(**params)).wait_until_finished(
max_retries=1000
)
action = self.hcloud_load_balancer.update_service(LoadBalancerService(**params))
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._get_load_balancer()
Expand All @@ -492,9 +490,8 @@ def delete_load_balancer_service(self):
if self.hcloud_load_balancer_service is not None:
if not self.module.check_mode:
try:
self.hcloud_load_balancer.delete_service(self.hcloud_load_balancer_service).wait_until_finished(
max_retries=1000
)
action = self.hcloud_load_balancer.delete_service(self.hcloud_load_balancer_service)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/load_balancer_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def _create_load_balancer_target(self):

if not self.module.check_mode:
try:
self.hcloud_load_balancer.add_target(**params).wait_until_finished()
action = self.hcloud_load_balancer.add_target(**params)
action.wait_until_finished()
except APIException as exception:
if exception.code == "locked" or exception.code == "conflict":
self._create_load_balancer_target()
Expand Down Expand Up @@ -269,7 +270,8 @@ def delete_load_balancer_target(self):
use_private_ip=False,
)
try:
self.hcloud_load_balancer.remove_target(target).wait_until_finished()
action = self.hcloud_load_balancer.remove_target(target)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down
9 changes: 6 additions & 3 deletions plugins/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def _create_network(self):
delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None:
self._get_network()
self.hcloud_network.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_network.change_protection(delete=delete_protection)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand All @@ -188,7 +189,8 @@ def _update_network(self):
ip_range = self.module.params.get("ip_range")
if ip_range is not None and ip_range != self.hcloud_network.ip_range:
if not self.module.check_mode:
self.hcloud_network.change_ip_range(ip_range=ip_range).wait_until_finished()
action = self.hcloud_network.change_ip_range(ip_range=ip_range)
action.wait_until_finished()
self._mark_as_changed()

expose_routes_to_vswitch = self.module.params.get("expose_routes_to_vswitch")
Expand All @@ -203,7 +205,8 @@ def _update_network(self):
delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None and delete_protection != self.hcloud_network.protection["delete"]:
if not self.module.check_mode:
self.hcloud_network.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_network.change_protection(delete=delete_protection)
action.wait_until_finished()
self._mark_as_changed()
except HCloudException as exception:
self.fail_json_hcloud(exception)
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/primary_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def _create_primary_ip(self):

delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None:
self.hcloud_primary_ip.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_primary_ip.change_protection(delete=delete_protection)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand All @@ -258,7 +259,8 @@ def _update_primary_ip(self):
delete_protection = self.module.params.get("delete_protection")
if delete_protection is not None and delete_protection != self.hcloud_primary_ip.protection["delete"]:
if not self.module.check_mode:
self.hcloud_primary_ip.change_protection(delete=delete_protection).wait_until_finished()
action = self.hcloud_primary_ip.change_protection(delete=delete_protection)
action.wait_until_finished()
self._mark_as_changed()

self._get_primary_ip()
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/rdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ def _create_rdns(self):

if not self.module.check_mode:
try:
self.hcloud_resource.change_dns_ptr(**params).wait_until_finished()
action = self.hcloud_resource.change_dns_ptr(**params)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand All @@ -293,7 +294,8 @@ def _update_rdns(self):

if not self.module.check_mode:
try:
self.hcloud_resource.change_dns_ptr(**params).wait_until_finished()
action = self.hcloud_resource.change_dns_ptr(**params)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def _create_route(self):

if not self.module.check_mode:
try:
self.hcloud_network.add_route(route=route).wait_until_finished()
action = self.hcloud_network.add_route(route=route)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)

Expand All @@ -149,7 +150,8 @@ def delete_route(self):
if self.hcloud_route is not None and self.hcloud_network is not None:
if not self.module.check_mode:
try:
self.hcloud_network.delete_route(self.hcloud_route).wait_until_finished()
action = self.hcloud_network.delete_route(self.hcloud_route)
action.wait_until_finished()
except HCloudException as exception:
self.fail_json_hcloud(exception)
self._mark_as_changed()
Expand Down
Loading

0 comments on commit 0709552

Please sign in to comment.