diff --git a/lib/puppet/provider/neutron.rb b/lib/puppet/provider/neutron.rb index f683d2877..c640f3cc8 100644 --- a/lib/puppet/provider/neutron.rb +++ b/lib/puppet/provider/neutron.rb @@ -31,8 +31,12 @@ def self.get_neutron_credentials conf = neutron_conf if conf and conf['keystone_authtoken'] and auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?} - return Hash[ auth_keys.map \ + creds = Hash[ auth_keys.map \ { |k| [k, conf['keystone_authtoken'][k].strip] } ] + if conf['DEFAULT'] and !conf['DEFAULT']['nova_region_name'].nil? + creds['nova_region_name'] = conf['DEFAULT']['nova_region_name'] + end + return creds else raise(Puppet::Error, "File: #{conf_filename} does not contain all \ required sections. Neutron types will not work if neutron is not \ @@ -68,6 +72,9 @@ def self.auth_neutron(*args) :OS_TENANT_NAME => q['admin_tenant_name'], :OS_PASSWORD => q['admin_password'] } + if q.key?('nova_region_name') + authenv[:OS_REGION_NAME] = q['nova_region_name'] + end begin withenv authenv do neutron(args) diff --git a/spec/unit/provider/neutron_spec.rb b/spec/unit/provider/neutron_spec.rb index e522f10fa..35a3ff381 100644 --- a/spec/unit/provider/neutron_spec.rb +++ b/spec/unit/provider/neutron_spec.rb @@ -64,6 +64,15 @@ def klass klass.get_auth_endpoint.should == auth_endpoint end + it 'should find region_name if specified' do + conf = { + 'keystone_authtoken' => credential_hash, + 'DEFAULT' => { 'nova_region_name' => 'REGION_NAME' } + } + klass.expects(:neutron_conf).returns(conf) + klass.neutron_credentials['nova_region_name'] == 'REGION_NAME' + end + end describe 'when invoking the neutron cli' do @@ -80,6 +89,21 @@ def klass klass.auth_neutron('test_retries') end + it 'should set region in the environment if needed' do + authenv = { + :OS_AUTH_URL => auth_endpoint, + :OS_USERNAME => credential_hash['admin_user'], + :OS_TENANT_NAME => credential_hash['admin_tenant_name'], + :OS_PASSWORD => credential_hash['admin_password'], + :OS_REGION_NAME => 'REGION_NAME', + } + + cred_hash = credential_hash.merge({'nova_region_name' => 'REGION_NAME'}) + klass.expects(:get_neutron_credentials).with().returns(cred_hash) + klass.expects(:withenv).with(authenv) + klass.auth_neutron('test_retries') + end + ['[Errno 111] Connection refused', '(HTTP 400)'].reverse.each do |valid_message| it "should retry when neutron cli returns with error #{valid_message}" do