Skip to content

Commit

Permalink
Add multi-region support
Browse files Browse the repository at this point in the history
If only one region is available then the Neutron CLI will just pick the
only one available.  However, if more than one is available, then it
will error out about ambiguous region.  This patch extends the base
provider code to parse out the nova_region_name when it's parsing out
the keystone credentials and define the OS_REGION_NAME environment
variable when calling neutron, if the nova_region_name variable exists
in the config file.

Closes-Bug: #1329552
Change-Id: Ic0d59dcb02a11e93e8fad1e0e2ea830fb0dcccc7
  • Loading branch information
claytono committed Jun 18, 2014
1 parent 069d086 commit d1235d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/puppet/provider/neutron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/provider/neutron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d1235d7

Please sign in to comment.