Skip to content

Commit 9bd8e0f

Browse files
committed
Merge pull request #97 from test-kitchen/chuckg-feature/fix_server_wait_for_private_ip_addresses
Fix connection to servers without a "public_ip_address" interface (ie: VPC)
2 parents 58718f5 + 23f4d94 commit 9bd8e0f

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

lib/kitchen/driver/ec2.rb

+28-8
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def create(state)
9595
server.wait_for do
9696
print '.'
9797
# Euca instances often report ready before they have an IP
98-
ready? && !public_ip_address.nil? && public_ip_address != '0.0.0.0'
98+
hostname = Kitchen::Driver::Ec2.hostname(self)
99+
ready? && !hostname.nil? && hostname != '0.0.0.0'
99100
end
100101
print '(server ready)'
101102
state[:hostname] = hostname(server)
@@ -221,22 +222,41 @@ def amis
221222
end
222223
end
223224

224-
def interface_types
225+
#
226+
# Ordered mapping from config name to Fog name. Ordered by preference
227+
# when looking up hostname.
228+
#
229+
INTERFACE_TYPES =
225230
{
226231
'dns' => 'dns_name',
227232
'public' => 'public_ip_address',
228233
'private' => 'private_ip_address'
229234
}
230-
end
231235

236+
#
237+
# Lookup hostname of a provided server using the configured interface.
238+
#
232239
def hostname(server)
233-
if config[:interface]
234-
method = interface_types.fetch(config[:interface]) do
235-
raise Kitchen::UserError, 'Invalid interface'
240+
Kitchen::Driver::Ec2.hostname(server, config[:interface])
241+
end
242+
243+
#
244+
# Lookup hostname of provided server. If interface_type is provided use
245+
# that interface to lookup hostname. Otherwise, try ordered list of
246+
# options.
247+
#
248+
def self.hostname(server, interface_type=nil)
249+
if interface_type
250+
INTERFACE_TYPES.fetch(interface_type) do
251+
raise Kitchen::UserError, "Invalid interface [#{interface_type}]"
236252
end
237-
server.send(method)
253+
server.send(interface_type)
238254
else
239-
server.dns_name || server.public_ip_address || server.private_ip_address
255+
potential_hostname = nil
256+
INTERFACE_TYPES.values.each do |type|
257+
potential_hostname ||= server.send(type)
258+
end
259+
potential_hostname
240260
end
241261
end
242262

0 commit comments

Comments
 (0)