Allow specifying the gateway_external_network by name
This change makes the l3_agent recipe lookup the ID of the network used for the gateway external network by name. For example, specify node[openstack][network][l3][gateway_external_network_name] = public and the recipe will lookup the network by name. It will use openstack-common/libraries/cli.rb network_uuid method, effectively querying `neutron net-external-list`. The result is saved to gateway_external_network_id and used on subsequent runs. To have the recipe check the UUID again (e.g. to update it), reset the _id attribute to nil. Change-Id: I5df6f9989df7b18121a8050835a192da9e1a762e
This commit is contained in:
parent
3caeb5f632
commit
f149cb105b
|
@ -7,8 +7,8 @@ This file is used to list changes made in each version of cookbook-openstack-net
|
|||
* Add attribute for ML2 enable_ipset
|
||||
* Bump Chef gem to 11.16
|
||||
* Add attributes for api_workers and rpc_workers
|
||||
|
||||
* Add attributes for quota_router and quota_floatingip
|
||||
* Allow specifying the L3 agents' gateway_external_network by name.
|
||||
|
||||
## 10.0.1
|
||||
* Add tunnel_types item in ovs_neutron_plugin.ini.erb
|
||||
|
|
|
@ -352,6 +352,8 @@ default['openstack']['network']['l3']['router_id'] = nil
|
|||
# the agent will enforce that only a single external networks exists and
|
||||
# use that external network id
|
||||
default['openstack']['network']['l3']['gateway_external_network_id'] = nil
|
||||
# If this name is specified and the ID above is nil, it will be looked up.
|
||||
default['openstack']['network']['l3']['gateway_external_network_name'] = nil
|
||||
|
||||
# Indicates that this L3 agent should also handle routers that do not have
|
||||
# an external network gateway configured. This option should be True only
|
||||
|
|
|
@ -22,6 +22,28 @@
|
|||
|
||||
include_recipe 'openstack-network::common'
|
||||
|
||||
ruby_block 'query gateway external network uuid' do
|
||||
block do
|
||||
begin
|
||||
external_name = node['openstack']['network']['l3']['gateway_external_network_name']
|
||||
admin_user = node['openstack']['identity']['admin_user']
|
||||
admin_tenant = node['openstack']['identity']['admin_tenant_name']
|
||||
env = openstack_command_env admin_user, admin_tenant
|
||||
|
||||
external_id = network_uuid 'net-external', 'name', external_name, env
|
||||
Chef::Log.error("gateway external network UUID for #{external_name} not found.") if external_id.nil?
|
||||
node.set['openstack']['network']['l3']['gateway_external_network_id'] = external_id
|
||||
rescue RuntimeError => e
|
||||
Chef::Log.error("Could not query UUID for network #{external_name}. Error was #{e.message}") unless external_id
|
||||
end
|
||||
end
|
||||
action :run
|
||||
only_if do
|
||||
node['openstack']['network']['l3']['gateway_external_network_id'].nil? &&
|
||||
node['openstack']['network']['l3']['gateway_external_network_name']
|
||||
end
|
||||
end
|
||||
|
||||
platform_options = node['openstack']['network']['platform']
|
||||
core_plugin = node['openstack']['network']['core_plugin']
|
||||
main_plugin = node['openstack']['network']['core_plugin_map'][core_plugin.split('.').last.downcase]
|
||||
|
|
|
@ -33,6 +33,24 @@ describe 'openstack-network::l3_agent' do
|
|||
expect(chef_run).to upgrade_package('neutron-l3-agent')
|
||||
end
|
||||
|
||||
describe 'gateway_external_network_id' do
|
||||
before do
|
||||
node.set['openstack']['network']['l3']['gateway_external_network_name'] = 'public'
|
||||
end
|
||||
|
||||
it 'looks up and sets the id attribute if needed' do
|
||||
node.set['openstack']['network']['l3']['gateway_external_network_id'] = nil
|
||||
chef_run.ruby_block('query gateway external network uuid').old_run_action(:create)
|
||||
expect(chef_run.node['openstack']['network']['l3']['gateway_external_network_id']).to eq '000-NET-UUID-FROM-CLI'
|
||||
end
|
||||
|
||||
it 'uses the id attribute if it is already set' do
|
||||
node.set['openstack']['network']['l3']['gateway_external_network_id'] = '000-NET-UUID-ALREADY-SET'
|
||||
chef_run.ruby_block('query gateway external network uuid').old_run_action(:create)
|
||||
expect(chef_run.node['openstack']['network']['l3']['gateway_external_network_id']).to eq '000-NET-UUID-ALREADY-SET'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'l3_agent.ini' do
|
||||
let(:file) { chef_run.template('/etc/neutron/l3_agent.ini') }
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ shared_context 'neutron-stubs' do
|
|||
allow_any_instance_of(Chef::Resource::RubyBlock).to receive(:identity_uuid)
|
||||
.with('tenant', 'name', 'service', {})
|
||||
.and_return('000-UUID-FROM-CLI')
|
||||
allow_any_instance_of(Chef::Resource::RubyBlock).to receive(:network_uuid)
|
||||
.with('net-external', 'name', 'public', {})
|
||||
.and_return('000-NET-UUID-FROM-CLI')
|
||||
|
||||
stub_command('dpkg -l | grep openvswitch-switch | grep 1.10.2-1').and_return(true)
|
||||
stub_command('ovs-vsctl br-exists br-int').and_return(false)
|
||||
|
|
Loading…
Reference in New Issue