Skip to content

Commit

Permalink
Fix #49 - Resolve catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Aug 2, 2014
1 parent 2df39f2 commit 909bd14
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ def read_network_api_version(env)
end
fail Errors::MultipleApiVersion, api_name: 'Neutron', url_property: 'openstack_network_url', version_list: version_list
end

links = versions.first['links']
if links.size > 1
link_list = ''
links.each do |link|
link_list << "#{link['href']}\n"
end
fail Errors::MultipleApiUrl, api_name: 'Neutron', url_property: 'openstack_network_url', url_list: link_list
end

client.session.endpoints[:network] = links.first['href']
client.session.endpoints[:network] = versions.first['links'].first['href']
end

def override_endpoint_catalog_with_user_config(env)
Expand Down
4 changes: 0 additions & 4 deletions source/lib/vagrant-openstack-provider/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class MultipleApiVersion < VagrantOpenstackError
error_key(:multiple_api_version)
end

class MultipleApiUrl < VagrantOpenstackError
error_key(:multiple_api_url)
end

class CreateBadState < VagrantOpenstackError
error_key(:create_bad_state)
end
Expand Down
6 changes: 0 additions & 6 deletions source/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ en:
state: '%{state}', instead of properly booting. Run `vagrant status`
to find out what can be done about this state, or `vagrant destroy`
if you want to start over.
multiple_api_url: |-
Multiple url found for %{api_name} API
%{url_list}
You must specify the desired network API url by setting
the provider's property '%{url_property}'.
multiple_api_version: |-
Multiple version found for %{api_name} API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:config) do
double('config').tap do |config|
double.tap do |config|
config.stub(:openstack_auth_url) { 'http://keystoneAuthV2' }
config.stub(:openstack_compute_url) { nil }
config.stub(:openstack_network_url) { nil }
Expand All @@ -23,18 +23,27 @@
end

let(:neutron) do
double('neutron').tap do |neutron|
double.tap do |neutron|
neutron.stub(:get_api_version_list).with(anything) do
{

}
[
{
'status' => 'CURRENT',
'id' => 'v2.0',
'links' => [
{
'href' => 'http://neutron/v2.0',
'rel' => 'self'
}
]
}
]
end
end
end

let(:env) do
Hash.new.tap do |env|
env[:ui] = double('ui')
env[:ui] = double
env[:ui].stub(:info).with(anything)
env[:ui].stub(:warn).with(anything)
env[:machine] = double('machine')
Expand All @@ -44,17 +53,18 @@
end
end

before :each do
before(:all) do
ConnectOpenstack.send(:public, *ConnectOpenstack.private_instance_methods)
end

before :each do
VagrantPlugins::Openstack.session.reset
@action = ConnectOpenstack.new(app, env)
end

describe 'read_endpoint_catalog' do

context 'with compute and network services' do
it 'stores endpoints URL in session' do

describe 'ConnectOpenstack' do
context 'with one endpoint by service' do
it 'read service catalog and stores endpoints URL in session' do
catalog = [
{
'endpoints' => [
Expand All @@ -78,36 +88,21 @@
}
]

stub_request(:get, 'http://neutron/')
.with(header: { 'Accept' => 'application/json' })
.to_return(
status: 200,
body: '{
"versions": [
{
"status": "CURRENT",
"id": "v2.0",
"links": [
{
"href": "http://neutron/v2.0",
"rel": "self"
}
]
}
]
}')

@action.read_endpoint_catalog(env, catalog)
double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
env[:openstack_client].stub(:neutron) { neutron }

@action.call(env)

expect(env[:openstack_client].session.endpoints)
.to eq(compute: 'http://nova/v2/projectId', network: 'http://neutron/v2.0')

end
end

context 'with multiple endpoints for a service' do
it 'takes the first one' do

catalog = [
{
'endpoints' => [
Expand All @@ -125,31 +120,71 @@
}
]

stub_request(:get, 'http://neutron/alt')
.with(header: { 'Accept' => 'application/json' })
.to_return(
status: 200,
body: '{
"versions": [
{
"status": "CURRENT",
"id": "v2.0",
"links": [
{
"href": "http://neutron/v2.0",
"rel": "self"
}
]
}
]
}')

ConnectOpenstack.new(app, env).read_endpoint_catalog(env, catalog)
double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
env[:openstack_client].stub(:neutron) { neutron }

expect(env[:openstack_client].session.endpoints).to eq(network: 'http://neutron/v2.0')
@action.call(env)

expect(env[:openstack_client].session.endpoints).to eq(network: 'http://neutron/v2.0')
end
end

context 'with multiple versions for network service' do

let(:neutron) do
double.tap do |neutron|
neutron.stub(:get_api_version_list).with(anything) do
[
{
'status' => 'CURRENT',
'id' => 'v2.0',
'links' => [
{
'href' => 'http://neutron/v2.0',
'rel' => 'self'
}
]
},
{
'status' => '...',
'id' => 'v1.0',
'links' => [
{
'href' => 'http://neutron/v1.0',
'rel' => 'self'
}
]
}
]
end
end
end

it 'raise a MultipleApiVersion error' do
catalog = [
{
'endpoints' => [
{
'publicURL' => 'http://neutron',
'id' => '3'
}
],
'type' => 'network',
'name' => 'neutron'
}
]

double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
env[:openstack_client].stub(:neutron) { neutron }

expect { @action.call(env) }.to raise_error(Errors::MultipleApiVersion)
end
end
end
end
38 changes: 38 additions & 0 deletions source/spec/vagrant-openstack-provider/client/neutron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,42 @@
end
end
end

describe 'get_api_version_list' do
context 'basic' do
it 'returns version list' do
stub_request(:get, 'http://neutron/')
.with(header: { 'Accept' => 'application/json' })
.to_return(
status: 200,
body: '{
"versions": [
{
"status": "...",
"id": "v1.0",
"links": [
{
"href": "http://neutron/v1.0",
"rel": "self"
}
]
},
{
"status": "CURRENT",
"id": "v2.0",
"links": [
{
"href": "http://neutron/v2.0",
"rel": "self"
}
]
}
]}')

versions = @neutron_client.get_api_version_list(env)

expect(versions.size).to eq(2)
end
end
end
end

0 comments on commit 909bd14

Please sign in to comment.