mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] Fix new instance eventual consistency for the non-filtered case.
This commit is contained in:
parent
709c8b807f
commit
f09a148950
2 changed files with 28 additions and 4 deletions
|
@ -154,16 +154,25 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
brand_new_instances = instance_set.find_all do |instance|
|
||||
instance['instanceState']['name'] == 'pending' &&
|
||||
Time.now - instance['launchTime'] < Fog::Mock.delay * 2
|
||||
end
|
||||
|
||||
# Error if filtering for a brand new instance directly
|
||||
if (filters['instance-id'] || filters['instanceId']) && !brand_new_instances.empty?
|
||||
raise Fog::Compute::AWS::NotFound.new("The instance ID '#{brand_new_instances.first['instanceId']}' does not exist")
|
||||
end
|
||||
|
||||
# Otherwise don't include it in the list
|
||||
instance_set = instance_set.reject {|instance| brand_new_instances.include?(instance) }
|
||||
|
||||
response.status = 200
|
||||
reservation_set = {}
|
||||
|
||||
instance_set.each do |instance|
|
||||
case instance['instanceState']['name']
|
||||
when 'pending'
|
||||
if Time.now - instance['launchTime'] < Fog::Mock.delay * 2
|
||||
raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance['instanceId']}' does not exist")
|
||||
end
|
||||
|
||||
if Time.now - instance['launchTime'] >= Fog::Mock.delay * 2
|
||||
instance['ipAddress'] = Fog::AWS::Mock.ip_address
|
||||
instance['originalIpAddress'] = instance['ipAddress']
|
||||
|
|
|
@ -138,6 +138,21 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
|||
data
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
# Ensure the new instance doesn't show up in mock describe_instances right away
|
||||
tests("#describe_instances").formats(@describe_instances_format) do
|
||||
body = Fog::Compute[:aws].describe_instances.body
|
||||
instance_ids = body['reservationSet'].map {|reservation| reservation['instancesSet'].map {|instance| instance['instanceId'] } }.flatten
|
||||
test("doesn't include the new instance") { !instance_ids.include?(@instance_id) }
|
||||
body
|
||||
end
|
||||
|
||||
# But querying for the new instance directly should raise an error
|
||||
tests("#describe_instances('instance-id' => '#{@instance_id}')").raises(Fog::Compute::AWS::NotFound) do
|
||||
Fog::Compute[:aws].describe_instances('instance-id' => @instance_id)
|
||||
end
|
||||
end
|
||||
|
||||
server = Fog::Compute[:aws].servers.get(@instance_id)
|
||||
while server.nil? do
|
||||
# It may take a moment to get the server after launching it
|
||||
|
|
Loading…
Add table
Reference in a new issue