lib/kitchen/driver/ec2.rb in kitchen-ec2-0.9.0 vs lib/kitchen/driver/ec2.rb in kitchen-ec2-0.9.1

- old
+ new

@@ -18,13 +18,14 @@ require "benchmark" require "json" require "aws" require "kitchen" -require "kitchen/driver/ec2_version" +require_relative "ec2_version" require_relative "aws/client" require_relative "aws/instance_generator" +require "aws-sdk-core/waiters/errors" module Kitchen module Driver @@ -58,10 +59,11 @@ default_config :image_id do |driver| driver.default_ami end default_config :username, nil default_config :associate_public_ip, nil + default_config :interface, nil required_config :aws_ssh_key_id required_config :image_id def self.validation_warn(driver, old_key, new_key) @@ -192,18 +194,25 @@ wait_log = proc do |attempts| c = attempts * config[:retryable_sleep] t = config[:retryable_tries] * config[:retryable_sleep] info "Waited #{c}/#{t}s for instance <#{state[:server_id]}> to become ready." end - server = server.wait_until( - :max_attempts => config[:retryable_tries], - :delay => config[:retryable_sleep], - :before_attempt => wait_log - ) do |s| - hostname = hostname(s) - # Euca instances often report ready before they have an IP - s.state.name == "running" && !hostname.nil? && hostname != "0.0.0.0" + begin + server = server.wait_until( + :max_attempts => config[:retryable_tries], + :delay => config[:retryable_sleep], + :before_attempt => wait_log + ) do |s| + hostname = hostname(s, config[:interface]) + # Euca instances often report ready before they have an IP + s.exists? && s.state.name == "running" && !hostname.nil? && hostname != "0.0.0.0" + end + rescue ::Aws::Waiters::Errors::WaiterFailed + error("Ran out of time waiting for the server with id [#{state[:server_id]}]" \ + " to become ready, attempting to destroy it") + destroy(state) + raise end info("EC2 instance <#{state[:server_id]}> ready.") state[:hostname] = hostname(server) instance.transport.connection(state).wait_until_ready @@ -215,11 +224,11 @@ return if state[:server_id].nil? server = ec2.get_instance(state[:server_id]) unless server.nil? instance.transport.connection(state).close - server.terminate unless server.nil? + server.terminate end if state[:spot_request_id] debug("Deleting spot request <#{state[:server_id]}>") ec2.client.cancel_spot_instance_requests( :spot_instance_request_ids => [state[:spot_request_id]] @@ -233,12 +242,10 @@ def default_ami region = amis["regions"][config[:region]] region && region[instance.platform.name] end - private - def ec2 @ec2 ||= Aws::Client.new( config[:region], config[:shared_credentials_profile], config[:aws_access_key_id], @@ -352,9 +359,11 @@ server.send(interface_type) else potential_hostname = nil INTERFACE_TYPES.values.each do |type| potential_hostname ||= server.send(type) + # AWS returns an empty string if the dns name isn't populated yet + potential_hostname = nil if potential_hostname == "" end potential_hostname end end