memcached (openstack) is no longer in use
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / classes / neutron_plugins_ml2_spec.rb
1 #
2 # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #
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
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
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
16 # under the License.
17 #
18 # Unit tests for neutron::plugins::ml2 class
19 #
20
21 require 'spec_helper'
22
23 describe 'neutron::plugins::ml2' do
24
25   let :pre_condition do
26     "class { 'neutron':
27       rabbit_password => 'passw0rd',
28       core_plugin     => 'neutron.plugins.ml2.plugin.Ml2Plugin' }"
29   end
30
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' }
41   end
42
43   let :params do
44     {}
45   end
46
47   shared_examples_for 'neutron plugin ml2' do
48     let :p do
49       default_params.merge(params)
50     end
51
52     it { should contain_class('neutron::params') }
53
54     it 'configures neutron.conf' do
55         should contain_neutron_config('DEFAULT/core_plugin').with_value('neutron.plugins.ml2.plugin.Ml2Plugin')
56     end
57
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(','))
62     end
63
64     it 'creates plugin symbolic link' do
65       should contain_file('/etc/neutron/plugin.ini').with(
66         :ensure  => 'link',
67         :target  => '/etc/neutron/plugins/ml2/ml2_conf.ini'
68       )
69     end
70
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]
76         )
77         should contain_package('neutron-plugin-ml2').with_before(/Neutron_plugin_ml2\[.+\]/)
78       end
79     end
80
81     context 'configure ml2 with bad driver value' do
82       before :each do
83        params.merge!(:type_drivers => ['foobar'])
84       end
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./)
87       end
88     end
89
90     context 'when using flat driver' do
91       before :each do
92         params.merge!(:flat_networks => ['eth1', 'eth2'])
93       end
94       it 'configures flat_networks' do
95         should contain_neutron_plugin_ml2('ml2_type_flat/flat_networks').with_value(p[:flat_networks].join(','))
96       end
97     end
98
99     context 'when using gre driver with valid values' do
100       before :each do
101         params.merge!(:tunnel_id_ranges => ['0:20', '40:60'])
102       end
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(','))
105       end
106     end
107
108     context 'when using gre driver with invalid values' do
109       before :each do
110        params.merge!(:tunnel_id_ranges => ['0:20', '40:100000000'])
111       end
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./)
114       end
115     end
116
117     context 'when using vlan driver with valid values' do
118       before :each do
119         params.merge!(:network_vlan_ranges => ['1:20', '400:4094'])
120       end
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(','))
123       end
124     end
125
126     context 'when using vlan driver with invalid vlan id' do
127       before :each do
128        params.merge!(:network_vlan_ranges => ['1:20', '400:4099'])
129       end
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./)
132       end
133     end
134
135     context 'when using vlan driver with invalid vlan range' do
136       before :each do
137         params.merge!(:network_vlan_ranges => ['2938:1'])
138       end
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./)
141       end
142     end
143
144     context 'when using vxlan driver with valid values' do
145       before :each do
146         params.merge!(:vni_ranges => ['40:300', '500:1000'], :vxlan_group => '224.1.1.1')
147       end
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])
151       end
152     end
153
154     context 'when using vxlan driver with invalid vxlan group' do
155       before :each do
156         params.merge!(:vxlan_group => '192.1.1.1')
157       end
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./)
160       end
161     end
162
163     context 'when using vxlan driver with invalid vni_range' do
164       before :each do
165         params.merge!(:vni_ranges => ['2938:1'])
166       end
167       it 'fails to configure vni_ranges with 2938:1 range' do
168         expect { subject }.to raise_error(Puppet::Error, /vni ranges are invalid./)
169       end
170     end
171
172     context 'when overriding package ensure state' do
173       before :each do
174         params.merge!(:package_ensure => 'latest')
175       end
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]
181           )
182         end
183       end
184     end
185
186     context 'when running sriov mechanism driver' do
187       before :each do
188         params.merge!(
189           :mechanism_drivers    => ['openvswitch', 'sriovnicswitch'],
190           :sriov_agent_required => true,
191         )
192       end
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')
196       end
197     end
198
199     context 'on Ubuntu operating systems' do
200       before do
201         facts.merge!({:operatingsystem => 'Ubuntu'})
202       end
203
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]']
210         )
211       end
212     end
213   end
214
215   context 'on Debian platforms' do
216     let :facts do
217       { :osfamily => 'Debian' }
218     end
219
220     let :platform_params do
221       {}
222     end
223
224     context 'on Ubuntu operating systems' do
225       before do
226         facts.merge!({:operatingsystem => 'Ubuntu'})
227         platform_params.merge!(:ml2_server_package => 'neutron-plugin-ml2')
228       end
229
230       it_configures 'neutron plugin ml2'
231     end
232
233     context 'on non-Ubuntu operating systems' do
234       before do
235         facts.merge!({:operatingsystem => 'Debian'})
236       end
237
238       it_configures 'neutron plugin ml2'
239     end
240   end
241
242   context 'on RedHat platforms' do
243     let :facts do
244       { :osfamily => 'RedHat' }
245     end
246
247     let :platform_params do
248       { :ml2_server_package => 'openstack-neutron-ml2' }
249     end
250
251     it_configures 'neutron plugin ml2'
252   end
253
254 end