Skip to content

Commit

Permalink
Return first adress when multiple are found
Browse files Browse the repository at this point in the history
Fix #155
  • Loading branch information
julienvey committed Nov 6, 2014
1 parent 7b40f3f commit c444e2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/lib/vagrant-openstack-provider/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_ip_address(env)
return network_detail['addr'] if network_detail['OS-EXT-IPS:type'] == 'floating'
end
end
return details['addresses'].first[1][0]['addr'] if details['addresses'].size == 1 && details['addresses'].first[1].size == 1
return details['addresses'].first[1][0]['addr'] if details['addresses'].size >= 1 && details['addresses'].first[1].size >= 1
fail Errors::UnableToResolveIP
end
end
Expand Down
26 changes: 26 additions & 0 deletions source/spec/vagrant-openstack-provider/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@
}
}
end
expect(@action.get_ip_address(env)).to eq('13.13.13.13')
end
end

context 'with networks but no ips' do
it 'fails' do
config.stub(:floating_ip) { nil }
nova.stub(:get_server_details).with(env, '1234id') do
{
'addresses' => {
'toto' => []
}
}
end
expect { @action.get_ip_address(env) }.to raise_error(Errors::UnableToResolveIP)
end
end

context 'with no networks ' do
it 'fails' do
config.stub(:floating_ip) { nil }
nova.stub(:get_server_details).with(env, '1234id') do
{
'addresses' => {}
}
end
expect { @action.get_ip_address(env) }.to raise_error(Errors::UnableToResolveIP)
end
end
Expand Down

0 comments on commit c444e2e

Please sign in to comment.