Skip to content

Commit

Permalink
scaleway_compute: When removing node, wait for transition (#444)
Browse files Browse the repository at this point in the history
To remove a scaleway compute node, one needs to stop it first. This is
handled internally within the module by shutting down before removing.
Shutting down the node transitions it to a "stopping" state, which is
not the "stopped" state we expect. We thus need the transition to
complete so that we can put it in the actual target state (absent, i.e.
delete it).

The mechanism for waiting for such transitions today is controlled by
module parameters, with default to not being enabled at all, which
includes the transition from ([running] -(stopping)-> [stopped]).

Without this chage, in case of a running node, we would shut it down
(transition it to "stopping"), not wait for it complete the transition,
realize that it's not yet stopped and issue a second shut down command
to the api. This would fail with a 400 Bad Request error, "already
stopped".

Reference: ansible/ansible#45740
Reported-by: zwindler
  • Loading branch information
olof authored Jun 11, 2020
1 parent 7bdd78b commit 3044c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- scaleway_compute - fix transition handling that could cause errors when removing a node (https://github.com/ansible-collections/community.general/pull/444).
10 changes: 6 additions & 4 deletions plugins/modules/cloud/scaleway/scaleway_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ def fetch_state(compute_api, server):
compute_api.module.fail_json(msg="Could not fetch state in %s" % response.json)


def wait_to_complete_state_transition(compute_api, server):
wait = compute_api.module.params["wait"]
def wait_to_complete_state_transition(compute_api, server, wait=None):
if wait is None:
wait = compute_api.module.params["wait"]
if not wait:
return

wait_timeout = compute_api.module.params["wait_timeout"]
wait_sleep_time = compute_api.module.params["wait_sleep_time"]

Expand Down Expand Up @@ -353,15 +355,15 @@ def absent_strategy(compute_api, wished_server):

# A server MUST be stopped to be deleted.
while fetch_state(compute_api=compute_api, server=target_server) != "stopped":
wait_to_complete_state_transition(compute_api=compute_api, server=target_server)
wait_to_complete_state_transition(compute_api=compute_api, server=target_server, wait=True)
response = stop_server(compute_api=compute_api, server=target_server)

if not response.ok:
err_msg = 'Error while stopping a server before removing it [{0}: {1}]'.format(response.status_code,
response.json)
compute_api.module.fail_json(msg=err_msg)

wait_to_complete_state_transition(compute_api=compute_api, server=target_server)
wait_to_complete_state_transition(compute_api=compute_api, server=target_server, wait=True)

response = remove_server(compute_api=compute_api, server=target_server)

Expand Down

0 comments on commit 3044c02

Please sign in to comment.