memcached (openstack) is no longer in use
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / classes / neutron_agents_ovs_spec.rb
1 require 'spec_helper'
2
3 describe 'neutron::agents::ovs' do
4
5   let :pre_condition do
6     "class { 'neutron': rabbit_password => 'passw0rd' }\n" +
7     "class { 'neutron::plugins::ovs': network_vlan_ranges => 'physnet1:1000:2000' }"
8   end
9
10   let :default_params do
11     { :package_ensure       => 'present',
12       :manage_service       => true,
13       :enabled              => true,
14       :bridge_uplinks       => [],
15       :bridge_mappings      => [],
16       :integration_bridge   => 'br-int',
17       :enable_tunneling     => false,
18       :local_ip             => false,
19       :tunnel_bridge        => 'br-tun',
20       :polling_interval     => 2,
21       :firewall_driver      => 'neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver',
22       :veth_mtu             => ''
23     }
24   end
25
26   let :params do
27     {}
28   end
29
30   shared_examples_for 'neutron plugin ovs agent' do
31     let :p do
32       default_params.merge(params)
33     end
34
35     it { should contain_class('neutron::params') }
36
37     it 'configures ovs_neutron_plugin.ini' do
38       should contain_neutron_plugin_ovs('AGENT/polling_interval').with_value(p[:polling_interval])
39       should contain_neutron_plugin_ovs('OVS/integration_bridge').with_value(p[:integration_bridge])
40       should contain_neutron_plugin_ovs('SECURITYGROUP/firewall_driver').\
41         with_value(p[:firewall_driver])
42       should contain_neutron_plugin_ovs('OVS/enable_tunneling').with_value(false)
43       should contain_neutron_plugin_ovs('OVS/tunnel_bridge').with_ensure('absent')
44       should contain_neutron_plugin_ovs('OVS/local_ip').with_ensure('absent')
45       should contain_neutron_plugin_ovs('AGENT/veth_mtu').with_ensure('absent')
46     end
47
48     it 'configures vs_bridge' do
49       should contain_vs_bridge(p[:integration_bridge]).with_ensure('present')
50     end
51
52     it 'installs neutron ovs agent package' do
53       if platform_params.has_key?(:ovs_agent_package)
54         should contain_package('neutron-plugin-ovs-agent').with(
55           :name   => platform_params[:ovs_agent_package],
56           :ensure => p[:package_ensure]
57         )
58         should contain_package('neutron-plugin-ovs-agent').with_before(/Neutron_plugin_ovs\[.+\]/)
59       else
60         should contain_package('neutron-plugin-ovs').with_before(/Neutron_plugin_ovs\[.+\]/)
61       end
62     end
63
64     it 'configures neutron ovs agent service' do
65       should contain_service('neutron-plugin-ovs-service').with(
66         :name    => platform_params[:ovs_agent_service],
67         :enable  => true,
68         :ensure  => 'running',
69         :require => 'Class[Neutron]'
70       )
71     end
72
73     context 'with veth_mtu set' do
74       before :each do
75         params.merge(:veth_mtu => '9000')
76       end
77
78       it 'should set the veth_mtu on the ovs agent' do
79         should contain_neutron_plugin_ovs('AGENT/veth_mtu').with_value(params[:veth_mtu])
80       end
81     end
82
83     context 'when not installing ovs agent package' do
84       before :each do
85         params.merge!(:package_ensure => 'absent')
86       end
87       it 'uninstalls neutron ovs agent package' do
88         if platform_params.has_key?(:ovs_agent_package)
89           should contain_package('neutron-plugin-ovs-agent').with(
90             :name   => platform_params[:ovs_agent_package],
91             :ensure => p[:package_ensure]
92           )
93         end
94       end
95     end
96
97     context 'when supplying a firewall driver' do
98       before :each do
99         params.merge!(:firewall_driver => false)
100       end
101       it 'should configure firewall driver' do
102         should contain_neutron_plugin_ovs('SECURITYGROUP/firewall_driver').with_ensure('absent')
103       end
104     end
105
106     context 'when supplying bridge mappings for provider networks' do
107       before :each do
108         params.merge!(:bridge_uplinks => ['br-ex:eth2'],:bridge_mappings => ['default:br-ex'])
109       end
110
111       it 'configures bridge mappings' do
112         should contain_neutron_plugin_ovs('OVS/bridge_mappings')
113       end
114
115       it 'should configure bridge mappings' do
116         should contain_neutron__plugins__ovs__bridge(params[:bridge_mappings].join(',')).with(
117           :before => 'Service[neutron-plugin-ovs-service]'
118         )
119       end
120
121       it 'should configure bridge uplinks' do
122         should contain_neutron__plugins__ovs__port(params[:bridge_uplinks].join(',')).with(
123           :before => 'Service[neutron-plugin-ovs-service]'
124         )
125       end
126     end
127
128     context 'when enabling tunneling' do
129       context 'without local ip address' do
130         before :each do
131           params.merge!(:enable_tunneling => true)
132         end
133         it 'should fail' do
134           expect do
135             subject
136           end.to raise_error(Puppet::Error, /Local ip for ovs agent must be set when tunneling is enabled/)
137         end
138       end
139       context 'with default params' do
140         before :each do
141           params.merge!(:enable_tunneling => true, :local_ip => '127.0.0.1' )
142         end
143         it 'should configure ovs for tunneling' do
144           should contain_neutron_plugin_ovs('OVS/enable_tunneling').with_value(true)
145           should contain_neutron_plugin_ovs('OVS/tunnel_bridge').with_value(default_params[:tunnel_bridge])
146           should contain_neutron_plugin_ovs('OVS/local_ip').with_value('127.0.0.1')
147           should contain_vs_bridge(default_params[:tunnel_bridge]).with_ensure('present')
148         end
149       end
150
151       context 'with vxlan tunneling' do
152         before :each do
153           params.merge!(:enable_tunneling => true,
154                         :local_ip => '127.0.0.1',
155                         :tunnel_types => ['vxlan'],
156                         :vxlan_udp_port => '4789')
157         end
158
159         it 'should perform vxlan network configuration' do
160           should contain_neutron_plugin_ovs('agent/tunnel_types').with_value(params[:tunnel_types])
161           should contain_neutron_plugin_ovs('agent/vxlan_udp_port').with_value(params[:vxlan_udp_port])
162         end
163       end
164     end
165   end
166
167   context 'on Debian platforms' do
168     let :facts do
169       { :osfamily => 'Debian' }
170     end
171
172     let :platform_params do
173       { :ovs_agent_package => 'neutron-plugin-openvswitch-agent',
174         :ovs_agent_service => 'neutron-plugin-openvswitch-agent' }
175     end
176
177     it_configures 'neutron plugin ovs agent'
178   end
179
180   context 'on RedHat platforms' do
181     let :facts do
182       { :osfamily => 'RedHat' }
183     end
184
185     let :platform_params do
186       { :ovs_cleanup_service => 'neutron-ovs-cleanup',
187         :ovs_agent_service   => 'neutron-openvswitch-agent' }
188     end
189
190     it_configures 'neutron plugin ovs agent'
191     it 'configures neutron ovs cleanup service' do
192       should contain_service('ovs-cleanup-service').with(
193         :name    => platform_params[:ovs_cleanup_service],
194         :enable  => true
195       )
196       should contain_package('neutron-plugin-ovs').with_before(/Service\[ovs-cleanup-service\]/)
197     end
198
199   end
200 end