2 # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # Unit tests for neutron::plugins::ml2 class
23 describe 'neutron::plugins::ml2' do
27 rabbit_password => 'passw0rd',
28 core_plugin => 'neutron.plugins.ml2.plugin.Ml2Plugin' }"
31 let :default_params do
32 { :type_drivers => ['local', 'flat', 'vlan', 'gre', 'vxlan'],
33 :tenant_network_types => ['local', 'flat', 'vlan', 'gre', 'vxlan'],
34 :mechanism_drivers => ['openvswitch', 'linuxbridge'],
35 :flat_networks => ['*'],
36 :network_vlan_ranges => ['10:50'],
37 :tunnel_id_ranges => ['20:100'],
38 :vxlan_group => '224.0.0.1',
39 :vni_ranges => ['10:100'],
40 :package_ensure => 'present' }
47 shared_examples_for 'neutron plugin ml2' do
49 default_params.merge(params)
52 it { should contain_class('neutron::params') }
54 it 'configures neutron.conf' do
55 should contain_neutron_config('DEFAULT/core_plugin').with_value('neutron.plugins.ml2.plugin.Ml2Plugin')
58 it 'configures ml2_conf.ini' do
59 should contain_neutron_plugin_ml2('ml2/type_drivers').with_value(p[:type_drivers].join(','))
60 should contain_neutron_plugin_ml2('ml2/tenant_network_types').with_value(p[:tenant_network_types].join(','))
61 should contain_neutron_plugin_ml2('ml2/mechanism_drivers').with_value(p[:mechanism_drivers].join(','))
64 it 'creates plugin symbolic link' do
65 should contain_file('/etc/neutron/plugin.ini').with(
67 :target => '/etc/neutron/plugins/ml2/ml2_conf.ini'
71 it 'installs ml2 package (if any)' do
72 if platform_params.has_key?(:ml2_server_package)
73 should contain_package('neutron-plugin-ml2').with(
74 :name => platform_params[:ml2_server_package],
75 :ensure => p[:package_ensure]
77 should contain_package('neutron-plugin-ml2').with_before(/Neutron_plugin_ml2\[.+\]/)
81 context 'configure ml2 with bad driver value' do
83 params.merge!(:type_drivers => ['foobar'])
85 it 'fails to configure ml2 because foobar is not a valid driver' do
86 expect { subject }.to raise_error(Puppet::Error, /type_driver unknown./)
90 context 'when using flat driver' do
92 params.merge!(:flat_networks => ['eth1', 'eth2'])
94 it 'configures flat_networks' do
95 should contain_neutron_plugin_ml2('ml2_type_flat/flat_networks').with_value(p[:flat_networks].join(','))
99 context 'when using gre driver with valid values' do
101 params.merge!(:tunnel_id_ranges => ['0:20', '40:60'])
103 it 'configures gre_networks with valid ranges' do
104 should contain_neutron_plugin_ml2('ml2_type_gre/tunnel_id_ranges').with_value(p[:tunnel_id_ranges].join(','))
108 context 'when using gre driver with invalid values' do
110 params.merge!(:tunnel_id_ranges => ['0:20', '40:100000000'])
112 it 'fails to configure gre_networks because of too big range' do
113 expect { subject }.to raise_error(Puppet::Error, /tunnel id ranges are to large./)
117 context 'when using vlan driver with valid values' do
119 params.merge!(:network_vlan_ranges => ['1:20', '400:4094'])
121 it 'configures vlan_networks with 1:20 and 400:4094 VLAN ranges' do
122 should contain_neutron_plugin_ml2('ml2_type_vlan/network_vlan_ranges').with_value(p[:network_vlan_ranges].join(','))
126 context 'when using vlan driver with invalid vlan id' do
128 params.merge!(:network_vlan_ranges => ['1:20', '400:4099'])
130 it 'fails to configure vlan_networks because of 400:4099 VLAN range' do
131 expect { subject }.to raise_error(Puppet::Error, /vlan id are invalid./)
135 context 'when using vlan driver with invalid vlan range' do
137 params.merge!(:network_vlan_ranges => ['2938:1'])
139 it 'fails to configure network_vlan_ranges with 2938:1 range' do
140 expect { subject }.to raise_error(Puppet::Error, /vlan ranges are invalid./)
144 context 'when using vxlan driver with valid values' do
146 params.merge!(:vni_ranges => ['40:300', '500:1000'], :vxlan_group => '224.1.1.1')
148 it 'configures vxlan_networks with 224.1.1.1 vxlan group' do
149 should contain_neutron_plugin_ml2('ml2_type_vxlan/vni_ranges').with_value(p[:vni_ranges].join(','))
150 should contain_neutron_plugin_ml2('ml2_type_vxlan/vxlan_group').with_value(p[:vxlan_group])
154 context 'when using vxlan driver with invalid vxlan group' do
156 params.merge!(:vxlan_group => '192.1.1.1')
158 it 'fails to configure vxlan_group with 192.1.1.1 vxlan group' do
159 expect { subject }.to raise_error(Puppet::Error, /is not valid for vxlan_group./)
163 context 'when using vxlan driver with invalid vni_range' do
165 params.merge!(:vni_ranges => ['2938:1'])
167 it 'fails to configure vni_ranges with 2938:1 range' do
168 expect { subject }.to raise_error(Puppet::Error, /vni ranges are invalid./)
172 context 'when overriding package ensure state' do
174 params.merge!(:package_ensure => 'latest')
176 it 'overrides package ensure state (if possible)' do
177 if platform_params.has_key?(:ml2_server_package)
178 should contain_package('neutron-plugin-ml2').with(
179 :name => platform_params[:ml2_server_package],
180 :ensure => params[:package_ensure]
186 context 'when running sriov mechanism driver' do
189 :mechanism_drivers => ['openvswitch', 'sriovnicswitch'],
190 :sriov_agent_required => true,
193 it 'configures sriov mechanism driver with agent_enabled' do
194 should contain_neutron_plugin_ml2('ml2_sriov/supported_pci_vendor_dev').with_value(['15b3:1004,8086:10ca'])
195 should contain_neutron_plugin_ml2('ml2_sriov/agent_required').with_value('true')
199 context 'on Ubuntu operating systems' do
201 facts.merge!({:operatingsystem => 'Ubuntu'})
204 it 'configures /etc/default/neutron-server' do
205 should contain_file_line('/etc/default/neutron-server:NEUTRON_PLUGIN_CONFIG').with(
206 :path => '/etc/default/neutron-server',
207 :match => '^NEUTRON_PLUGIN_CONFIG=(.*)$',
208 :line => 'NEUTRON_PLUGIN_CONFIG=/etc/neutron/plugin.ini',
209 :require => ['File[/etc/neutron/plugin.ini]']
215 context 'on Debian platforms' do
217 { :osfamily => 'Debian' }
220 let :platform_params do
224 context 'on Ubuntu operating systems' do
226 facts.merge!({:operatingsystem => 'Ubuntu'})
227 platform_params.merge!(:ml2_server_package => 'neutron-plugin-ml2')
230 it_configures 'neutron plugin ml2'
233 context 'on non-Ubuntu operating systems' do
235 facts.merge!({:operatingsystem => 'Debian'})
238 it_configures 'neutron plugin ml2'
242 context 'on RedHat platforms' do
244 { :osfamily => 'RedHat' }
247 let :platform_params do
248 { :ml2_server_package => 'openstack-neutron-ml2' }
251 it_configures 'neutron plugin ml2'