Skip to content

Commit

Permalink
Fix floating IP assignement
Browse files Browse the repository at this point in the history
Depending on the latency within Neutron to actually assign the floating
IP, the plugin doesn't manage to resolve the IP when it tries to access the
machine immediately after the assignment request. A race condition is caused
by a missing assignment into the machine config object.
  • Loading branch information
ggiamarchi committed May 20, 2017
1 parent 2978da1 commit a7e2af3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/lib/vagrant-openstack-provider/config_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ def resolve_floating_ip(env)
config = env[:machine].provider_config
nova = env[:openstack_client].nova
return config.floating_ip if config.floating_ip

fail Errors::UnableToResolveFloatingIP if config.floating_ip_pool.nil? || config.floating_ip_pool.empty?

@logger.debug 'Searching for available ips'
free_ip = search_free_ip(config, nova, env)
config.floating_ip = free_ip
return free_ip unless free_ip.nil?

@logger.debug 'Allocate new ip anyway'
allocated_ip = allocate_ip(config, nova, env)
config.floating_ip = allocated_ip
return allocated_ip unless allocated_ip.nil?
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
FloatingIP.new('80.81.82.85', 'pool-1', nil)
end
config.stub(:floating_ip_pool) { ['pool-1'] }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.85')
end
end
Expand All @@ -261,6 +262,7 @@
FloatingIP.new('80.81.82.83', 'pool-1', nil)]
end
config.stub(:floating_ip_pool) { ['pool-1'] }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.83')
end
end
Expand All @@ -275,6 +277,7 @@
FloatingIP.new('80.81.82.84', 'pool-1', nil)
end
config.stub(:floating_ip_pool) { ['pool-1'] }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.84')
end
end
Expand All @@ -294,6 +297,7 @@
FloatingIP.new('80.81.82.85', 'pool-1', nil)
end
config.stub(:floating_ip_pool) { %w(pool-1 pool-2) }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.85')
end
end
Expand All @@ -306,6 +310,7 @@
FloatingIP.new('80.81.82.83', 'pool-2', nil)]
end
config.stub(:floating_ip_pool) { %w(pool-1 pool-2) }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.83')
end
end
Expand All @@ -322,6 +327,7 @@
FloatingIP.new('80.81.82.84', 'pool-1', nil)
end
config.stub(:floating_ip_pool) { %w(pool-1 pool-2) }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.84')
end
end
Expand All @@ -337,6 +343,7 @@
FloatingIP.new('80.81.82.84', 'pool-2', nil)
end
config.stub(:floating_ip_pool) { %w(pool-1 pool-2) }
config.stub(:floating_ip=) { nil }
@action.resolve_floating_ip(env).should eq('80.81.82.84')
end
end
Expand All @@ -350,6 +357,7 @@
nova.stub(:allocate_floating_ip).with(env, 'pool-1').and_raise Errors::VagrantOpenstackError, message: 'error', code: 404
nova.stub(:allocate_floating_ip).with(env, 'pool-2').and_raise Errors::VagrantOpenstackError, message: 'error', code: 404
config.stub(:floating_ip_pool) { %w(pool-1 pool-2) }
config.stub(:floating_ip=) { nil }
expect { @action.resolve_floating_ip(env) }.to raise_error(Errors::VagrantOpenstackError)
end
end
Expand Down

0 comments on commit a7e2af3

Please sign in to comment.