try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / spec / classes / nova_init_spec.rb
1 require 'spec_helper'
2
3 describe 'nova' do
4
5   shared_examples 'nova' do
6
7     context 'with default parameters' do
8
9       it 'installs packages' do
10         should contain_package('python').with_ensure('present')
11         should contain_package('python-greenlet').with(
12           :ensure  => 'present',
13           :require => 'Package[python]'
14         )
15         should contain_package('python-nova').with(
16           :ensure  => 'present',
17           :require => 'Package[python-greenlet]'
18         )
19         should contain_package('nova-common').with(
20           :name    => platform_params[:nova_common_package],
21           :ensure  => 'present',
22           :tag    => ['openstack', 'nova']
23         )
24       end
25
26       it 'does not create user and group' do
27         should_not contain_group('nova').with(
28           :ensure  => 'present',
29           :system  => true,
30           :before  => 'User[nova]'
31         )
32         should_not contain_user('nova').with(
33           :ensure     => 'present',
34           :system     => true,
35           :groups     => 'nova',
36           :home       => '/var/lib/nova',
37           :managehome => false,
38           :shell      => '/bin/false'
39         )
40       end
41
42       it 'creates various files and folders' do
43         should contain_file('/var/log/nova').with(
44           :ensure  => 'directory',
45           :mode    => '0750',
46           :owner   => 'nova',
47           :require => 'Package[nova-common]'
48         )
49         should contain_file('/etc/nova/nova.conf').with(
50           :mode    => '0640',
51           :owner   => 'nova',
52           :group   => 'nova',
53           :require => 'Package[nova-common]'
54         )
55       end
56
57       it 'configures rootwrap' do
58         should contain_nova_config('DEFAULT/rootwrap_config').with_value('/etc/nova/rootwrap.conf')
59       end
60
61       it { should contain_exec('networking-refresh').with(
62         :command     => '/sbin/ifdown -a ; /sbin/ifup -a',
63         :refreshonly => true
64       )}
65
66       it 'configures image service' do
67         should contain_nova_config('DEFAULT/image_service').with_value('nova.image.glance.GlanceImageService')
68         should contain_nova_config('glance/api_servers').with_value('localhost:9292')
69       end
70
71       it 'configures auth_strategy' do
72         should contain_nova_config('DEFAULT/auth_strategy').with_value('keystone')
73         should_not contain_nova_config('DEFAULT/use_deprecated_auth').with_value(false)
74       end
75
76       it 'configures rabbit' do
77         should contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit')
78         should contain_nova_config('DEFAULT/rabbit_host').with_value('localhost')
79         should contain_nova_config('DEFAULT/rabbit_password').with_value('guest').with_secret(true)
80         should contain_nova_config('DEFAULT/rabbit_port').with_value('5672')
81         should contain_nova_config('DEFAULT/rabbit_userid').with_value('guest')
82         should contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/')
83       end
84
85       it 'configures various things' do
86         should contain_nova_config('DEFAULT/verbose').with_value(false)
87         should contain_nova_config('DEFAULT/debug').with_value(false)
88         should contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova')
89         should contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova')
90         should contain_nova_config('DEFAULT/lock_path').with_value(platform_params[:lock_path])
91         should contain_nova_config('DEFAULT/service_down_time').with_value('60')
92         should contain_nova_config('DEFAULT/rootwrap_config').with_value('/etc/nova/rootwrap.conf')
93         should contain_nova_config('DEFAULT/report_interval').with_value('10')
94         should contain_nova_config('DEFAULT/os_region_name').with_ensure('absent')
95       end
96
97       it 'installs utilities' do
98         should contain_class('nova::utilities')
99       end
100
101       it 'disables syslog' do
102         should contain_nova_config('DEFAULT/use_syslog').with_value(false)
103       end
104     end
105
106     context 'with overridden parameters' do
107
108       let :params do
109         { :verbose                  => true,
110           :debug                    => true,
111           :log_dir                  => '/var/log/nova2',
112           :image_service            => 'nova.image.local.LocalImageService',
113           :rabbit_host              => 'rabbit',
114           :rabbit_userid            => 'rabbit_user',
115           :rabbit_port              => '5673',
116           :rabbit_password          => 'password',
117           :rabbit_ha_queues         => 'undef',
118           :lock_path                => '/var/locky/path',
119           :state_path               => '/var/lib/nova2',
120           :service_down_time        => '120',
121           :auth_strategy            => 'foo',
122           :ensure_package           => '2012.1.1-15.el6',
123           :memcached_servers        => ['memcached01:11211', 'memcached02:11211'],
124           :install_utilities        => false,
125           :notification_driver      => 'ceilometer.compute.nova_notifier',
126           :notification_topics      => 'openstack',
127           :notify_api_faults        => true,
128           :nova_user_id             => '499',
129           :nova_group_id            => '499',
130           :report_interval          => '60',
131           :nova_shell               => '/bin/bash',
132           :os_region_name           => 'MyRegion' }
133       end
134
135       it 'creates user and group' do
136         should contain_group('nova').with(
137           :ensure  => 'present',
138           :system  => true,
139           :gid     => '499',
140           :before  => 'Package[nova-common]'
141         )
142         should contain_user('nova').with(
143           :ensure     => 'present',
144           :system     => true,
145           :groups     => 'nova',
146           :home       => '/var/lib/nova',
147           :managehome => false,
148           :shell      => '/bin/bash',
149           :uid        => '499',
150           :gid        => '499',
151           :require    => 'Group[nova]'
152         )
153       end
154
155       it 'installs packages' do
156         should contain_package('nova-common').with('ensure' => '2012.1.1-15.el6')
157         should contain_package('python-nova').with('ensure' => '2012.1.1-15.el6')
158       end
159
160       it 'configures image service' do
161         should contain_nova_config('DEFAULT/image_service').with_value('nova.image.local.LocalImageService')
162         should_not contain_nova_config('glance/api_servers')
163       end
164
165       it 'configures auth_strategy' do
166         should contain_nova_config('DEFAULT/auth_strategy').with_value('foo')
167         should_not contain_nova_config('DEFAULT/use_deprecated_auth').with_value(true)
168       end
169
170       it 'configures rabbit' do
171         should contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit')
172         should contain_nova_config('DEFAULT/rabbit_host').with_value('rabbit')
173         should contain_nova_config('DEFAULT/rabbit_password').with_value('password').with_secret(true)
174         should contain_nova_config('DEFAULT/rabbit_port').with_value('5673')
175         should contain_nova_config('DEFAULT/rabbit_userid').with_value('rabbit_user')
176         should contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/')
177       end
178
179       it 'configures memcached_servers' do
180         should contain_nova_config('DEFAULT/memcached_servers').with_value('memcached01:11211,memcached02:11211')
181       end
182
183       it 'configures various things' do
184         should contain_nova_config('DEFAULT/verbose').with_value(true)
185         should contain_nova_config('DEFAULT/debug').with_value(true)
186         should contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova2')
187         should contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova2')
188         should contain_nova_config('DEFAULT/lock_path').with_value('/var/locky/path')
189         should contain_nova_config('DEFAULT/service_down_time').with_value('120')
190         should contain_nova_config('DEFAULT/notification_driver').with_value('ceilometer.compute.nova_notifier')
191         should contain_nova_config('DEFAULT/notification_topics').with_value('openstack')
192         should contain_nova_config('DEFAULT/notify_api_faults').with_value(true)
193         should contain_nova_config('DEFAULT/report_interval').with_value('60')
194         should contain_nova_config('DEFAULT/os_region_name').with_value('MyRegion')
195       end
196
197       context 'with multiple notification_driver' do
198         before { params.merge!( :notification_driver => ['ceilometer.compute.nova_notifier', 'nova.openstack.common.notifier.rpc_notifier']) }
199
200         it { should contain_nova_config('DEFAULT/notification_driver').with_value(
201           'ceilometer.compute.nova_notifier,nova.openstack.common.notifier.rpc_notifier'
202         ) }
203       end
204
205       it 'does not install utilities' do
206         should_not contain_class('nova::utilities')
207       end
208
209       context 'with logging directory disabled' do
210         before { params.merge!( :log_dir => false) }
211
212         it { should contain_nova_config('DEFAULT/log_dir').with_ensure('absent') }
213       end
214     end
215
216     context 'with wrong notify_on_state_change parameter' do
217       let :params do
218         { :notify_on_state_change => 'vm_status' }
219       end
220
221       it 'configures database' do
222         should contain_nova_config('DEFAULT/notify_on_state_change').with_ensure('absent')
223       end
224     end
225
226     context 'with notify_on_state_change parameter' do
227       let :params do
228         { :notify_on_state_change => 'vm_state' }
229       end
230
231       it 'configures database' do
232         should contain_nova_config('DEFAULT/notify_on_state_change').with_value('vm_state')
233       end
234     end
235
236     context 'with syslog enabled' do
237       let :params do
238         { :use_syslog => 'true' }
239       end
240
241       it 'configures syslog' do
242         should contain_nova_config('DEFAULT/use_syslog').with_value(true)
243         should contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_USER')
244       end
245     end
246
247     context 'with syslog enabled and log_facility parameter' do
248       let :params do
249         { :use_syslog   => 'true',
250           :log_facility => 'LOG_LOCAL0' }
251       end
252
253       it 'configures syslog' do
254         should contain_nova_config('DEFAULT/use_syslog').with_value(true)
255         should contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0')
256       end
257     end
258
259     context 'with rabbit_hosts parameter' do
260       let :params do
261         { :rabbit_hosts => ['rabbit:5673', 'rabbit2:5674'] }
262       end
263
264       it 'configures rabbit' do
265         should_not contain_nova_config('DEFAULT/rabbit_host')
266         should_not contain_nova_config('DEFAULT/rabbit_port')
267         should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673,rabbit2:5674')
268         should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
269         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
270         should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false)
271         should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
272         should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
273         should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
274         should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
275       end
276     end
277
278     context 'with rabbit_hosts parameter (one server)' do
279       let :params do
280         { :rabbit_hosts => ['rabbit:5673'] }
281       end
282
283       it 'configures rabbit' do
284         should_not contain_nova_config('DEFAULT/rabbit_host')
285         should_not contain_nova_config('DEFAULT/rabbit_port')
286         should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673')
287         should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
288         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
289         should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false)
290       end
291     end
292
293     context 'with rabbit_ha_queues set to true' do
294       let :params do
295         { :rabbit_ha_queues => 'true' }
296       end
297
298       it 'configures rabbit' do
299         should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
300       end
301     end
302
303     context 'with amqp_durable_queues parameter' do
304       let :params do
305         { :rabbit_hosts => ['rabbit:5673'],
306           :amqp_durable_queues => 'true' }
307       end
308
309       it 'configures rabbit' do
310         should_not contain_nova_config('DEFAULT/rabbit_host')
311         should_not contain_nova_config('DEFAULT/rabbit_port')
312         should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673')
313         should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
314         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
315         should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(true)
316         should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
317         should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
318         should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
319         should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
320       end
321     end
322
323     context 'with rabbit ssl enabled with kombu' do
324       let :params do
325         { :rabbit_hosts       => ['rabbit:5673'],
326           :rabbit_use_ssl     => 'true',
327           :kombu_ssl_ca_certs => '/etc/ca.cert',
328           :kombu_ssl_certfile => '/etc/certfile',
329           :kombu_ssl_keyfile  => '/etc/key',
330           :kombu_ssl_version  => 'TLSv1', }
331       end
332
333       it 'configures rabbit' do
334         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true)
335         should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_value('/etc/ca.cert')
336         should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_value('/etc/certfile')
337         should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_value('/etc/key')
338         should contain_nova_config('DEFAULT/kombu_ssl_version').with_value('TLSv1')
339       end
340     end
341
342     context 'with rabbit ssl enabled without kombu' do
343       let :params do
344         { :rabbit_hosts       => ['rabbit:5673'],
345           :rabbit_use_ssl     => 'true', }
346       end
347
348       it 'configures rabbit' do
349         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true)
350         should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
351         should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
352         should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
353         should contain_nova_config('DEFAULT/kombu_ssl_version').with_value('TLSv1')
354       end
355     end
356
357     context 'with rabbit ssl disabled' do
358       let :params do
359         {
360           :rabbit_password    => 'pass',
361           :rabbit_use_ssl     => false,
362           :kombu_ssl_version  => 'TLSv1',
363         }
364       end
365
366       it 'configures rabbit' do
367         should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value('false')
368         should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
369         should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
370         should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
371         should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
372       end
373     end
374
375     context 'with qpid rpc_backend' do
376       let :params do
377         { :rpc_backend => 'qpid' }
378       end
379
380       context 'with default parameters' do
381         it 'configures qpid' do
382           should contain_nova_config('DEFAULT/rpc_backend').with_value('qpid')
383           should contain_nova_config('DEFAULT/qpid_hostname').with_value('localhost')
384           should contain_nova_config('DEFAULT/qpid_port').with_value('5672')
385           should contain_nova_config('DEFAULT/qpid_username').with_value('guest')
386           should contain_nova_config('DEFAULT/qpid_password').with_value('guest').with_secret(true)
387           should contain_nova_config('DEFAULT/qpid_heartbeat').with_value('60')
388           should contain_nova_config('DEFAULT/qpid_protocol').with_value('tcp')
389           should contain_nova_config('DEFAULT/qpid_tcp_nodelay').with_value(true)
390         end
391       end
392
393       context 'with qpid_password parameter (without qpid_sasl_mechanisms)' do
394         before do
395           params.merge!({ :qpid_password => 'guest' })
396         end
397         it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_ensure('absent') }
398       end
399
400       context 'with qpid_password parameter (with qpid_sasl_mechanisms)' do
401         before do
402           params.merge!({
403             :qpid_password        => 'guest',
404             :qpid_sasl_mechanisms => 'A'
405           })
406         end
407         it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_value('A') }
408       end
409
410       context 'with qpid_password parameter (with array of qpid_sasl_mechanisms)' do
411         before do
412           params.merge!({
413             :qpid_password        => 'guest',
414             :qpid_sasl_mechanisms => [ 'DIGEST-MD5', 'GSSAPI', 'PLAIN' ]
415           })
416         end
417         it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_value('DIGEST-MD5 GSSAPI PLAIN') }
418       end
419     end
420
421     context 'with qpid rpc_backend with old parameter' do
422       let :params do
423         { :rpc_backend => 'nova.openstack.common.rpc.impl_qpid' }
424       end
425
426       it { should contain_nova_config('DEFAULT/rpc_backend').with_value('nova.openstack.common.rpc.impl_qpid') }
427     end
428
429     context 'with rabbitmq rpc_backend with old parameter' do
430       let :params do
431         { :rpc_backend => 'nova.openstack.common.rpc.impl_kombu' }
432       end
433
434       it { should contain_nova_config('DEFAULT/rpc_backend').with_value('nova.openstack.common.rpc.impl_kombu') }
435     end
436
437     context 'with ssh public key' do
438       let :params do
439         {
440           :nova_public_key => {'type' => 'ssh-rsa',
441                                'key'  => 'keydata'}
442         }
443       end
444
445       it 'should install ssh public key' do
446         should contain_ssh_authorized_key('nova-migration-public-key').with(
447           :ensure => 'present',
448           :key => 'keydata',
449           :type => 'ssh-rsa'
450         )
451       end
452     end
453
454     context 'with ssh public key missing key type' do
455       let :params do
456         {
457           :nova_public_key => {'type' => '',
458                                'key'  => 'keydata'}
459         }
460       end
461
462       it 'should raise an error' do
463         expect {
464           should contain_ssh_authorized_key('nova-migration-public-key').with(
465             :ensure => 'present',
466             :key => 'keydata',
467             :type => ''
468           )
469         }.to raise_error Puppet::Error, /You must provide both a key type and key data./
470       end
471     end
472
473     context 'with ssh public key missing key data' do
474       let :params do
475         {
476           :nova_public_key => {'type' => 'ssh-rsa',
477                                'key'  => ''}
478         }
479       end
480
481       it 'should raise an error' do
482         expect {
483           should contain_ssh_authorized_key('nova-migration-public-key').with(
484             :ensure => 'present',
485             :key => 'keydata',
486             :type => ''
487           )
488         }.to raise_error Puppet::Error, /You must provide both a key type and key data./
489       end
490     end
491
492     context 'with ssh private key' do
493       let :params do
494         {
495           :nova_private_key => {'type' => 'ssh-rsa',
496                                 'key'  => 'keydata'}
497         }
498       end
499
500       it 'should install ssh private key' do
501         should contain_file('/var/lib/nova/.ssh/id_rsa').with(
502           :content => 'keydata'
503         )
504       end
505     end
506
507     context 'with ssh private key missing key type' do
508       let :params do
509         {
510           :nova_private_key => {'type' => '',
511                                 'key'  => 'keydata'}
512         }
513       end
514
515       it 'should raise an error' do
516         expect {
517           should contain_file('/var/lib/nova/.ssh/id_rsa').with(
518             :content => 'keydata'
519           )
520         }.to raise_error Puppet::Error, /You must provide both a key type and key data./
521       end
522     end
523
524     context 'with ssh private key having incorrect key type' do
525       let :params do
526         {
527           :nova_private_key => {'type' => 'invalid',
528                                 'key'  => 'keydata'}
529         }
530       end
531
532       it 'should raise an error' do
533         expect {
534           should contain_file('/var/lib/nova/.ssh/id_rsa').with(
535             :content => 'keydata'
536           )
537         }.to raise_error Puppet::Error, /Unable to determine name of private key file./
538       end
539     end
540
541     context 'with ssh private key missing key data' do
542       let :params do
543         {
544           :nova_private_key => {'type' => 'ssh-rsa',
545                                 'key'  => ''}
546         }
547       end
548
549       it 'should raise an error' do
550         expect {
551           should contain_file('/var/lib/nova/.ssh/id_rsa').with(
552             :content => 'keydata'
553           )
554         }.to raise_error Puppet::Error, /You must provide both a key type and key data./
555       end
556     end
557
558     context 'with SSL socket options set' do
559       let :params do
560         {
561           :use_ssl          => true,
562           :enabled_ssl_apis => ['ec2', 'osapi_compute'],
563           :cert_file        => '/path/to/cert',
564           :ca_file          => '/path/to/ca',
565           :key_file         => '/path/to/key',
566         }
567       end
568
569       it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_value('ec2,osapi_compute') }
570       it { should contain_nova_config('DEFAULT/ssl_ca_file').with_value('/path/to/ca') }
571       it { should contain_nova_config('DEFAULT/ssl_cert_file').with_value('/path/to/cert') }
572       it { should contain_nova_config('DEFAULT/ssl_key_file').with_value('/path/to/key') }
573     end
574
575     context 'with SSL socket options set with wrong parameters' do
576       let :params do
577         {
578           :use_ssl          => true,
579           :enabled_ssl_apis => ['ec2'],
580           :ca_file          => '/path/to/ca',
581           :key_file         => '/path/to/key',
582         }
583       end
584
585       it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
586     end
587
588     context 'with SSL socket options set to false' do
589       let :params do
590         {
591           :use_ssl          => false,
592           :enabled_ssl_apis => [],
593           :cert_file        => false,
594           :ca_file          => false,
595           :key_file         => false,
596         }
597       end
598
599       it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_ensure('absent') }
600       it { should contain_nova_config('DEFAULT/ssl_ca_file').with_ensure('absent') }
601       it { should contain_nova_config('DEFAULT/ssl_cert_file').with_ensure('absent') }
602       it { should contain_nova_config('DEFAULT/ssl_key_file').with_ensure('absent') }
603     end
604
605   end
606
607   context 'on Debian platforms' do
608     let :facts do
609       { :osfamily => 'Debian',
610         :operatingsystem => 'Debian' }
611     end
612
613     let :platform_params do
614       { :nova_common_package => 'nova-common',
615         :lock_path           => '/var/lock/nova' }
616     end
617
618     it_behaves_like 'nova'
619     it 'creates the log folder with the right group for Debian' do
620       should contain_file('/var/log/nova').with(:group => 'nova')
621     end
622   end
623
624   context 'on Ubuntu platforms' do
625     let :facts do
626       { :osfamily => 'Debian',
627         :operatingsystem => 'Ubuntu' }
628     end
629
630     let :platform_params do
631       { :nova_common_package => 'nova-common',
632         :lock_path           => '/var/lock/nova' }
633     end
634
635     it_behaves_like 'nova'
636     it 'creates the log folder with the right group for Ubuntu' do
637       should contain_file('/var/log/nova').with(:group => 'adm')
638     end
639   end
640
641   context 'on RedHat platforms' do
642     let :facts do
643       { :osfamily => 'RedHat' }
644     end
645
646     let :platform_params do
647       { :nova_common_package => 'openstack-nova-common',
648         :lock_path           => '/var/lib/nova/tmp' }
649     end
650
651     it_behaves_like 'nova'
652
653     it 'creates the log folder with the right group for RedHat' do
654       should contain_file('/var/log/nova').with(:group => 'nova')
655     end
656   end
657 end