memcached (openstack) is no longer in use
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / classes / neutron_init_spec.rb
1 require 'spec_helper'
2
3 describe 'neutron' do
4
5   let :params do
6     { :package_ensure        => 'present',
7       :verbose               => false,
8       :debug                 => false,
9       :core_plugin           => 'linuxbridge',
10       :rabbit_host           => '127.0.0.1',
11       :rabbit_port           => 5672,
12       :rabbit_hosts          => false,
13       :rabbit_user           => 'guest',
14       :rabbit_password       => 'guest',
15       :rabbit_virtual_host   => '/',
16       :kombu_reconnect_delay => '1.0',
17       :log_dir               => '/var/log/neutron',
18       :report_interval       => '30',
19     }
20   end
21
22   shared_examples_for 'neutron' do
23
24     context 'and if rabbit_host parameter is provided' do
25       it_configures 'a neutron base installation'
26     end
27
28     context 'and if rabbit_hosts parameter is provided' do
29       before do
30         params.delete(:rabbit_host)
31         params.delete(:rabbit_port)
32       end
33
34       context 'with one server' do
35         before { params.merge!( :rabbit_hosts => ['127.0.0.1:5672'] ) }
36         it_configures 'a neutron base installation'
37         it_configures 'rabbit HA with a single virtual host'
38       end
39
40       context 'with multiple servers' do
41         before { params.merge!( :rabbit_hosts => ['rabbit1:5672', 'rabbit2:5672'] ) }
42         it_configures 'a neutron base installation'
43         it_configures 'rabbit HA with multiple hosts'
44       end
45
46       it 'configures logging' do
47         should contain_neutron_config('DEFAULT/log_file').with_ensure('absent')
48         should contain_neutron_config('DEFAULT/log_dir').with_value(params[:log_dir])
49       end
50
51     end
52
53     it_configures 'with SSL enabled with kombu'
54     it_configures 'with SSL enabled without kombu'
55     it_configures 'with SSL disabled'
56     it_configures 'with SSL wrongly configured'
57     it_configures 'with SSL and kombu wrongly configured'
58     it_configures 'with SSL socket options set'
59     it_configures 'with SSL socket options set with wrong parameters'
60     it_configures 'with SSL socket options set to false'
61     it_configures 'with syslog disabled'
62     it_configures 'with syslog enabled'
63     it_configures 'with syslog enabled and custom settings'
64     it_configures 'with log_file specified'
65     it_configures 'with logging disabled'
66     it_configures 'without service_plugins'
67     it_configures 'with service_plugins'
68   end
69
70   shared_examples_for 'a neutron base installation' do
71
72     it { should contain_class('neutron::params') }
73
74     it 'configures neutron configuration folder' do
75       should contain_file('/etc/neutron/').with(
76         :ensure  => 'directory',
77         :owner   => 'root',
78         :group   => 'neutron',
79         :mode    => '0750',
80         :require => 'Package[neutron]'
81       )
82     end
83
84     it 'configures neutron configuration file' do
85       should contain_file('/etc/neutron/neutron.conf').with(
86         :owner   => 'root',
87         :group   => 'neutron',
88         :mode    => '0640',
89         :require => 'Package[neutron]'
90       )
91     end
92
93     it 'installs neutron package' do
94       should contain_package('neutron').with(
95         :ensure => 'present',
96         :name   => platform_params[:common_package_name]
97       )
98     end
99
100     it 'configures credentials for rabbit' do
101       should contain_neutron_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_user] )
102       should contain_neutron_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] )
103       should contain_neutron_config('DEFAULT/rabbit_password').with_secret( true )
104       should contain_neutron_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] )
105       should contain_neutron_config('DEFAULT/kombu_reconnect_delay').with_value( params[:kombu_reconnect_delay] )
106     end
107
108     it 'configures neutron.conf' do
109       should contain_neutron_config('DEFAULT/verbose').with_value( params[:verbose] )
110       should contain_neutron_config('DEFAULT/bind_host').with_value('0.0.0.0')
111       should contain_neutron_config('DEFAULT/bind_port').with_value('9696')
112       should contain_neutron_config('DEFAULT/auth_strategy').with_value('keystone')
113       should contain_neutron_config('DEFAULT/core_plugin').with_value( params[:core_plugin] )
114       should contain_neutron_config('DEFAULT/base_mac').with_value('fa:16:3e:00:00:00')
115       should contain_neutron_config('DEFAULT/mac_generation_retries').with_value(16)
116       should contain_neutron_config('DEFAULT/dhcp_lease_duration').with_value(86400)
117       should contain_neutron_config('DEFAULT/dhcp_agents_per_network').with_value(1)
118       should contain_neutron_config('DEFAULT/network_device_mtu').with_ensure('absent')
119       should contain_neutron_config('DEFAULT/dhcp_agent_notification').with_value(true)
120       should contain_neutron_config('DEFAULT/allow_bulk').with_value(true)
121       should contain_neutron_config('DEFAULT/allow_pagination').with_value(false)
122       should contain_neutron_config('DEFAULT/allow_sorting').with_value(false)
123       should contain_neutron_config('DEFAULT/allow_overlapping_ips').with_value(false)
124       should contain_neutron_config('DEFAULT/api_extensions_path').with_value(nil)
125       should contain_neutron_config('DEFAULT/control_exchange').with_value('neutron')
126       should contain_neutron_config('agent/root_helper').with_value('sudo neutron-rootwrap /etc/neutron/rootwrap.conf')
127       should contain_neutron_config('agent/report_interval').with_value('30')
128     end
129   end
130
131   shared_examples_for 'rabbit HA with a single virtual host' do
132     it 'in neutron.conf' do
133       should_not contain_neutron_config('DEFAULT/rabbit_host')
134       should_not contain_neutron_config('DEFAULT/rabbit_port')
135       should contain_neutron_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts] )
136       should contain_neutron_config('DEFAULT/rabbit_ha_queues').with_value(true)
137     end
138   end
139
140   shared_examples_for 'rabbit HA with multiple hosts' do
141     it 'in neutron.conf' do
142       should_not contain_neutron_config('DEFAULT/rabbit_host')
143       should_not contain_neutron_config('DEFAULT/rabbit_port')
144       should contain_neutron_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') )
145       should contain_neutron_config('DEFAULT/rabbit_ha_queues').with_value(true)
146     end
147   end
148
149   shared_examples_for 'with SSL socket options set' do
150     before do
151       params.merge!(
152         :use_ssl         => true,
153         :cert_file       => '/path/to/cert',
154         :key_file        => '/path/to/key',
155         :ca_file         => '/path/to/ca'
156       )
157     end
158
159     it { should contain_neutron_config('DEFAULT/use_ssl').with_value('true') }
160     it { should contain_neutron_config('DEFAULT/ssl_cert_file').with_value('/path/to/cert') }
161     it { should contain_neutron_config('DEFAULT/ssl_key_file').with_value('/path/to/key') }
162     it { should contain_neutron_config('DEFAULT/ssl_ca_file').with_value('/path/to/ca') }
163   end
164
165   shared_examples_for 'with SSL socket options set with wrong parameters' do
166     before do
167       params.merge!(
168         :use_ssl         => true,
169         :key_file        => '/path/to/key',
170         :ca_file         => '/path/to/ca'
171       )
172     end
173
174     it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
175   end
176
177   shared_examples_for 'with SSL socket options set to false' do
178     before do
179       params.merge!(
180         :use_ssl         => false,
181         :cert_file       => false,
182         :key_file        => false,
183         :ca_file         => false
184       )
185     end
186
187     it { should contain_neutron_config('DEFAULT/use_ssl').with_value('false') }
188     it { should contain_neutron_config('DEFAULT/ssl_cert_file').with_ensure('absent') }
189     it { should contain_neutron_config('DEFAULT/ssl_key_file').with_ensure('absent') }
190     it { should contain_neutron_config('DEFAULT/ssl_ca_file').with_ensure('absent') }
191   end
192
193   shared_examples_for 'with SSL socket options set and no ca_file' do
194     before do
195       params.merge!(
196         :use_ssl         => true,
197         :cert_file       => '/path/to/cert',
198         :key_file        => '/path/to/key'
199       )
200     end
201
202     it { should contain_neutron_config('DEFAULT/use_ssl').with_value('true') }
203     it { should contain_neutron_config('DEFAULT/ssl_cert_file').with_value('/path/to/cert') }
204     it { should contain_neutron_config('DEFAULT/ssl_key_file').with_value('/path/to/key') }
205     it { should contain_neutron_config('DEFAULT/ssl_ca_file').with_ensure('absent') }
206   end
207
208   shared_examples_for 'with SSL socket options disabled with ca_file' do
209     before do
210       params.merge!(
211         :use_ssl         => false,
212         :ca_file         => '/path/to/ca'
213       )
214     end
215
216     it_raises 'a Puppet::Error', /The ca_file parameter requires that use_ssl to be set to true/
217   end
218
219   shared_examples_for 'with syslog disabled' do
220     it { should contain_neutron_config('DEFAULT/use_syslog').with_value(false) }
221   end
222
223   shared_examples_for 'with SSL enabled with kombu' do
224     before do
225       params.merge!(
226         :rabbit_use_ssl     => true,
227         :kombu_ssl_ca_certs => '/path/to/ssl/ca/certs',
228         :kombu_ssl_certfile => '/path/to/ssl/cert/file',
229         :kombu_ssl_keyfile  => '/path/to/ssl/keyfile',
230         :kombu_ssl_version  => 'TLSv1'
231       )
232     end
233
234     it do
235       should contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('true')
236       should contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs')
237       should contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file')
238       should contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile')
239       should contain_neutron_config('DEFAULT/kombu_ssl_version').with_value('TLSv1')
240     end
241   end
242
243   shared_examples_for 'with SSL enabled without kombu' do
244     before do
245       params.merge!(
246         :rabbit_use_ssl     => true
247       )
248     end
249
250     it do
251       should contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('true')
252       should contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
253       should contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
254       should contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
255       should contain_neutron_config('DEFAULT/kombu_ssl_version').with_value('TLSv1')
256     end
257   end
258
259   shared_examples_for 'with SSL disabled' do
260     before do
261       params.merge!(
262         :rabbit_use_ssl     => false,
263         :kombu_ssl_version  => 'TLSv1'
264       )
265     end
266
267     it do
268       should contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('false')
269       should contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
270       should contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
271       should contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
272       should contain_neutron_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
273     end
274   end
275
276   shared_examples_for 'with SSL wrongly configured' do
277     before do
278       params.merge!(
279         :rabbit_use_ssl     => false
280       )
281     end
282
283     context 'with SSL disabled' do
284
285       context 'with kombu_ssl_ca_certs parameter' do
286         before { params.merge!(:kombu_ssl_ca_certs => '/path/to/ssl/ca/certs') }
287         it_raises 'a Puppet::Error', /The kombu_ssl_ca_certs parameter requires rabbit_use_ssl to be set to true/
288       end
289
290       context 'with kombu_ssl_certfile parameter' do
291         before { params.merge!(:kombu_ssl_certfile => '/path/to/ssl/cert/file') }
292         it_raises 'a Puppet::Error', /The kombu_ssl_certfile parameter requires rabbit_use_ssl to be set to true/
293       end
294
295       context 'with kombu_ssl_keyfile parameter' do
296         before { params.merge!(:kombu_ssl_keyfile => '/path/to/ssl/keyfile') }
297         it_raises 'a Puppet::Error', /The kombu_ssl_keyfile parameter requires rabbit_use_ssl to be set to true/
298       end
299     end
300
301   end
302
303   shared_examples_for 'with SSL and kombu wrongly configured' do
304     before do
305       params.merge!(
306         :rabbit_use_ssl     => true,
307         :kombu_ssl_certfile  => '/path/to/ssl/cert/file',
308         :kombu_ssl_keyfile  => '/path/to/ssl/keyfile'
309       )
310     end
311
312     context 'without required parameters' do
313
314       context 'without kombu_ssl_keyfile parameter' do
315         before { params.delete(:kombu_ssl_keyfile) }
316         it_raises 'a Puppet::Error', /The kombu_ssl_certfile and kombu_ssl_keyfile parameters must be used together/
317       end
318     end
319
320   end
321
322   shared_examples_for 'with syslog enabled' do
323     before do
324       params.merge!(
325         :use_syslog => 'true'
326       )
327     end
328
329     it do
330       should contain_neutron_config('DEFAULT/use_syslog').with_value(true)
331       should contain_neutron_config('DEFAULT/syslog_log_facility').with_value('LOG_USER')
332     end
333   end
334
335   shared_examples_for 'with syslog enabled and custom settings' do
336     before do
337       params.merge!(
338         :use_syslog    => 'true',
339         :log_facility  => 'LOG_LOCAL0'
340       )
341     end
342
343     it do
344       should contain_neutron_config('DEFAULT/use_syslog').with_value(true)
345       should contain_neutron_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0')
346     end
347   end
348
349   shared_examples_for 'with log_file specified' do
350     before do
351       params.merge!(
352         :log_file => '/var/log/neutron/server.log',
353         :log_dir  => '/tmp/log/neutron'
354       )
355     end
356     it 'configures logging' do
357       should contain_neutron_config('DEFAULT/log_file').with_value(params[:log_file])
358       should contain_neutron_config('DEFAULT/log_dir').with_value(params[:log_dir])
359     end
360   end
361
362   shared_examples_for 'with logging disabled' do
363     before { params.merge!(
364       :log_file => false,
365       :log_dir  => false
366     )}
367     it {
368       should contain_neutron_config('DEFAULT/log_file').with_ensure('absent')
369       should contain_neutron_config('DEFAULT/log_dir').with_ensure('absent')
370     }
371   end
372
373   shared_examples_for 'without service_plugins' do
374     it { should_not contain_neutron_config('DEFAULT/service_plugins') }
375   end
376
377   shared_examples_for 'with service_plugins' do
378     before do
379       params.merge!(
380         :service_plugins => ['router','firewall','lbaas','vpnaas','metering']
381       )
382     end
383
384     it do
385       should contain_neutron_config('DEFAULT/service_plugins').with_value('router,firewall,lbaas,vpnaas,metering')
386     end
387
388   end
389
390   shared_examples_for 'with network_device_mtu defined' do
391     before do
392       params.merge!(
393         :network_device_mtu => 9000
394       )
395     end
396
397     it do
398       should contina_neutron_config('DEFAULT/network_device_mtu').with_value(params[:newtork_device_mtu])
399     end
400   end
401
402   context 'on Debian platforms' do
403     let :facts do
404       { :osfamily => 'Debian' }
405     end
406
407     let :platform_params do
408       { :common_package_name => 'neutron-common' }
409     end
410
411     it_configures 'neutron'
412   end
413
414   context 'on RedHat platforms' do
415     let :facts do
416       { :osfamily => 'RedHat' }
417     end
418
419     let :platform_params do
420       { :common_package_name => 'openstack-neutron' }
421     end
422
423     it_configures 'neutron'
424   end
425 end