]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/nova/spec/classes/nova_api_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / nova / spec / classes / nova_api_spec.rb
1 require 'spec_helper'
2
3 describe 'nova::api' do
4
5   let :pre_condition do
6     'include nova'
7   end
8
9   let :params do
10     { :admin_password => 'passw0rd' }
11   end
12
13   let :facts do
14     { :processorcount => 5 }
15   end
16
17   shared_examples 'nova-api' do
18
19     context 'with default parameters' do
20
21       it 'installs nova-api package and service' do
22         should contain_service('nova-api').with(
23           :name      => platform_params[:nova_api_service],
24           :ensure    => 'stopped',
25           :hasstatus => true,
26           :enable    => false
27         )
28         should contain_package('nova-api').with(
29           :name   => platform_params[:nova_api_package],
30           :ensure => 'present',
31           :notify => 'Service[nova-api]',
32           :tag    => ['openstack', 'nova']
33         )
34         should_not contain_exec('validate_nova_api')
35       end
36
37       it 'configures keystone_authtoken middleware' do
38         should contain_nova_config(
39          'keystone_authtoken/auth_host').with_value('127.0.0.1')
40         should contain_nova_config(
41           'keystone_authtoken/auth_port').with_value('35357')
42         should contain_nova_config(
43           'keystone_authtoken/auth_protocol').with_value('http')
44         should contain_nova_config(
45           'keystone_authtoken/auth_uri').with_value('http://127.0.0.1:5000/')
46         should contain_nova_config(
47           'keystone_authtoken/auth_admin_prefix').with_ensure('absent')
48         should contain_nova_config(
49           'keystone_authtoken/auth_version').with_ensure('absent')
50         should contain_nova_config(
51           'keystone_authtoken/admin_tenant_name').with_value('services')
52         should contain_nova_config(
53           'keystone_authtoken/admin_user').with_value('nova')
54         should contain_nova_config(
55           'keystone_authtoken/admin_password').with_value('passw0rd').with_secret(true)
56       end
57
58       it 'configures various stuff' do
59         should contain_nova_config('DEFAULT/ec2_listen').with('value' => '0.0.0.0')
60         should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '0.0.0.0')
61         should contain_nova_config('DEFAULT/metadata_listen').with('value' => '0.0.0.0')
62         should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '0.0.0.0')
63         should contain_nova_config('DEFAULT/osapi_compute_workers').with('value' => '5')
64         should contain_nova_config('DEFAULT/ec2_workers').with('value' => '5')
65         should contain_nova_config('DEFAULT/metadata_workers').with('value' => '5')
66       end
67
68       it 'do not configure v3 api' do
69         should contain_nova_config('osapi_v3/enabled').with('value' => false)
70       end
71
72       it 'unconfigures neutron_metadata proxy' do
73         should contain_nova_config('neutron/service_metadata_proxy').with(:value => false)
74         should contain_nova_config('neutron/metadata_proxy_shared_secret').with(:ensure => 'absent')
75       end
76     end
77
78     context 'with deprecated parameters' do
79       before do
80         params.merge!({
81           :workers           => 1,
82         })
83       end
84       it 'configures various stuff' do
85         should contain_nova_config('DEFAULT/osapi_compute_workers').with('value' => '1')
86       end
87     end
88
89     context 'with overridden parameters' do
90       before do
91         params.merge!({
92           :enabled                              => true,
93           :ensure_package                       => '2012.1-2',
94           :auth_host                            => '10.0.0.1',
95           :auth_port                            => 1234,
96           :auth_protocol                        => 'https',
97           :auth_admin_prefix                    => '/keystone/admin',
98           :auth_uri                             => 'https://10.0.0.1:9999/',
99           :auth_version                         => 'v3.0',
100           :admin_tenant_name                    => 'service2',
101           :admin_user                           => 'nova2',
102           :admin_password                       => 'passw0rd2',
103           :api_bind_address                     => '192.168.56.210',
104           :metadata_listen                      => '127.0.0.1',
105           :volume_api_class                     => 'nova.volume.cinder.API',
106           :use_forwarded_for                    => false,
107           :ratelimits                           => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)',
108           :neutron_metadata_proxy_shared_secret => 'secrete',
109           :osapi_compute_workers                => 1,
110           :metadata_workers                     => 2,
111           :osapi_v3                             => true,
112           :keystone_ec2_url                     => 'https://example.com:5000/v2.0/ec2tokens',
113           :pci_alias                            => "[{\"vendor_id\":\"8086\",\"product_id\":\"0126\",\"name\":\"graphic_card\"},{\"vendor_id\":\"9096\",\"product_id\":\"1520\",\"name\":\"network_card\"}]"
114         })
115       end
116
117       it 'installs nova-api package and service' do
118         should contain_package('nova-api').with(
119           :name   => platform_params[:nova_api_package],
120           :ensure => '2012.1-2',
121           :tag    => ['openstack', 'nova']
122         )
123         should contain_service('nova-api').with(
124           :name      => platform_params[:nova_api_service],
125           :ensure    => 'running',
126           :hasstatus => true,
127           :enable    => true
128         )
129       end
130
131       it 'configures keystone_authtoken middleware' do
132         should contain_nova_config(
133           'keystone_authtoken/auth_host').with_value('10.0.0.1')
134         should contain_nova_config(
135           'keystone_authtoken/auth_port').with_value('1234')
136         should contain_nova_config(
137           'keystone_authtoken/auth_protocol').with_value('https')
138         should contain_nova_config(
139           'keystone_authtoken/auth_admin_prefix').with_value('/keystone/admin')
140         should contain_nova_config(
141           'keystone_authtoken/auth_uri').with_value('https://10.0.0.1:9999/')
142         should contain_nova_config(
143           'keystone_authtoken/auth_version').with_value('v3.0')
144         should contain_nova_config(
145           'keystone_authtoken/admin_tenant_name').with_value('service2')
146         should contain_nova_config(
147           'keystone_authtoken/admin_user').with_value('nova2')
148         should contain_nova_config(
149           'keystone_authtoken/admin_password').with_value('passw0rd2').with_secret(true)
150         should contain_nova_paste_api_ini(
151           'filter:ratelimit/limits').with_value('(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)')
152       end
153
154       it 'configures various stuff' do
155         should contain_nova_config('DEFAULT/ec2_listen').with('value' => '192.168.56.210')
156         should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '192.168.56.210')
157         should contain_nova_config('DEFAULT/metadata_listen').with('value' => '127.0.0.1')
158         should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '192.168.56.210')
159         should contain_nova_config('DEFAULT/use_forwarded_for').with('value' => false)
160         should contain_nova_config('DEFAULT/osapi_compute_workers').with('value' => '1')
161         should contain_nova_config('DEFAULT/metadata_workers').with('value' => '2')
162         should contain_nova_config('neutron/service_metadata_proxy').with('value' => true)
163         should contain_nova_config('neutron/metadata_proxy_shared_secret').with('value' => 'secrete')
164         should contain_nova_config('DEFAULT/keystone_ec2_url').with('value' => 'https://example.com:5000/v2.0/ec2tokens')
165       end
166
167       it 'configure nova api v3' do
168         should contain_nova_config('osapi_v3/enabled').with('value' => true)
169       end
170
171       it 'configures nova pci_alias entries' do
172         should contain_nova_config('DEFAULT/pci_alias').with(
173           'value' => "[{\"vendor_id\":\"8086\",\"product_id\":\"0126\",\"name\":\"graphic_card\"},{\"vendor_id\":\"9096\",\"product_id\":\"1520\",\"name\":\"network_card\"}]"
174         )
175       end
176     end
177
178     [
179       '/keystone/',
180       'keystone/',
181       'keystone',
182       '/keystone/admin/',
183       'keystone/admin/',
184       'keystone/admin'
185     ].each do |auth_admin_prefix|
186       context "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do
187         before do
188           params.merge!({ :auth_admin_prefix => auth_admin_prefix })
189         end
190         it { expect { should contain_nova_config('keystone_authtoken/auth_admin_prefix') }.to \
191           raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/) }
192       end
193     end
194
195     context 'while validating the service with default command' do
196       before do
197         params.merge!({
198           :validate => true,
199         })
200       end
201       it { should contain_exec('execute nova-api validation').with(
202         :path        => '/usr/bin:/bin:/usr/sbin:/sbin',
203         :provider    => 'shell',
204         :tries       => '10',
205         :try_sleep   => '2',
206         :command     => 'nova --os-auth-url http://127.0.0.1:5000/ --os-tenant-name services --os-username nova --os-password passw0rd flavor-list',
207       )}
208
209       it { should contain_anchor('create nova-api anchor').with(
210         :require => 'Exec[execute nova-api validation]',
211       )}
212     end
213
214     context 'while validating the service with custom command' do
215       before do
216         params.merge!({
217           :validate            => true,
218           :validation_options  => { 'nova-api' => { 'command' => 'my-script' } }
219         })
220       end
221       it { should contain_exec('execute nova-api validation').with(
222         :path        => '/usr/bin:/bin:/usr/sbin:/sbin',
223         :provider    => 'shell',
224         :tries       => '10',
225         :try_sleep   => '2',
226         :command     => 'my-script',
227       )}
228
229       it { should contain_anchor('create nova-api anchor').with(
230         :require => 'Exec[execute nova-api validation]',
231       )}
232     end
233
234     context 'while not managing service state' do
235       before do
236         params.merge!({
237           :enabled           => false,
238           :manage_service    => false,
239         })
240       end
241
242       it { should contain_service('nova-api').without_ensure }
243     end
244
245     context 'with default database parameters' do
246       let :pre_condition do
247         "include nova"
248       end
249
250       it { should_not contain_nova_config('database/connection') }
251       it { should_not contain_nova_config('database/slave_connection') }
252       it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
253     end
254
255     context 'with overridden database parameters' do
256       let :pre_condition do
257         "class { 'nova':
258            database_connection   => 'mysql://user:pass@db/db',
259            slave_connection      => 'mysql://user:pass@slave/db',
260            database_idle_timeout => '30',
261          }
262         "
263       end
264
265       it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
266       it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
267       it { should contain_nova_config('database/idle_timeout').with_value('30') }
268     end
269
270   end
271
272   context 'on Debian platforms' do
273     before do
274       facts.merge!( :osfamily => 'Debian' )
275     end
276
277     let :platform_params do
278       { :nova_api_package => 'nova-api',
279         :nova_api_service => 'nova-api' }
280     end
281
282     it_behaves_like 'nova-api'
283   end
284
285   context 'on RedHat platforms' do
286     before do
287       facts.merge!( :osfamily => 'RedHat' )
288     end
289
290     let :platform_params do
291       { :nova_api_package => 'openstack-nova-api',
292         :nova_api_service => 'openstack-nova-api' }
293     end
294
295     it_behaves_like 'nova-api'
296   end
297
298 end