Skip to content

Commit

Permalink
Merge pull request #559 from kasif-adnan/ka/191_improve_error_handlin…
Browse files Browse the repository at this point in the history
…g_kitchen

skip waiting period if aws instance is already destroyed ref#191
  • Loading branch information
tas50 committed Oct 28, 2021
2 parents b5fd431 + 177ccc6 commit d877db5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/kitchen/driver/aws/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def get_instance_from_spot_request(request_id)
).to_a[0]
end

# check if instance exists, given an id
# @param id [String] aws instance id
# @return boolean
def instance_exists?(id)
resource.instance(id).exists?
end

def client
@client ||= ::Aws::EC2::Client.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def destroy(state)
# If we are going to clean up an automatic security group, we need
# to wait for the instance to shut down. This slightly breaks the
# subsystem encapsulation, sorry not sorry.
if state[:auto_security_group_id] && server
if state[:auto_security_group_id] && server && ec2.instance_exists?(state[:server_id])
server.wait_until_terminated do |waiter|
waiter.max_attempts = config[:retryable_tries]
waiter.delay = config[:retryable_sleep]
Expand Down

0 comments on commit d877db5

Please # to comment.