From b5a5d28440b4ec8f86ca6a3d9171665cd1f74a9e Mon Sep 17 00:00:00 2001 From: mael Date: Sat, 29 Nov 2014 13:16:55 +0100 Subject: [PATCH 1/4] Issue#110 : specify endpoint interface configuration --- source/Vagrantfile | 1 + .../catalog/openstack_catalog.rb | 7 +- .../lib/vagrant-openstack-provider/config.rb | 1 + .../action/connect_openstack_spec.rb | 289 ++++++++++++++++++ 4 files changed, 295 insertions(+), 3 deletions(-) diff --git a/source/Vagrantfile b/source/Vagrantfile index 660fa6d..2b6b04d 100644 --- a/source/Vagrantfile +++ b/source/Vagrantfile @@ -7,6 +7,7 @@ Vagrant.configure('2') do |config| config.ssh.username = ENV['OS_SSH_USERNAME'] config.vm.provider :openstack do |os| + os.endpoint_type = ENV['OS_ENDPOINT_TYPE'] os.openstack_auth_url = ENV['OS_AUTH_URL'] os.tenant_name = ENV['OS_TENANT_NAME'] os.username = ENV['OS_USERNAME'] diff --git a/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb b/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb index 40b37dc..66c0c6b 100644 --- a/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb +++ b/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb @@ -13,17 +13,18 @@ def read(env, catalog) @logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints')) @logger.info("Selecting endpoints matching region '#{config.region}'") unless config.region.nil? + endpoint_type = env[:endpoint_type].nil? ? 'publicURL' : env[:endpoint_type] catalog.each do |service| se = service['endpoints'] if config.region.nil? if se.size > 1 env[:ui].warn I18n.t('vagrant_openstack.client.multiple_endpoint', size: se.size, type: service['type']) - env[:ui].warn " => #{service['endpoints'][0]['publicURL']}" + env[:ui].warn " => #{service['endpoints'][0][endpoint_type]}" end - url = se[0]['publicURL'].strip + url = se[0][endpoint_type].strip else se.each do |endpoint| - url = endpoint['publicURL'].strip if endpoint['region'].eql? config.region + url = endpoint[endpoint_type].strip if endpoint['region'].eql? config.region end end endpoints[service['type'].to_sym] = url unless url.nil? || url.empty? diff --git a/source/lib/vagrant-openstack-provider/config.rb b/source/lib/vagrant-openstack-provider/config.rb index 485e8e9..c072f72 100644 --- a/source/lib/vagrant-openstack-provider/config.rb +++ b/source/lib/vagrant-openstack-provider/config.rb @@ -168,6 +168,7 @@ def initialize @openstack_orchestration_url = UNSET_VALUE @openstack_image_url = UNSET_VALUE @openstack_auth_url = UNSET_VALUE + @endpoint_type = UNSET_VALUE @region = UNSET_VALUE @flavor = UNSET_VALUE @image = UNSET_VALUE diff --git a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb index 30e1948..d8e780f 100644 --- a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb @@ -44,6 +44,25 @@ end end + let(:neutron_admin_url) 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/admin', + 'rel' => 'self' + } + ] + } + ] + end + end + end + let(:neutron_france) do double.tap do |neutron| neutron.stub(:get_api_version_list).with(anything) do @@ -82,6 +101,25 @@ end end + let(:glance_admin_url) do + double.tap do |glance| + glance.stub(:get_api_version_list).with(anything) do + [ + { + 'status' => 'CURRENT', + 'id' => 'v2.1', + 'links' => [ + { + 'href' => 'http://glance/v2.0/admin', + 'rel' => 'self' + } + ] + } + ] + end + end + end + let(:glance_v1) do double.tap do |glance| glance.stub(:get_api_version_list).with(anything) do @@ -317,6 +355,257 @@ end end + describe 'endpoint_type' do + context 'with adminURL specified' do + it 'read service catalog and stores endpoints URL in session' do + catalog = [ + { + 'endpoints' => [ + { + 'publicURL' => 'http://nova/v2/projectId', + 'adminURL' => 'http://nova/v2/projectId/admin', + 'id' => '1' + } + ], + 'type' => 'compute', + 'name' => 'nova' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://neutron', + 'adminURL' => 'http://neutron/admin', + 'id' => '2' + } + ], + 'type' => 'network', + 'name' => 'neutron' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://cinder/v2/projectId', + 'adminURL' => 'http://cinder/v2/projectId/admin', + 'id' => '2' + } + ], + 'type' => 'volume', + 'name' => 'cinder' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://glance', + 'adminURL' => 'http://glance/admin', + 'id' => '2' + } + ], + 'type' => 'image', + 'name' => 'glance' + } + ] + + double.tap do |keystone| + keystone.stub(:authenticate).with(anything) { catalog } + env[:openstack_client].stub(:keystone) { keystone } + end + env[:openstack_client].stub(:neutron) { neutron_admin_url } + env[:openstack_client].stub(:glance) { glance_admin_url } + env[:endpoint_type] = 'adminURL' + + @action.call(env) + + expect(env[:openstack_client].session.endpoints) + .to eq(compute: 'http://nova/v2/projectId/admin', + network: 'http://neutron/v2.0/admin', + volume: 'http://cinder/v2/projectId/admin', + image: 'http://glance/v2.0/admin') + end + end + end + + describe 'endpoint_type' do + context 'with internalURL specified' do + it 'read service catalog and stores endpoints URL in session' do + catalog = [ + { + 'endpoints' => [ + { + 'publicURL' => 'http://nova/v2/projectId', + 'adminURL' => 'http://nova/v2/projectId/admin', + 'internalURL' => 'http://nova/v2/projectId/internal', + 'id' => '1' + } + ], + 'type' => 'compute', + 'name' => 'nova' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://cinder/v2/projectId', + 'adminURL' => 'http://cinder/v2/projectId/admin', + 'internalURL' => 'http://cinder/v2/projectId/internal', + 'id' => '2' + } + ], + 'type' => 'volume', + 'name' => 'cinder' + } + ] + + double.tap do |keystone| + keystone.stub(:authenticate).with(anything) { catalog } + env[:openstack_client].stub(:keystone) { keystone } + end + env[:endpoint_type] = 'internalURL' + + @action.call(env) + + expect(env[:openstack_client].session.endpoints) + .to eq(compute: 'http://nova/v2/projectId/internal', + volume: 'http://cinder/v2/projectId/internal') + end + end + end + + describe 'endpoint_type' do + context 'with publicURL specified' do + it 'read service catalog and stores endpoints URL in session' do + catalog = [ + { + 'endpoints' => [ + { + 'publicURL' => 'http://nova/v2/projectId', + 'adminURL' => 'http://nova/v2/projectId/admin', + 'id' => '1' + } + ], + 'type' => 'compute', + 'name' => 'nova' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://neutron', + 'adminURL' => 'http://neutron/admin', + 'id' => '2' + } + ], + 'type' => 'network', + 'name' => 'neutron' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://cinder/v2/projectId', + 'adminURL' => 'http://cinder/v2/projectId/admin', + 'id' => '2' + } + ], + 'type' => 'volume', + 'name' => 'cinder' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://glance', + 'adminURL' => 'http://glance/admin', + 'id' => '2' + } + ], + 'type' => 'image', + 'name' => 'glance' + } + ] + + double.tap do |keystone| + keystone.stub(:authenticate).with(anything) { catalog } + env[:openstack_client].stub(:keystone) { keystone } + end + env[:openstack_client].stub(:neutron) { neutron } + env[:openstack_client].stub(:glance) { glance } + env[:endpoint_type] = 'publicURL' + + @action.call(env) + + expect(env[:openstack_client].session.endpoints) + .to eq(compute: 'http://nova/v2/projectId', + network: 'http://neutron/v2.0', + volume: 'http://cinder/v2/projectId', + image: 'http://glance/v2.0') + end + end + end + + describe 'endpoint_type' do + context 'with nothing specified' do + it 'read service catalog and stores endpoints URL in session taking publicURL by default' do + catalog = [ + { + 'endpoints' => [ + { + 'publicURL' => 'http://nova/v2/projectId', + 'adminURL' => 'http://nova/v2/projectId/admin', + 'id' => '1' + } + ], + 'type' => 'compute', + 'name' => 'nova' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://neutron', + 'adminURL' => 'http://neutron/admin', + 'id' => '2' + } + ], + 'type' => 'network', + 'name' => 'neutron' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://cinder/v2/projectId', + 'adminURL' => 'http://cinder/v2/projectId/admin', + 'id' => '2' + } + ], + 'type' => 'volume', + 'name' => 'cinder' + }, + { + 'endpoints' => [ + { + 'publicURL' => 'http://glance', + 'adminURL' => 'http://glance/admin', + 'id' => '2' + } + ], + 'type' => 'image', + 'name' => 'glance' + } + ] + + double.tap do |keystone| + keystone.stub(:authenticate).with(anything) { catalog } + env[:openstack_client].stub(:keystone) { keystone } + end + env[:openstack_client].stub(:neutron) { neutron } + env[:openstack_client].stub(:glance) { glance } + + @action.call(env) + + expect(env[:openstack_client].session.endpoints) + .to eq(compute: 'http://nova/v2/projectId', + network: 'http://neutron/v2.0', + volume: 'http://cinder/v2/projectId', + image: 'http://glance/v2.0') + end + end + end + context 'with glance v1 only' do it 'read service catalog and stores endpoints URL in session', :focus do catalog = [ From f33006503d78855fb33e4d959f61d57054912158 Mon Sep 17 00:00:00 2001 From: mael Date: Sat, 13 Dec 2014 00:57:04 +0100 Subject: [PATCH 2/4] issue#110: -endpoint_type moved to the config .rb file -test updated -endpoint_type error message added -readme annotated --- README.md | 1 + .../catalog/openstack_catalog.rb | 2 +- .../lib/vagrant-openstack-provider/config.rb | 7 ++ source/locales/en.yml | 2 + .../action/connect_openstack_spec.rb | 77 ++----------------- 5 files changed, 16 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 5f08e5a..d6611f5 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ vagrant will authenticate against the UK authentication endpoint. * `openstack_network_url` - The network service URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint. * `openstack_volume_url` - The block storage URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint. * `openstack_image_url` - The image URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint. +* `endpoint_type` - The endpoint type to use : publicURL, adminURL, internalURL. If not provided, vagrant will use publicURL by default. ### VM Configuration diff --git a/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb b/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb index 66c0c6b..7c6192a 100644 --- a/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb +++ b/source/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb @@ -10,10 +10,10 @@ def read(env, catalog) config = env[:machine].provider_config client = env[:openstack_client] endpoints = client.session.endpoints + endpoint_type = config.endpoint_type @logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints')) @logger.info("Selecting endpoints matching region '#{config.region}'") unless config.region.nil? - endpoint_type = env[:endpoint_type].nil? ? 'publicURL' : env[:endpoint_type] catalog.each do |service| se = service['endpoints'] if config.region.nil? diff --git a/source/lib/vagrant-openstack-provider/config.rb b/source/lib/vagrant-openstack-provider/config.rb index c072f72..a5bb65d 100644 --- a/source/lib/vagrant-openstack-provider/config.rb +++ b/source/lib/vagrant-openstack-provider/config.rb @@ -160,6 +160,11 @@ class Config < Vagrant.plugin('2', :config) # @return [Boolean] attr_accessor :ssh_disabled + # Specify the endpoint_type to use : publicURL, adminURL, or internalURL (default is publicURL) + # + # @return [String] + attr_accessor :endpoint_type + def initialize @password = UNSET_VALUE @openstack_compute_url = UNSET_VALUE @@ -239,6 +244,7 @@ def finalize! @openstack_volume_url = nil if @openstack_volume_url == UNSET_VALUE @openstack_image_url = nil if @openstack_image_url == UNSET_VALUE @openstack_auth_url = nil if @openstack_auth_url == UNSET_VALUE + @endpoint_type = 'publicURL' if @endpoint_type == UNSET_VALUE @region = nil if @region == UNSET_VALUE @flavor = nil if @flavor == UNSET_VALUE @image = nil if @image == UNSET_VALUE @@ -280,6 +286,7 @@ def validate(machine) errors << I18n.t('vagrant_openstack.config.password_required') unless @password errors << I18n.t('vagrant_openstack.config.username_required') unless @username + errors << I18n.t('vagrant_openstack.config.invalid_endpoint_type') unless %w(publicURL adminURL internalURL).include?(@endpoint_type) validate_ssh_username(machine, errors) validate_stack_config(errors) diff --git a/source/locales/en.yml b/source/locales/en.yml index eeb5995..bee4331 100644 --- a/source/locales/en.yml +++ b/source/locales/en.yml @@ -98,6 +98,8 @@ en: name: 'mystack', template: '/path/to/heat_template.yml', }] + invalid_endpoint_type: |- + endpoint_type must be publicURL, adminURL or internalURL (if not provided, default is publicURL) metadata_must_be_hash: |- Metadata must be a hash. keypair_name_required: |- diff --git a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb index d8e780f..59b9711 100644 --- a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb @@ -22,6 +22,7 @@ config.stub(:username) { 'username' } config.stub(:password) { 'password' } config.stub(:region) { nil } + config.stub(:endpoint_type) { 'publicURL' } end end @@ -182,7 +183,7 @@ describe 'ConnectOpenstack' do context 'with one endpoint by service' do - it 'read service catalog and stores endpoints URL in session' do + it 'read service catalog and stores endpoints URL in session', :focus do catalog = [ { 'endpoints' => [ @@ -411,7 +412,7 @@ end env[:openstack_client].stub(:neutron) { neutron_admin_url } env[:openstack_client].stub(:glance) { glance_admin_url } - env[:endpoint_type] = 'adminURL' + config.stub(:endpoint_type) { 'adminURL' } @action.call(env) @@ -458,7 +459,7 @@ keystone.stub(:authenticate).with(anything) { catalog } env[:openstack_client].stub(:keystone) { keystone } end - env[:endpoint_type] = 'internalURL' + config.stub(:endpoint_type) { 'internalURL' } @action.call(env) @@ -525,75 +526,7 @@ end env[:openstack_client].stub(:neutron) { neutron } env[:openstack_client].stub(:glance) { glance } - env[:endpoint_type] = 'publicURL' - - @action.call(env) - - expect(env[:openstack_client].session.endpoints) - .to eq(compute: 'http://nova/v2/projectId', - network: 'http://neutron/v2.0', - volume: 'http://cinder/v2/projectId', - image: 'http://glance/v2.0') - end - end - end - - describe 'endpoint_type' do - context 'with nothing specified' do - it 'read service catalog and stores endpoints URL in session taking publicURL by default' do - catalog = [ - { - 'endpoints' => [ - { - 'publicURL' => 'http://nova/v2/projectId', - 'adminURL' => 'http://nova/v2/projectId/admin', - 'id' => '1' - } - ], - 'type' => 'compute', - 'name' => 'nova' - }, - { - 'endpoints' => [ - { - 'publicURL' => 'http://neutron', - 'adminURL' => 'http://neutron/admin', - 'id' => '2' - } - ], - 'type' => 'network', - 'name' => 'neutron' - }, - { - 'endpoints' => [ - { - 'publicURL' => 'http://cinder/v2/projectId', - 'adminURL' => 'http://cinder/v2/projectId/admin', - 'id' => '2' - } - ], - 'type' => 'volume', - 'name' => 'cinder' - }, - { - 'endpoints' => [ - { - 'publicURL' => 'http://glance', - 'adminURL' => 'http://glance/admin', - 'id' => '2' - } - ], - 'type' => 'image', - 'name' => 'glance' - } - ] - - double.tap do |keystone| - keystone.stub(:authenticate).with(anything) { catalog } - env[:openstack_client].stub(:keystone) { keystone } - end - env[:openstack_client].stub(:neutron) { neutron } - env[:openstack_client].stub(:glance) { glance } + config.stub(:endpoint_type) { 'publicURL' } @action.call(env) From 7cb01f1730a378a949e630ec1e9f71ca7db0a4db Mon Sep 17 00:00:00 2001 From: mael Date: Sat, 13 Dec 2014 01:44:18 +0100 Subject: [PATCH 3/4] issue#110: -removed endpoint_type from Vagrantfile --- source/Vagrantfile | 1 - 1 file changed, 1 deletion(-) diff --git a/source/Vagrantfile b/source/Vagrantfile index 2b6b04d..660fa6d 100644 --- a/source/Vagrantfile +++ b/source/Vagrantfile @@ -7,7 +7,6 @@ Vagrant.configure('2') do |config| config.ssh.username = ENV['OS_SSH_USERNAME'] config.vm.provider :openstack do |os| - os.endpoint_type = ENV['OS_ENDPOINT_TYPE'] os.openstack_auth_url = ENV['OS_AUTH_URL'] os.tenant_name = ENV['OS_TENANT_NAME'] os.username = ENV['OS_USERNAME'] From ac84102c9bf2b395ed0e16279f98255eef1af80a Mon Sep 17 00:00:00 2001 From: mael Date: Sat, 13 Dec 2014 01:46:29 +0100 Subject: [PATCH 4/4] issue#110 : removed endpoint_type from Vagrantfile --- .../action/connect_openstack_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb index 59b9711..9e7c88d 100644 --- a/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb @@ -183,7 +183,7 @@ describe 'ConnectOpenstack' do context 'with one endpoint by service' do - it 'read service catalog and stores endpoints URL in session', :focus do + it 'read service catalog and stores endpoints URL in session' do catalog = [ { 'endpoints' => [ @@ -540,7 +540,7 @@ end context 'with glance v1 only' do - it 'read service catalog and stores endpoints URL in session', :focus do + it 'read service catalog and stores endpoints URL in session' do catalog = [ { 'endpoints' => [