Support to set external_network_bridge empty

external_network_bridge could be empty to support multiple external
networks, update l3_agent recipe to support this situation.

Change-Id: Idca94b9d40df750f89e70567e641fe96b6f4a4b1
Closes-Bug: #1483994
This commit is contained in:
leejian0612 2015-08-12 16:49:41 +08:00
parent 08bd03d011
commit f8b8355684
6 changed files with 49 additions and 26 deletions

View File

@ -375,7 +375,8 @@ default['openstack']['network']['l3']['gateway_external_network_name'] = nil
default['openstack']['network']['l3']['handle_internal_only_routers'] = 'True'
# Name of bridge used for external network traffic. This should be set to
# empty value for the linux bridge
# empty value for the linux bridge. When external_network_bridge is empty or nil,
# creation of external bridge will be skipped in the recipe.
default['openstack']['network']['l3']['external_network_bridge'] = 'br-ex'
# Interface to use for external bridge.

View File

@ -120,14 +120,16 @@ case driver_name
when 'OVSInterfaceDriver'
ext_bridge = node['openstack']['network']['l3']['external_network_bridge']
ext_bridge_iface = node['openstack']['network']['l3']['external_network_bridge_interface']
execute 'enable external_network_bridge_interface' do
command "ip link set #{ext_bridge_iface} up"
end
execute 'create external network bridge' do
command "ovs-vsctl add-br #{ext_bridge} && ovs-vsctl add-port #{ext_bridge} #{ext_bridge_iface}"
action :run
not_if "ovs-vsctl br-exists #{ext_bridge}"
only_if "ip link show #{ext_bridge_iface}"
unless ext_bridge.to_s.empty?
execute 'create external network bridge' do
command "ovs-vsctl add-br #{ext_bridge}"
action :run
not_if "ovs-vsctl br-exists #{ext_bridge}"
end
execute 'enable external_network_bridge_interface' do
command "ip link set #{ext_bridge_iface} up && ovs-vsctl add-port #{ext_bridge} #{ext_bridge_iface}"
only_if "ip link show #{ext_bridge_iface}"
end
end
when 'BridgeInterfaceDriver'
# TODO: Handle linuxbridge case

View File

@ -7,6 +7,7 @@ describe 'openstack-network::l3_agent' do
let(:node) { runner.node }
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
stub_command('ovs-vsctl br-exists br-ex').and_return(false)
runner.converge(described_recipe)
end

View File

@ -12,6 +12,10 @@ describe 'openstack-network::l3_agent' do
runner.converge(described_recipe)
end
before do
stub_command('ovs-vsctl br-exists br-ex').and_return(false)
end
include_context 'neutron-stubs'
it 'starts the l3 agent on boot' do
@ -72,14 +76,20 @@ describe 'openstack-network::l3_agent' do
let(:file_name) { file.name }
end
%w(handle_internal_only_routers external_network_bridge metadata_port send_arp_for_ha
periodic_interval periodic_fuzzy_delay router_delete_namespaces).each do |attr|
%w(handle_internal_only_routers metadata_port send_arp_for_ha periodic_interval
periodic_fuzzy_delay router_delete_namespaces).each do |attr|
it "displays the #{attr} l3 attribute" do
node.set['openstack']['network']['l3'][attr] = "network_l3_#{attr}_value"
expect(chef_run).to render_file(file.name).with_content(/^#{attr} = network_l3_#{attr}_value$/)
end
end
it 'displays the external_network_bridge l3 attribute' do
node.set['openstack']['network']['l3']['external_network_bridge'] = 'network_l3_external_network_bridge_value'
stub_command('ovs-vsctl br-exists network_l3_external_network_bridge_value').and_return(false)
expect(chef_run).to render_file(file.name).with_content(/^external_network_bridge = network_l3_external_network_bridge_value$/)
end
it 'sets the agent_mode attribute to dvr_snat' do
node.set['openstack']['network']['l3']['router_distributed'] = true
allow_any_instance_of(Chef::Recipe).to receive(:recipe_included?).with('openstack-network::server').and_return(true)
@ -157,39 +167,46 @@ describe 'openstack-network::l3_agent' do
end
describe 'create ovs bridges' do
let(:iplink) { 'ip link set eth1 up' }
let(:cmd) { 'ovs-vsctl add-br br-ex && ovs-vsctl add-port br-ex eth1' }
let(:cmd) { 'ovs-vsctl add-br br-ex' }
let(:iplink) { 'ip link set eth1 up && ovs-vsctl add-port br-ex eth1' }
it "doesn't add the external bridge if it already exists" do
stub_command(/ovs-vsctl br-exists/).and_return(true)
stub_command(/ip link show eth1/).and_return(true)
it 'does not add the external bridge and disable external_network_bridge_interface if external_network_bridge is empty' do
node.set['openstack']['network']['l3']['external_network_bridge'] = ''
expect(chef_run).to run_execute(iplink)
expect(chef_run).not_to run_execute(cmd)
expect(chef_run).not_to run_execute(iplink)
end
it "doesn't add the external bridge if the physical interface doesn't exist" do
stub_command(/ovs-vsctl br-exists/).and_return(true)
it 'does not add the external bridge if it already exists' do
stub_command(/ovs-vsctl br-exists br-ex/).and_return(true)
stub_command(/ip link show eth1/).and_return(true)
expect(chef_run).not_to run_execute(cmd)
expect(chef_run).to run_execute(iplink)
end
it 'disable external_network_bridge_interface if the physical interface does not exist' do
stub_command(/ovs-vsctl br-exists br-ex/).and_return(false)
stub_command(/ip link show eth1/).and_return(false)
expect(chef_run).to run_execute(iplink)
expect(chef_run).not_to run_execute(cmd)
expect(chef_run).to run_execute(cmd)
expect(chef_run).not_to run_execute(iplink)
end
it 'adds the external bridge if it does not yet exist' do
stub_command(/ovs-vsctl br-exists/).and_return(false)
stub_command(/ovs-vsctl br-exists br-ex/).and_return(false)
stub_command(/ip link show eth1/).and_return(true)
expect(chef_run).to run_execute(iplink)
expect(chef_run).to run_execute(cmd)
expect(chef_run).to run_execute(iplink)
end
it 'adds the external bridge if the physical interface exists' do
stub_command(/ovs-vsctl br-exists/).and_return(false)
it 'enable external_network_bridge_interface if the physical interface exists' do
stub_command(/ovs-vsctl br-exists br-ex/).and_return(false)
stub_command(/ip link show eth1/).and_return(true)
expect(chef_run).to run_execute(iplink)
expect(chef_run).to run_execute(cmd)
expect(chef_run).to run_execute(iplink)
end
end
end

View File

@ -8,6 +8,7 @@ describe 'openstack-network::vpn_agent' do
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['network']['enable_vpn'] = true
stub_command('ovs-vsctl br-exists br-ex').and_return(false)
runner.converge(described_recipe)
end

View File

@ -8,6 +8,7 @@ describe 'openstack-network::vpn_agent' do
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['network']['enable_vpn'] = true
stub_command('ovs-vsctl br-exists br-ex').and_return(false)
runner.converge(described_recipe)
end