4def5d90063fb7dda644abd5613258cbfaa2f1ec
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / classes / neutron_plugins_ovs_spec.rb
1 require 'spec_helper'
2
3 describe 'neutron::plugins::ovs' do
4
5   let :pre_condition do
6     "class { 'neutron': rabbit_password => 'passw0rd' }"
7   end
8
9   let :default_params do
10    {
11      :package_ensure       => 'present',
12      :sql_connection       => false,
13      :sql_max_retries      => false,
14      :sql_idle_timeout     => false,
15      :reconnect_interval   => false,
16      :tunnel_id_ranges     => '1:1000',
17      :network_vlan_ranges  => 'physnet1:1000:2000'
18    }
19   end
20
21   let :params do
22     { }
23   end
24
25   shared_examples_for 'neutron ovs plugin' do
26     before do
27       params.merge!(default_params) { |key, v1, v2| v1 }
28     end
29
30     let :params do
31       { :tenant_network_type => 'vlan' }
32     end
33
34     it 'should create plugin symbolic link' do
35       should contain_file('/etc/neutron/plugin.ini').with(
36         :ensure  => 'link',
37         :target  => '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini',
38         :require => 'Package[neutron-plugin-ovs]'
39       )
40     end
41
42     it 'should perform default configuration of' do
43       should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
44       should contain_package('neutron-plugin-ovs').with(
45         :name   => platform_params[:ovs_server_package],
46         :ensure => params[:package_ensure]
47       )
48       should_not contain_class('vswitch::ovs')
49     end
50
51     context 'with vlan mode' do
52       let :params do
53         { :tenant_network_type => 'vlan' }
54       end
55
56       it 'should perform vlan network configuration' do
57         should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
58         should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges])
59       end
60     end
61
62     context 'with gre tunneling' do
63       let :params do
64         { :tenant_network_type => 'gre', :tunnel_id_ranges => '1:1000'}
65       end
66
67       before do
68         params.delete(:network_vlan_ranges)
69       end
70
71       it 'should perform gre network configuration' do
72         should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
73         should contain_neutron_plugin_ovs('OVS/tunnel_id_ranges').with_value(params[:tunnel_id_ranges])
74         should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_ensure('absent')
75       end
76     end
77
78     context 'with gre tunneling and provider networks' do
79       let :params do
80         { :tenant_network_type => 'gre',
81           :network_vlan_ranges => 'physnet1:1000:2000',
82           :tunnel_id_ranges    => '1:1000'}
83       end
84
85       it 'should perform gre network configuration' do
86         should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges])
87         should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
88         should contain_neutron_plugin_ovs('OVS/tunnel_id_ranges').with_value(params[:tunnel_id_ranges])
89       end
90     end
91
92     context 'with vxlan tunneling' do
93       let :params do
94         { :tenant_network_type => 'vxlan',
95           :vxlan_udp_port      => '4789'}
96       end
97
98       before do
99         params.delete(:network_vlan_ranges)
100       end
101
102       it 'should perform vxlan network configuration' do
103         should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
104         should contain_neutron_plugin_ovs('OVS/vxlan_udp_port').with_value(params[:vxlan_udp_port])
105         should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_ensure('absent')
106       end
107     end
108
109     context 'with vxlan tunnelling using bad vxlan_udp_port' do
110       let :params do
111         { :tenant_network_type => 'vxlan',
112           :vxlan_udp_port      => '1',}
113       end
114
115       it 'should fail if invalid port is passed' do
116         expect { subject }.to raise_error(Puppet::Error, /vxlan udp port is invalid./)
117       end
118     end
119
120     context 'with vxlan tunnelling using bad tunnel_id_ranges' do
121       let :params do
122         { :tenant_network_type => 'vxlan',
123           :tunnel_id_ranges    => '100:9',}
124       end
125
126       it 'should fail if invalid id range is passed' do
127         expect { subject }.to raise_error(Puppet::Error, /tunnel id ranges are invalid./)
128       end
129     end
130
131     context 'with vxlan tunneling and provider networks using bad network_vlan_ranges' do
132       let :params do
133         { :tenant_network_type => 'vxlan',
134           :network_vlan_ranges => 'physnet1:200:1'}
135       end
136
137       it 'should fail if invalid vlan range is passed' do
138         expect { subject }.to raise_error(Puppet::Error, /network vlan ranges are invalid./)
139       end
140     end
141
142     context 'with vxlan tunneling using bad multiple network_vlan_ranges' do
143       let :params do
144         { :tenant_network_type => 'vxlan',
145           :network_vlan_ranges => ['physnet1:0:100', 'physnet2:1000:1']}
146       end
147
148       it 'should fail if invalid network vlan range is passed' do
149         expect { subject }.to raise_error(Puppet::Error, /network vlan ranges are invalid/)
150       end
151     end
152
153     context 'with vxlan tunneling and provider networks' do
154       let :params do
155         { :tenant_network_type => 'vxlan',
156           :network_vlan_ranges => 'physnet1:1000:2000'}
157       end
158
159       it 'should perform vxlan network configuration' do
160         should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges])
161         should contain_neutron_plugin_ovs('OVS/tenant_network_type').with_value(params[:tenant_network_type])
162       end
163     end
164
165     context 'with a flat network' do
166       let :params do
167         { :tenant_network_type => 'flat'}
168       end
169       it { should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges]) }
170     end
171
172     context 'with comma separated vlan ranges' do
173       let :params do
174         { :network_vlan_ranges => 'physint1:1000:2000,physext1:100:200' }
175       end
176       it { should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges]) }
177     end
178
179     context 'with vlan ranges in array' do
180       let :params do
181         { :network_vlan_ranges => ['physint1:1000:2000', 'physext1:100:200'] }
182       end
183       it { should contain_neutron_plugin_ovs('OVS/network_vlan_ranges').with_value(params[:network_vlan_ranges].join(',')) }
184     end
185   end
186
187   context 'on Debian platforms' do
188     let :facts do
189       { :osfamily => 'Debian' }
190     end
191
192     let :platform_params do
193       { :ovs_server_package => 'neutron-plugin-openvswitch' }
194     end
195
196     it_configures 'neutron ovs plugin'
197   end
198
199   context 'on RedHat platforms' do
200     let :facts do
201       { :osfamily => 'RedHat' }
202     end
203
204     let :params do
205       { :network_vlan_ranges => 'physnet1:1000:2000' }
206     end
207
208     let :platform_params do
209       { :ovs_server_package => 'openstack-neutron-openvswitch' }
210     end
211
212     it_configures 'neutron ovs plugin'
213   end
214 end