From b5358ad836fa3fa34d42431a0016326ac2ce43a0 Mon Sep 17 00:00:00 2001 From: kasif Date: Mon, 25 Oct 2021 18:36:09 +0530 Subject: [PATCH 1/2] skip waiting period if instance is destroyed Signed-off-by: kasif --- lib/kitchen/driver/aws/client.rb | 7 +++++++ lib/kitchen/driver/ec2.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/kitchen/driver/aws/client.rb b/lib/kitchen/driver/aws/client.rb index 0dca8341..aaf9b3ca 100644 --- a/lib/kitchen/driver/aws/client.rb +++ b/lib/kitchen/driver/aws/client.rb @@ -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 diff --git a/lib/kitchen/driver/ec2.rb b/lib/kitchen/driver/ec2.rb index 78af58bd..4093f2cc 100644 --- a/lib/kitchen/driver/ec2.rb +++ b/lib/kitchen/driver/ec2.rb @@ -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] && ec2.instance_exists?(state[:server_id]) server.wait_until_terminated do |waiter| waiter.max_attempts = config[:retryable_tries] waiter.delay = config[:retryable_sleep] From 177ccc6460b85b1056264f859df3494ac5f85225 Mon Sep 17 00:00:00 2001 From: kasif Date: Wed, 27 Oct 2021 11:08:58 +0530 Subject: [PATCH 2/2] put back server condition Signed-off-by: kasif --- lib/kitchen/driver/ec2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kitchen/driver/ec2.rb b/lib/kitchen/driver/ec2.rb index 4093f2cc..b4bcc844 100644 --- a/lib/kitchen/driver/ec2.rb +++ b/lib/kitchen/driver/ec2.rb @@ -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] && ec2.instance_exists?(state[:server_id]) + 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]