try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / classes / neutron_server_spec.rb
1 require 'spec_helper'
2
3 describe 'neutron::server' do
4
5   let :pre_condition do
6     "class { 'neutron': rabbit_password => 'passw0rd' }"
7   end
8
9   let :params do
10     { :auth_password => 'passw0rd',
11       :auth_user     => 'neutron' }
12   end
13
14   let :default_params do
15     { :package_ensure           => 'present',
16       :enabled                  => true,
17       :auth_type                => 'keystone',
18       :auth_host                => 'localhost',
19       :auth_port                => '35357',
20       :auth_tenant              => 'services',
21       :auth_user                => 'neutron',
22       :database_connection      => 'sqlite:////var/lib/neutron/ovs.sqlite',
23       :database_max_retries     => '10',
24       :database_idle_timeout    => '3600',
25       :database_retry_interval  => '10',
26       :database_min_pool_size   => '1',
27       :database_max_pool_size   => '10',
28       :database_max_overflow    => '20',
29       :sync_db                  => false,
30       :agent_down_time          => '75',
31       :router_scheduler_driver  => 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler',
32       :router_distributed       => false,
33       :l3_ha                    => false,
34       :max_l3_agents_per_router => '3',
35       :min_l3_agents_per_router => '2',
36       :l3_ha_net_cidr           => '169.254.192.0/18'
37     }
38   end
39
40   shared_examples_for 'a neutron server' do
41     let :p do
42       default_params.merge(params)
43     end
44
45     it 'should perform default database configuration of' do
46       should contain_neutron_config('database/connection').with_value(p[:database_connection])
47       should contain_neutron_config('database/connection').with_secret( true )
48       should contain_neutron_config('database/max_retries').with_value(p[:database_max_retries])
49       should contain_neutron_config('database/idle_timeout').with_value(p[:database_idle_timeout])
50       should contain_neutron_config('database/retry_interval').with_value(p[:database_retry_interval])
51       should contain_neutron_config('database/min_pool_size').with_value(p[:database_min_pool_size])
52       should contain_neutron_config('database/max_pool_size').with_value(p[:database_max_pool_size])
53       should contain_neutron_config('database/max_overflow').with_value(p[:database_max_overflow])
54     end
55
56     it { should contain_class('neutron::params') }
57     it { should contain_class('neutron::policy') }
58
59     it 'configures authentication middleware' do
60       should contain_neutron_api_config('filter:authtoken/auth_host').with_value(p[:auth_host]);
61       should contain_neutron_api_config('filter:authtoken/auth_port').with_value(p[:auth_port]);
62       should contain_neutron_api_config('filter:authtoken/admin_tenant_name').with_value(p[:auth_tenant]);
63       should contain_neutron_api_config('filter:authtoken/admin_user').with_value(p[:auth_user]);
64       should contain_neutron_api_config('filter:authtoken/admin_password').with_value(p[:auth_password]);
65       should contain_neutron_api_config('filter:authtoken/admin_password').with_secret( true )
66       should contain_neutron_api_config('filter:authtoken/auth_admin_prefix').with(:ensure => 'absent')
67       should contain_neutron_api_config('filter:authtoken/auth_uri').with_value("http://localhost:5000/");
68     end
69
70     it 'installs neutron server package' do
71       if platform_params.has_key?(:server_package)
72         should contain_package('neutron-server').with(
73           :name   => platform_params[:server_package],
74           :ensure => p[:package_ensure]
75         )
76         should contain_package('neutron-server').with_before(/Neutron_api_config\[.+\]/)
77         should contain_package('neutron-server').with_before(/Neutron_config\[.+\]/)
78         should contain_package('neutron-server').with_before(/Service\[neutron-server\]/)
79       else
80         should contain_package('neutron').with_before(/Neutron_api_config\[.+\]/)
81       end
82     end
83
84     it 'configures neutron server service' do
85       should contain_service('neutron-server').with(
86         :name    => platform_params[:server_service],
87         :enable  => true,
88         :ensure  => 'running',
89         :require => 'Class[Neutron]'
90       )
91       should_not contain_exec('neutron-db-sync')
92       should contain_neutron_api_config('filter:authtoken/auth_admin_prefix').with(
93         :ensure => 'absent'
94       )
95       should contain_neutron_config('DEFAULT/api_workers').with_value(facts[:processorcount])
96       should contain_neutron_config('DEFAULT/rpc_workers').with_value(facts[:processorcount])
97       should contain_neutron_config('DEFAULT/agent_down_time').with_value(p[:agent_down_time])
98       should contain_neutron_config('DEFAULT/router_scheduler_driver').with_value(p[:router_scheduler_driver])
99     end
100
101     context 'with manage_service as false' do
102       before :each do
103         params.merge!(:manage_service => false)
104       end
105       it 'should not start/stop service' do
106         should contain_service('neutron-server').without_ensure
107       end
108     end
109
110     context 'with DVR enabled' do
111       before :each do
112         params.merge!(:router_distributed => true)
113       end
114       it 'should enable DVR' do
115         should contain_neutron_config('DEFAULT/router_distributed').with_value(true)
116       end
117     end
118
119     context 'with HA routers enabled' do
120       before :each do
121         params.merge!(:l3_ha => true)
122       end
123       it 'should enable HA routers' do
124         should contain_neutron_config('DEFAULT/l3_ha').with_value(true)
125         should contain_neutron_config('DEFAULT/max_l3_agents_per_router').with_value('3')
126         should contain_neutron_config('DEFAULT/min_l3_agents_per_router').with_value('2')
127         should contain_neutron_config('DEFAULT/l3_ha_net_cidr').with_value('169.254.192.0/18')
128       end
129     end
130
131     context 'with HA routers disabled' do
132       before :each do
133         params.merge!(:l3_ha => false)
134       end
135       it 'should disable HA routers' do
136         should contain_neutron_config('DEFAULT/l3_ha').with_value(false)
137       end
138     end
139
140     context 'with HA routers enabled with unlimited l3 agents per router' do
141       before :each do
142         params.merge!(:l3_ha                    => true,
143                       :max_l3_agents_per_router => '0' )
144       end
145       it 'should enable HA routers' do
146         should contain_neutron_config('DEFAULT/max_l3_agents_per_router').with_value('0')
147       end
148     end
149
150     context 'with HA routers enabled and wrong parameters' do
151       before :each do
152         params.merge!(:l3_ha                    => true,
153                       :max_l3_agents_per_router => '2',
154                       :min_l3_agents_per_router => '3' )
155       end
156       it 'should fail to configure HA routerd' do
157         expect { subject }.to raise_error(Puppet::Error, /min_l3_agents_per_router should be less than or equal to max_l3_agents_per_router./)
158       end
159     end
160   end
161
162   shared_examples_for 'a neutron server with auth_admin_prefix set' do
163     [ '/keystone', '/keystone/admin', '' ].each do |auth_admin_prefix|
164       describe "with keystone_auth_admin_prefix containing incorrect value #{auth_admin_prefix}" do
165         before do
166           params.merge!({
167             :auth_admin_prefix => auth_admin_prefix,
168           })
169         end
170         it do
171           should contain_neutron_api_config('filter:authtoken/auth_admin_prefix').with(
172             :value => params[:auth_admin_prefix]
173           )
174         end
175       end
176     end
177   end
178
179   shared_examples_for 'a neutron server with some incorrect auth_admin_prefix set' do
180     [ '/keystone/', 'keystone/', 'keystone' ].each do |auth_admin_prefix|
181       describe "with keystone_auth_admin_prefix containing incorrect value #{auth_admin_prefix}" do
182         before do
183           params.merge!({
184             :auth_admin_prefix => auth_admin_prefix,
185           })
186         end
187         it do
188           expect {
189             should contain_neutron_api_config('filter:authtoken/auth_admin_prefix')
190           }.to raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/)
191         end
192       end
193     end
194   end
195
196   shared_examples_for 'a neutron server with broken authentication' do
197     before do
198       params.delete(:auth_password)
199     end
200     it_raises 'a Puppet::Error', /auth_password must be set/
201   end
202
203   shared_examples_for 'a neutron server with removed log_dir parameter' do
204     before { params.merge!({ :log_dir  => '/var/log/neutron' })}
205     it_raises 'a Puppet::Error', /log_dir parameter is removed/
206   end
207
208   shared_examples_for 'a neutron server with removed log_file parameter' do
209     before { params.merge!({ :log_file  => '/var/log/neutron/blah.log' })}
210     it_raises 'a Puppet::Error', /log_file parameter is removed/
211   end
212
213   shared_examples_for 'a neutron server without database synchronization' do
214     before do
215       params.merge!(
216         :sync_db => true
217       )
218     end
219     it 'should exec neutron-db-sync' do
220       should contain_exec('neutron-db-sync').with(
221         :command     => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head',
222         :path        => '/usr/bin',
223         :before      => 'Service[neutron-server]',
224         :require     => 'Neutron_config[database/connection]',
225         :refreshonly => true
226       )
227     end
228   end
229
230   shared_examples_for 'a neutron server with deprecated parameters' do
231
232     context 'first generation' do
233       before do
234         params.merge!({
235           :sql_connection          => 'sqlite:////var/lib/neutron/ovs-deprecated_parameter.sqlite',
236           :database_connection     => 'sqlite:////var/lib/neutron/ovs-IGNORED_parameter.sqlite',
237           :sql_max_retries         => 20,
238           :database_max_retries    => 90,
239           :sql_idle_timeout        => 21,
240           :database_idle_timeout   => 91,
241           :sql_reconnect_interval  => 22,
242           :database_retry_interval => 92,
243         })
244       end
245
246       it 'configures database connection with deprecated parameters' do
247         should contain_neutron_config('database/connection').with_value(params[:sql_connection])
248         should contain_neutron_config('database/max_retries').with_value(params[:sql_max_retries])
249         should contain_neutron_config('database/idle_timeout').with_value(params[:sql_idle_timeout])
250         should contain_neutron_config('database/retry_interval').with_value(params[:sql_reconnect_interval])
251       end
252     end
253
254     context 'second generation' do
255       before do
256         params.merge!({
257           :connection              => 'sqlite:////var/lib/neutron/ovs-deprecated_parameter.sqlite',
258           :database_connection     => 'sqlite:////var/lib/neutron/ovs-IGNORED_parameter.sqlite',
259           :max_retries             => 20,
260           :database_max_retries    => 90,
261           :idle_timeout            => 21,
262           :database_idle_timeout   => 91,
263           :retry_interval          => 22,
264           :database_retry_interval => 92,
265         })
266       end
267
268       it 'configures database connection with deprecated parameters' do
269         should contain_neutron_config('database/connection').with_value(params[:connection])
270         should contain_neutron_config('database/max_retries').with_value(params[:max_retries])
271         should contain_neutron_config('database/idle_timeout').with_value(params[:idle_timeout])
272         should contain_neutron_config('database/retry_interval').with_value(params[:retry_interval])
273       end
274     end
275   end
276
277   shared_examples_for 'a neutron server with database_connection specified' do
278     before do
279       params.merge!(
280         :database_connection => 'sqlite:////var/lib/neutron/ovs-TEST_parameter.sqlite'
281       )
282     end
283     it 'configures database connection' do
284       should contain_neutron_config('database/connection').with_value(params[:database_connection])
285     end
286   end
287
288   describe "with custom keystone auth_uri" do
289     let :facts do
290       { :osfamily => 'RedHat' }
291     end
292     before do
293       params.merge!({
294         :auth_uri => 'https://foo.bar:1234/',
295       })
296     end
297     it 'configures auth_uri' do
298       should contain_neutron_api_config('filter:authtoken/auth_uri').with_value("https://foo.bar:1234/");
299     end
300   end
301
302   context 'on Debian platforms' do
303     let :facts do
304       { :osfamily => 'Debian',
305         :processorcount => '2' }
306     end
307
308     let :platform_params do
309       { :server_package => 'neutron-server',
310         :server_service => 'neutron-server' }
311     end
312
313     it_configures 'a neutron server'
314     it_configures 'a neutron server with broken authentication'
315     it_configures 'a neutron server with auth_admin_prefix set'
316     it_configures 'a neutron server with some incorrect auth_admin_prefix set'
317     it_configures 'a neutron server with deprecated parameters'
318     it_configures 'a neutron server with database_connection specified'
319     it_configures 'a neutron server without database synchronization'
320     it_configures 'a neutron server with removed log_file parameter'
321     it_configures 'a neutron server with removed log_dir parameter'
322   end
323
324   context 'on RedHat platforms' do
325     let :facts do
326       { :osfamily => 'RedHat',
327         :processorcount => '2' }
328     end
329
330     let :platform_params do
331       { :server_service => 'neutron-server' }
332     end
333
334     it_configures 'a neutron server'
335     it_configures 'a neutron server with broken authentication'
336     it_configures 'a neutron server with auth_admin_prefix set'
337     it_configures 'a neutron server with some incorrect auth_admin_prefix set'
338     it_configures 'a neutron server with deprecated parameters'
339     it_configures 'a neutron server with database_connection specified'
340     it_configures 'a neutron server without database synchronization'
341     it_configures 'a neutron server with removed log_file parameter'
342     it_configures 'a neutron server with removed log_dir parameter'
343   end
344 end