Fix wait_for_task backoff behavior in vmware modules #45429
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
I stepped into this when I tried
vmware_guest_powerstate
to turn off a running VM in VMware by settingstate=powered-off
. The instance went down almost immediately, but I had to wait another minute for the module task to return.In #39596, a timer with an exponential backoff algorithm was added:
The intent was obviously to wait for [1,2,4,8,16,32,64,64...] seconds, with some fuzzing added to the seconds. But as it is implemented, the added
randint(1, 1000)
will be greater thanmax_backoff
(64) most of the time, resulting in a 93,6% chance that the first wait duration will be 64 seconds.I assume that the random value was intended to add a slight fuzzing in the range 0..1000 milliseconds.
This PR adjusts the code to that assumption.
ISSUE TYPE
COMPONENT NAME
lib/ansible/module_utils/vmware.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
sample invocation, credentials specified in environment variables
hacking/test-module -m lib/ansible/modules/cloud/vmware/vmware_guest_powerstate.py -a 'state=powered-off name=some-running-vm'