Trap boto exception InvalidSpotInstanceRequestID.NotFound when allow_missing is True #1022
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.
The following behavior occurs usually when trying to destroy an EC2 one-time spot instance whereas the associated spot instance request resource does not exist no more.
According to documentation, also as tested, once a spot instance request is cancelled and the instance gets terminated with status code instance-terminated-no-capacity, then the spot instance request goes to state closed and the resource is gone after a couple of hours: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-bid-status.html#spot-instances-bid-status-lifecycle
Logically, the _get_spot_instance_request_by_id() function is supposed to account for such a case and raise an exception with the message "Spot instance request xxx disappeared!" when argument allow_missing = False, the above exception message is instead being raised by the boto function get_all_spot_instance_requests() causing nixops to exit immediately.
This change intends to trap boto exceptions with the message "InvalidSpotInstanceRequestID.NotFound" and leave the exception handling at the level of parent function get_all_spot_instance_requests(), or return None if allow_missing = True.