From 841d4fce050d4aaf396545f9c9a1b24e95afab9a Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Wed, 16 Apr 2014 16:33:54 -0500 Subject: [PATCH] Allow data network openvswitch bridge to be created Allow data network ovs bridge to be created for flat and vlan. Add attributes to control creation. Add Tests. Change-Id: I4d4cb79c40f849193c5ff1a79c88b7049886d594 Closes-Bug: #1307587 --- CHANGELOG.md | 3 +++ attributes/default.rb | 8 ++++++++ metadata.rb | 2 +- recipes/openvswitch.rb | 14 ++++++++++++++ spec/openvswitch_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 254b255e..1c2d31fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG for cookbook-openstack-network This file is used to list changes made in each version of cookbook-openstack-network. +## 9.0.2 +* Fix to allow data network openvswitch bridge to be created + ## 9.0.1 * Fix package action to allow updates diff --git a/attributes/default.rb b/attributes/default.rb index f94a9da5..dc3139e6 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -430,6 +430,14 @@ default['openstack']['network']['openvswitch']['tun_peer_patch_port'] = nil # Example: bridge_mappings = physnet1:br-eth1 default['openstack']['network']['openvswitch']['bridge_mappings'] = nil +# Create OVS data network bridge for the physical network and configure it +# with the specified port. If nil or empty string is specified, the data +# network bridge will not be created. +# Format: : +# +# Example: bridge_mapping_interface = br-eth1:eth1 +default['openstack']['network']['openvswitch']['bridge_mapping_interface'] = nil + # Agent's polling interval in seconds default['openstack']['network']['openvswitch']['polling_interval'] = 2 diff --git a/metadata.rb b/metadata.rb index aa97e0a3..f59dc7cc 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ maintainer 'Jay Pipes ' license 'Apache 2.0' description 'Installs and configures the OpenStack Network API Service and various agents and plugins' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '9.0.1' +version '9.0.2' recipe 'openstack-network::client', 'Install packages required for network client' recipe 'openstack-network::server', 'Installs packages required for a OpenStack Network server' recipe 'openstack-network::openvswitch', 'Installs packages required for OVS' diff --git a/recipes/openvswitch.rb b/recipes/openvswitch.rb index c324289f..b213e5f3 100644 --- a/recipes/openvswitch.rb +++ b/recipes/openvswitch.rb @@ -126,6 +126,20 @@ unless ['nicira', 'plumgrid', 'bigswitch'].include?(main_plugin) end end +unless ['nicira', 'plumgrid', 'bigswitch'].include?(main_plugin) + unless node['openstack']['network']['openvswitch']['bridge_mapping_interface'].to_s.empty? + ext_bridge_mapping = node['openstack']['network']['openvswitch']['bridge_mapping_interface'] + ext_bridge, ext_bridge_iface = ext_bridge_mapping.split(':') + execute 'create data network bridge' do + command "ovs-vsctl add-br #{ext_bridge} -- 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}" + notifies :restart, 'service[neutron-plugin-openvswitch-agent]', :delayed + end + end +end + if node['openstack']['network']['disable_offload'] package 'ethtool' do diff --git a/spec/openvswitch_spec.rb b/spec/openvswitch_spec.rb index 10421e1a..ad6d3348 100644 --- a/spec/openvswitch_spec.rb +++ b/spec/openvswitch_spec.rb @@ -165,5 +165,44 @@ describe 'openstack-network::openvswitch' do end end end + + describe 'create ovs data network bridge' do + let(:cmd) { 'ovs-vsctl add-br br-eth1 -- add-port br-eth1 eth1' } + + it 'does not add data network bridge if it already exists' do + node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = 'br-eth1:eth1' + stub_command(/ovs-vsctl br-exists br-eth1/).and_return(true) + stub_command(/ip link show eth1/).and_return(true) + expect(chef_run).not_to run_execute(cmd) + end + + it 'does not add data network bridge if the physical interface does not exist' do + node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = 'br-eth1:eth1' + stub_command(/ovs-vsctl br-exists br-eth1/).and_return(false) + stub_command(/ip link show eth1/).and_return(false) + expect(chef_run).not_to run_execute(cmd) + end + + it 'adds data network bridge if it does not yet exist and physical interface exists' do + node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = 'br-eth1:eth1' + stub_command(/ovs-vsctl br-exists br-eth1/).and_return(false) + stub_command(/ip link show eth1/).and_return(true) + expect(chef_run).to run_execute(cmd) + end + + it 'does not add data network bridge if nil specified for bridge mapping' do + node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = nil + stub_command(/ovs-vsctl br-exists br-eth1/).and_return(false) + stub_command(/ip link show eth1/).and_return(true) + expect(chef_run).not_to run_execute(cmd) + end + + it 'does not add data network bridge if emtpy string specified for bridge mapping' do + node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = '' + stub_command(/ovs-vsctl br-exists br-eth1/).and_return(false) + stub_command(/ip link show eth1/).and_return(true) + expect(chef_run).not_to run_execute(cmd) + end + end end end