removed bridge creation from recipes and splittet recipes

* removed the creation of ovs bridges (except br-int) from all recipes,
  since this can not be done in a sufficient generic way or only with a lot of
  case switches to cope with all possible network setups
* added an example recipe to create all default ovs bridges from the
  networking guide for legacy ovs setups (we should also create one for dvr later)
* splittet recipe ml2_openvswitch into seperate recipes for ml2_openvswitch config,
  openvswitch_agent and openvswitch to allow bridge creation from wrapper recipe inbetween
  and seperate configs from package installation

Change-Id: I6383575862ba110b3f3b5cba227288dc026fce77
This commit is contained in:
Jan Klare 2016-02-25 15:03:48 +01:00
parent e30222057e
commit d518462595
17 changed files with 377 additions and 410 deletions

View File

@ -1,15 +1,16 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-02-04 14:25:45 +0100 using RuboCop version 0.35.1.
# on 2016-02-19 12:46:00 +0100 using RuboCop version 0.34.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 8
# Offense count: 9
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/ClassAndModuleChildren:
Exclude:
- 'recipes/_bridge_config_example.rb'
- 'recipes/client.rb'
- 'recipes/default.rb'
- 'recipes/identity_registration.rb'

View File

@ -185,7 +185,6 @@ default['openstack']['network_fwaas']['enabled'] = false
# default['openstack']['network']['fwaas']['driver'] = 'neutron_fwaas.services.firewall.drivers.linux.iptables_fwaas.IptablesFwaasDriver'
# Custom the fwaas config file path
# default['openstack']['network']['fwaas']['config_file'] = '/etc/neutron/fwaas_driver.ini'
default['openstack']['network']['openvswitch']['bridge_mapping_interface'] = nil
# ============================= platform-specific settings ===========
default['openstack']['network']['platform'].tap do |platform|
platform['user'] = 'neutron'

View File

@ -0,0 +1,119 @@
# Encoding: utf-8
#
# Cookbook Name:: openstack-network
# Recipe:: _bridge_config_example
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This recipe is intended as an example of just one possible bridge
# configuration for ml2 and should not be used as is in production. The
# openstack-network cookbook tries to provide all the basic features to deploy
# the neutron services, but can not include all possible network and bridge
# configurations out there. To use the openstack-network cookbook in production,
# please create a wrapper to configure your network interfaces and adapt the
# configs accordingly. You should find fitting examples given below.
# Make Openstack object available in Chef::Recipe
class ::Chef::Recipe
include ::Openstack
end
# Helper for creating dummy interfaces for ovs bridges on jenkins test nodes and
# in testing vagrant boxes.
# The created interfaces do not work for real network traffic, but are needed to
# test the bridge creation and usage in the recipes.
# This needs to be done during compile time to ensure that the address_for
# method used lateron works
execute 'create eth-ext dummy interface' do
command 'ip link add eth-ext type dummy;'\
'ip link set dev eth-ext up'
not_if 'ip link show | grep eth-ext'
end.run_action(:run)
execute 'create eth-vlan dummy interface' do
command 'ip link add eth-vlan type dummy;'\
'ip link set dev eth-vlan up'
not_if 'ip link show | grep eth-vlan'
end.run_action(:run)
execute 'create eth-tun dummy interface' do
command 'ip link add eth-tun type dummy;'\
'ip link set dev eth-tun up;'\
'ip addr add 10.0.0.201/24 dev eth-tun'
not_if 'ip link show | grep eth-tun'
end.run_action(:run)
# reload node attributes to get configuration for newly created dummy interfaces
ohai('reload').run_action(:reload)
# set all the needed attributes according to the dummy interfaces added above
# vlan bridge
node.default['openstack']['network']['vlan_network_bridge_interface'] = 'eth-vlan'
node.default['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['bridge_mappings'] = 'vlan:br-vlan,external:br-ex'
# external bridge
node.default['openstack']['network_l3']['external_network_bridge_interface'] = 'eth-ext'
# tunnel bridge
node.default['openstack']['network']['tun_network_bridge_interface'] = 'eth-tun'
node.default['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['tunnel_bridge'] = 'br-tun'
node.default['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['local_ip'] =
address_for(node.default['openstack']['network']['tun_network_bridge_interface'])
node.default['openstack']['network']['plugins']['openvswitch']['conf']
.[]('AGENT')['tunnel_types'] = 'gre,vxlan'
# ovs security groups
node.default['openstack']['network']['plugins']['openvswitch']['conf']
.[]('SECURITYGROUP')['firewall_driver'] =
'neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver'
# define variables for bridge definitions below
ex_bridge_iface = node['openstack']['network_l3']['external_network_bridge_interface']
vlan_bridge_iface = node['openstack']['network']['vlan_network_bridge_interface']
tun_bridge = node['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['tunnel_bridge']
# get the bridge names from the ovs bridge_mappings
mappings = node['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['bridge_mappings'].split(',')
vlan_bridge = mappings.find { |mapping| mapping.split(':').first == 'vlan' }.split(':').last
ex_bridge = mappings.find { |mapping| mapping.split(':').first == 'external' }.split(':').last
execute 'create external network bridge' do
command "ovs-vsctl --may-exist add-br #{ex_bridge}"
action :run
end
execute 'create external network bridge port' do
command "ovs-vsctl --may-exist add-port #{ex_bridge} #{ex_bridge_iface}"
action :run
end
execute 'create vlan network bridge' do
command "ovs-vsctl --may-exist add-br #{vlan_bridge}"
action :run
end
execute 'create vlan network bridge port' do
command "ovs-vsctl --may-exist add-port #{vlan_bridge} #{vlan_bridge_iface}"
action :run
end
execute 'create tunnel network bridge' do
command "ovs-vsctl --may-exist add-br #{tun_bridge}"
action :run
end

View File

@ -51,23 +51,6 @@ template node['openstack']['network_l3']['config_file'] do
end
# See http://docs.openstack.org/admin-guide-cloud/content/section_adv_cfg_l3_agent.html
if node['openstack']['network_l3']['conf']['DEFAULT']['interface_driver'] ==
'neutron.agent.linux.interface.OVSInterfaceDriver'
ext_bridge = node['openstack']['network_l3']['conf']['DEFAULT']['external_network_bridge']
ext_bridge_iface = node['openstack']['network_l3']['external_network_bridge_interface']
if ext_bridge && ext_bridge_iface
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 --may-exist add-port #{ext_bridge} #{ext_bridge_iface}"
action :run
only_if "ip link show #{ext_bridge_iface}"
end
end
end
service 'neutron-l3-agent' do
service_name platform_options['neutron_l3_agent_service']

View File

@ -25,9 +25,10 @@ class ::Chef::Recipe
include ::Openstack
end
include_recipe 'openstack-network::ml2_core_plugin'
node.default['openstack']['network']['plugins']['ml2']['conf']['ml2']['mechanism_drivers'] = 'openvswitch'
platform_options = node['openstack']['network']['platform']
node.default['openstack']['network']['plugins']['openvswitch'].tap do |ovs|
case node['platform_family']
when 'fedora', 'rhel'
@ -42,77 +43,4 @@ node.default['openstack']['network']['plugins']['openvswitch'].tap do |ovs|
'openvswitch_agent.ini'
end
ovs['conf']['DEFAULT']['integration_bridge'] = 'br-int'
ovs['conf']['OVS']['tunnel_bridge'] = 'br-tun'
end
platform_options['neutron_openvswitch_packages'].each do |pkg|
package pkg do
options platform_options['package_overrides']
action :upgrade
end
end
plugin_file_path = File.join(
node['openstack']['network']['plugins']['openvswitch']['path'],
node['openstack']['network']['plugins']['openvswitch']['filename']
)
platform_options['neutron_openvswitch_agent_packages'].each do |pkg|
package pkg do
action :upgrade
options platform_options['package_overrides']
end
end
int_bridge =
node['openstack']['network']['plugins']['openvswitch']['conf']
.[]('DEFAULT')['integration_bridge']
tun_bridge =
node['openstack']['network']['plugins']['openvswitch']['conf']
.[]('OVS')['tunnel_bridge']
execute 'create internal network bridge' do
ignore_failure true
command "ovs-vsctl add-br #{int_bridge}"
action :run
not_if "ovs-vsctl br-exists #{int_bridge}"
end
include_recipe 'openstack-network::plugin_config'
service 'neutron-openvswitch-switch' do
service_name platform_options['neutron_openvswitch_service']
supports status: true, restart: true
action [:enable, :start]
subscribes :restart, "template[#{plugin_file_path}]"
end
service 'neutron-plugin-openvswitch-agent' do
service_name platform_options['neutron_openvswitch_agent_service']
supports status: true, restart: true
action [:enable, :start]
subscribes :restart, [
'template[/etc/neutron/neutron.conf]',
"template[#{plugin_file_path}]",
'execute[create internal network bridge]',
'execute[create tunnel network bridge]',
'execute[create data network bridge]'
]
end
execute 'create tunnel network bridge' do
ignore_failure true
command "ovs-vsctl add-br #{tun_bridge}"
action :run
not_if "ovs-vsctl br-exists #{tun_bridge}"
end
if node['openstack']['network']['openvswitch']['bridge_mapping_interface']
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}"
end
end

39
recipes/openvswitch.rb Normal file
View File

@ -0,0 +1,39 @@
# Encoding: utf-8
#
# Cookbook Name:: openstack-network
# Recipe:: opensvswitch
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe 'openstack-network::ml2_openvswitch'
plugin_file_path = File.join(
node['openstack']['network']['plugins']['openvswitch']['path'],
node['openstack']['network']['plugins']['openvswitch']['filename']
)
platform_options = node['openstack']['network']['platform']
platform_options['neutron_openvswitch_packages'].each do |pkg|
package pkg do
options platform_options['package_overrides']
action :upgrade
end
end
service 'neutron-openvswitch-switch' do
service_name platform_options['neutron_openvswitch_service']
supports status: true, restart: true
action [:enable, :start]
subscribes :restart, "template[#{plugin_file_path}]"
end

View File

@ -0,0 +1,50 @@
# Encoding: utf-8
#
# Cookbook Name:: openstack-network
# Recipe:: openvswitch_agent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe 'openstack-network::ml2_openvswitch'
plugin_file_path = File.join(
node['openstack']['network']['plugins']['openvswitch']['path'],
node['openstack']['network']['plugins']['openvswitch']['filename']
)
platform_options = node['openstack']['network']['platform']
platform_options['neutron_openvswitch_agent_packages'].each do |pkg|
package pkg do
action :upgrade
options platform_options['package_overrides']
end
end
int_bridge =
node['openstack']['network']['plugins']['openvswitch']['conf']
.[]('DEFAULT')['integration_bridge']
execute 'create integration network bridge' do
command "ovs-vsctl --may-exist add-br #{int_bridge}"
action :run
end
service 'neutron-plugin-openvswitch-agent' do
service_name platform_options['neutron_openvswitch_agent_service']
supports status: true, restart: true
action [:enable, :start]
subscribes :restart, [
'template[/etc/neutron/neutron.conf]',
"template[#{plugin_file_path}]"
]
end

View File

@ -0,0 +1,61 @@
# Encoding: utf-8
require_relative 'spec_helper'
describe 'openstack-network::_bridge_config_example' do
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)
end
before do
%w(eth-ext eth-vlan eth-tun).each do |eth|
stub_command("ip link show | grep #{eth}")
end
allow_any_instance_of(Chef::Recipe).to receive(:address_for)
.with('eth-tun')
.and_return('1.2.3.4')
end
describe 'create ovs external network bridge and port' do
let(:cmd_br) { 'ovs-vsctl --may-exist add-br br-ex' }
let(:cmd_port) { 'ovs-vsctl --may-exist add-port br-ex eth-ext' }
let(:name) { 'create external network bridge' }
it 'adds external network bridge' do
expect(chef_run).to run_execute(name)
.with(command: cmd_br)
end
it 'adds external network bridge port' do
expect(chef_run).to run_execute("#{name} port")
.with(command: cmd_port)
end
end
describe 'create vlan network bridge and port' do
let(:cmd_br) { 'ovs-vsctl --may-exist add-br br-vlan' }
let(:cmd_port) { 'ovs-vsctl --may-exist add-port br-vlan eth-vlan' }
let(:name) { 'create vlan network bridge' }
it 'adds vlan network bridge' do
expect(chef_run).to run_execute(name)
.with(command: cmd_br)
end
it 'adds vlan network bridge port' do
expect(chef_run).to run_execute("#{name} port")
.with(command: cmd_port)
end
end
describe 'create tunnel network bridge' do
let(:cmd_br) { 'ovs-vsctl --may-exist add-br br-tun' }
let(:name) { 'create tunnel network bridge' }
it 'adds tunnel network bridge' do
expect(chef_run).to run_execute(name)
.with(command: cmd_br)
end
end
end
end

View File

@ -68,7 +68,7 @@ describe 'openstack-network' do
end
end
context 'oslo_messaging'do
context 'oslo_messaging' do
let(:file) { chef_run.template('/etc/neutron/neutron.conf') }
describe 'has rabbit as default service' do
before do

View File

@ -6,9 +6,7 @@ describe 'openstack-network::l3_agent' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['network_l3']['external_network_bridge_interface'] = 'eth1'
runner.converge(described_recipe)
end
describe 'recipe' do
@ -55,68 +53,5 @@ describe 'openstack-network::l3_agent' do
end
end
end
describe 'create ovs bridges' do
let(:cmd) { 'ovs-vsctl add-br br-ex' }
let(:create_ex_br_name) { 'create external network bridge' }
let(:enable_ex_br_int_name) { 'enable external_network_bridge_interface' }
let(:iplink) { 'ip link set eth1 up && ovs-vsctl --may-exist add-port br-ex eth1' }
include_context 'neutron-stubs'
context 'interface driver unset' do
before do
node.set['openstack']['network_l3']['conf']['DEFAULT']['interface_driver'] = nil
end
end
context 'interface driver set' do
before do
node.set['openstack']['network_l3']['conf']['DEFAULT']['interface_driver'] =
'neutron.agent.linux.interface.OVSInterfaceDriver'
end
context 'ext_bridge and ext_bridge_iface unset' do
before do
node.set['openstack']['network_l3']['conf']['DEFAULT']['external_network_bridge'] = nil
node.set['openstack']['network_l3']['external_network_bridge_interface'] = nil
end
end
context 'ext_bridge and ext_bridge_iface are set' do
before do
node.set['openstack']['network_l3']['conf']['DEFAULT']['external_network_bridge'] = 'br-ex'
node.set['openstack']['network_l3']['external_network_bridge_interface'] = 'eth1'
stub_command(/ovs-vsctl add-br br-ex/)
end
context 'ext_bridge exists' do
before do
stub_command(/ovs-vsctl br-exists br-ex/).and_return(true)
end
it 'does not add ext_bridge' do
expect(chef_run).not_to run_execute(create_ex_br_name)
end
end
context 'ext_bridge doesnt exists' do
before do
stub_command(/ovs-vsctl br-exists br-ex/).and_return(false)
end
it 'does add ext_bridge' do
expect(chef_run).to run_execute(create_ex_br_name)
end
end
context 'ext_bridge_iface exists' do
before do
stub_command(/ip link show eth1/).and_return(true)
end
it 'does enable ext_bridge_iface' do
expect(chef_run).to run_execute(enable_ex_br_int_name)
end
end
context 'ext_bridge_iface doesnt exists' do
before do
stub_command(/ip link show eth1/).and_return(false)
end
it 'does not enable ext_bridge_iface' do
expect(chef_run).not_to run_execute(enable_ex_br_int_name)
end
end
end
end
end
end
end

View File

@ -32,7 +32,6 @@ describe 'openstack-network::ml2_linuxbridge' do
it do
expect(chef_run).to include_recipe('openstack-network::plugin_config')
end
it_behaves_like 'plugin_config builder', 'linuxbridge'
it do
%w(neutron-plugin-linuxbridge neutron-plugin-linuxbridge-agent).each do |pkg|

View File

@ -1,27 +0,0 @@
# Encoding: utf-8
require_relative 'spec_helper'
describe 'openstack-network::ml2_openvswitch' do
describe 'redhat' do
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['network']['core_plugin'] = 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2'
runner.converge(described_recipe)
end
before do
node.set['openstack']['network']['plugins']['openvswitch']['path'] = '/etc/neutron/plugins/openvswitch'
node.set['openstack']['network']['plugins']['openvswitch']['filename'] = 'openvswitch_plugin.ini'
end
include_context 'neutron-stubs'
it 'upgrades neutron ml2_ovs packages' do
%w(openstack-neutron-openvswitch openvswitch).each do |pkg|
expect(chef_run).to upgrade_package(pkg)
end
end
it_behaves_like 'plugin_config builder', 'openvswitch'
end
end

View File

@ -1,189 +0,0 @@
# upgrade platform options
# upgrade platform options
# int bridge cmmd
# include recipe plugin_config
# service restart
# service restart
# execute cmd
# execute cmd
# Encoding: utf-8
require_relative 'spec_helper'
describe 'openstack-network::ml2_openvswitch' do
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:kmod_command) { '/usr/share/openvswitch/scripts/ovs-ctl force-reload-kmod' }
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['endpoints']['network-openvswitch']['bind_interface'] = 'eth0'
node.set['openstack']['network']['openvswitch']['integration_bridge'] = 'br-int'
node.set['openstack']['network']['core_plugin'] = 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2'
node.automatic_attrs['kernel']['release'] = '1.2.3'
runner.converge(described_recipe)
end
describe 'recipe' do
include_context 'neutron-stubs'
before do
stub_command(/ip link show/)
stub_command('ovs-vsctl add-br br-eth1 -- add-port br-eth1 eth1')
stub_command('ovs-vsctl add-br br-int')
stub_command('ovs-vsctl add-br br-tun')
node.set['openstack']['network']['plugins']['ml2']['path'] = '/etc/neutron/plugins/ml2'
node.set['openstack']['network']['plugins']['ml2']['filename'] = 'openvswitch_agent.ini'
end
it 'upgrades openvswitch switch' do
expect(chef_run).to upgrade_package 'openvswitch-switch'
end
it 'upgrades openvswitch datapath dkms' do
expect(chef_run).to upgrade_package 'openvswitch-datapath-dkms'
end
it 'upgrades linux bridge utils' do
expect(chef_run).to upgrade_package 'bridge-utils'
end
it 'sets the openvswitch service to start on boot' do
expect(chef_run).to enable_service 'openvswitch-switch'
end
it 'start the openvswitch service' do
expect(chef_run).to start_service 'openvswitch-switch'
end
it 'upgrades openvswitch agent' do
expect(chef_run).to upgrade_package 'neutron-plugin-openvswitch-agent'
end
it 'sets the openvswitch service to start on boot' do
expect(chef_run).to enable_service 'neutron-plugin-openvswitch-agent'
end
it_behaves_like 'plugin_config builder', 'ml2'
it 'allows overriding the service names' do
node.set['openstack']['network']['platform']['neutron_openvswitch_service'] = 'my-ovs-server'
node.set['openstack']['network']['platform']['neutron_openvswitch_agent_service'] = 'my-ovs-agent'
%w(my-ovs-server my-ovs-agent).each do |service|
expect(chef_run).to enable_service service
end
end
it 'allows overriding package options' do
node.set['openstack']['network']['platform']['package_overrides'] = '--my-override1 --my-override2'
%w(openvswitch-switch openvswitch-datapath-dkms neutron-plugin-openvswitch neutron-plugin-openvswitch-agent).each do |pkg|
expect(chef_run).to upgrade_package(pkg).with(options: '--my-override1 --my-override2')
end
end
it 'allows overriding package names' do
node.set['openstack']['network']['platform']['neutron_openvswitch_packages'] = ['my-openvswitch', 'my-other-openvswitch']
node.set['openstack']['network']['platform']['neutron_openvswitch_agent_packages'] = ['my-openvswitch-agent', 'my-other-openvswitch-agent']
%w(my-openvswitch my-other-openvswitch my-openvswitch-agent my-other-openvswitch-agent).each do |pkg|
expect(chef_run).to upgrade_package(pkg)
end
end
it 'does not create execute resource when openvswitch-datasource-dkms package is not being installed' do
node.set['openstack']['network']['platform']['neutron_openvswitch_packages'] = ['my-openvswitch', 'my-other-openvswitch']
chef_run.converge 'openstack-network::ml2_openvswitch'
resource = chef_run.find_resource('execute', kmod_command)
expect(resource).to eq(nil)
end
end
describe 'create ovs data network bridge' do
let(:cmd) { 'ovs-vsctl add-br br-eth1 -- add-port br-eth1 eth1' }
let(:name) { 'create data network bridge' }
before do
stub_command('ovs-vsctl add-br br-int')
stub_command('ovs-vsctl add-br br-tun')
end
include_context 'neutron-stubs'
context 'bridge mapping interface unset' do
before do
node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = nil
end
end
context 'bridge mapping interface set' do
before do
node.set['openstack']['network']['openvswitch']['bridge_mapping_interface'] = 'br-eth1:eth1'
end
context 'ext_bridge exists' do
before do
stub_command(/ovs-vsctl br-exists br-eth1/).and_return(true)
end
it 'does not add data network bridge' do
expect(chef_run).not_to run_execute(name)
end
end
context 'ext_bridge doesnt exist' do
before do
stub_command(/ovs-vsctl br-exists br-eth1/).and_return(false)
end
context 'ext_bridge_iface exists' do
before do
stub_command(/ip link show eth1/).and_return(true)
end
it 'adds data network bridge' do
expect(chef_run).to run_execute(name)
end
end
context 'ext_bridge_iface doesnt exists' do
before do
stub_command(/ip link show eth1/).and_return(false)
end
it 'does not add data network bridge' do
expect(chef_run).not_to run_execute(name)
end
end
end
end
describe 'create ovs internal network bridge' do
let(:cmd) { 'ovs-vsctl add-br br-int' }
let(:name) { 'create internal network bridge' }
context 'int_bridge exists' do
before do
stub_command('ovs-vsctl br-exists br-int').and_return(false)
end
it 'add internal network bridge' do
expect(chef_run).to run_execute(name)
end
end
context 'int_bridge doesnt exists' do
before do
stub_command('ovs-vsctl br-exists br-int').and_return(true)
end
it 'does not add internal network bridge' do
expect(chef_run).not_to run_execute(name)
end
end
end
describe 'create ovs tunnel network bridge' do
let(:cmd) { 'ovs-vsctl add-br br-tun' }
let(:name) { 'create tunnel network bridge' }
context 'tun_bridge exists' do
before do
stub_command('ovs-vsctl br-exists br-tun').and_return(false)
end
it 'add tunnel network bridge' do
expect(chef_run).to run_execute(name)
end
end
context 'tun_bridge doesnt exists' do
before do
stub_command('ovs-vsctl br-exists br-tun').and_return(true)
end
it 'does not add tunnel network bridge' do
expect(chef_run).not_to run_execute(name)
end
end
end
end
end
end

View File

@ -0,0 +1,37 @@
# Encoding: utf-8
require_relative 'spec_helper'
describe 'openstack-network::openvswitch_agent' do
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['openstack']['network']['openvswitch']['integration_bridge'] = 'br-int'
runner.converge(described_recipe)
end
before do
stub_command('ovs-vsctl --may-exist add-br br-int')
end
it 'upgrades openvswitch agent' do
expect(chef_run).to upgrade_package 'neutron-plugin-openvswitch-agent'
end
describe 'create integration network bridget' do
let(:cmd_br) { 'ovs-vsctl --may-exist add-br br-int' }
let(:name) { 'create integration network bridge' }
it 'adds integration network bridge' do
expect(chef_run).to run_execute(name)
.with(command: cmd_br)
end
end
it 'sets the openvswitch_agent service to start on boot' do
expect(chef_run).to enable_service 'neutron-plugin-openvswitch-agent'
end
it 'starts the openvswitch_agent service' do
expect(chef_run).to start_service 'neutron-plugin-openvswitch-agent'
end
end
end

32
spec/openvswitch_spec.rb Normal file
View File

@ -0,0 +1,32 @@
# Encoding: utf-8
require_relative 'spec_helper'
describe 'openstack-network::openvswitch' do
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)
end
it 'upgrades openvswitch switch' do
expect(chef_run).to upgrade_package 'openvswitch-switch'
end
it 'upgrades openvswitch datapath dkms' do
expect(chef_run).to upgrade_package 'openvswitch-datapath-dkms'
end
it 'upgrades linux bridge utils' do
expect(chef_run).to upgrade_package 'bridge-utils'
end
it 'sets the openvswitch service to start on boot' do
expect(chef_run).to enable_service 'openvswitch-switch'
end
it 'start the openvswitch service' do
expect(chef_run).to start_service 'openvswitch-switch'
end
end
end

View File

@ -6,10 +6,41 @@ describe 'openstack-network::plugin_config' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['openstack']['compute']['network']['service_type'] = 'neutron'
node.set['openstack']['network']['plugins']['ml2'].tap do |ml2|
ml2['path'] = '/etc/neutron/more_plugins'
ml2['filename'] = 'ml2_conf.ini'
ml2['conf'].tap do |conf|
conf['section']['key'] = 'value'
end
end
node.set['openstack']['network']['plugins']['openvswitch'].tap do |ovs|
ovs['path'] = '/etc/neutron/plugins/'
ovs['filename'] = 'openvswitch_conf.ini'
ovs['conf'].tap do |conf|
conf['section']['key'] = 'value'
end
end
runner.converge(described_recipe)
end
include_context 'neutron-stubs'
%w(/etc/neutron/more_plugins /etc/neutron/plugins/).each do |dir|
it do
expect(chef_run).to create_directory(dir)
.with(
recursive: true,
owner: 'neutron',
group: 'neutron',
mode: 00700
)
end
%w(ml2_conf.ini openvswitch_conf.ini).each do |conf|
let(:file) { chef_run.template(File.join(dir, conf)) }
it do
expect(chef_run).to render_config_file(file.name)
.with_section_content('section', 'key = value')
end
end
end
end
end

View File

@ -45,18 +45,6 @@ shared_context 'neutron-stubs' do
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('service', 'openstack-compute')
.and_return('nova-pass')
# allow_any_instance_of(Chef::Resource::RubyBlock).to receive(:openstack_command_env)
# .with('admin', 'admin')
# .and_return({})
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)
stub_command('ovs-vsctl br-exists br-tun').and_return(false)
# stub_command('ovs-vsctl add-br br-ex').and_return(false)
stub_command('ip link show eth1').and_return(false)
stub_command('ovs-vsctl add-br br-eth1 -- add-port br-eth1 eth1').and_return(true)
stub_command('ovs-vsctl br-exists ').and_return(false)
stub_command('ovs-vsctl br-exists br-ex').and_return(false)
stub_command('ovs-vsctl br-exists eth1').and_return(false)
end
shared_examples 'custom template banner displayer' do
it 'shows the custom banner' do
@ -84,23 +72,4 @@ shared_context 'neutron-stubs' do
end
end
end
shared_examples 'plugin_config builder' do |plugin|
it do
expect(chef_run).to create_directory(node['openstack']['network']['plugins'][plugin]['path']).with(
recursive: true,
owner: 'neutron',
group: 'neutron',
mode: 00700
)
end
let(:file) { chef_run.template(File.join(node['openstack']['network']['plugins'][plugin]['path'], node['openstack']['network']['plugins'][plugin]['filename'])) }
it do
expect(chef_run).to create_template(file.name).with(
user: 'neutron',
group: 'neutron',
mode: 00644
)
end
end
end