try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / glance / spec / classes / glance_registry_spec.rb
1
2 describe 'glance::registry' do
3
4   let :facts do
5     {
6       :osfamily => 'Debian'
7     }
8   end
9
10   let :default_params do
11     {
12       :verbose                => false,
13       :debug                  => false,
14       :bind_host              => '0.0.0.0',
15       :bind_port              => '9191',
16       :log_file               => '/var/log/glance/registry.log',
17       :log_dir                => '/var/log/glance',
18       :database_connection    => 'sqlite:///var/lib/glance/glance.sqlite',
19       :database_idle_timeout  => '3600',
20       :enabled                => true,
21       :manage_service         => true,
22       :auth_type              => 'keystone',
23       :auth_host              => '127.0.0.1',
24       :auth_port              => '35357',
25       :auth_protocol          => 'http',
26       :auth_uri               => 'http://127.0.0.1:5000/',
27       :keystone_tenant        => 'services',
28       :keystone_user          => 'glance',
29       :keystone_password      => 'ChangeMe',
30       :purge_config           => false,
31       :sync_db                => true,
32     }
33   end
34
35   [
36     {:keystone_password => 'ChangeMe'},
37     {
38       :verbose                => true,
39       :debug                  => true,
40       :bind_host              => '127.0.0.1',
41       :bind_port              => '9111',
42       :database_connection    => 'sqlite:///var/lib/glance.sqlite',
43       :database_idle_timeout  => '360',
44       :enabled                => false,
45       :auth_type              => 'keystone',
46       :auth_host              => '127.0.0.1',
47       :auth_port              => '35357',
48       :auth_protocol          => 'http',
49       :auth_uri               => 'http://127.0.0.1:5000/',
50       :keystone_tenant        => 'admin',
51       :keystone_user          => 'admin',
52       :keystone_password      => 'ChangeMe',
53       :sync_db                => false,
54     }
55   ].each do |param_set|
56
57     describe "when #{param_set == {:keystone_password => 'ChangeMe'} ? "using default" : "specifying"} class parameters" do
58       let :param_hash do
59         default_params.merge(param_set)
60       end
61
62       let :params do
63         param_set
64       end
65
66       it { should contain_class 'glance::registry' }
67
68       it { should contain_service('glance-registry').with(
69           'ensure'     => (param_hash[:manage_service] && param_hash[:enabled]) ? 'running' : 'stopped',
70           'enable'     => param_hash[:enabled],
71           'hasstatus'  => true,
72           'hasrestart' => true,
73           'subscribe'  => 'File[/etc/glance/glance-registry.conf]',
74           'require'    => 'Class[Glance]'
75       )}
76
77       it 'should only sync the db if the service is enabled' do
78
79         if param_hash[:enabled]
80           should contain_exec('glance-manage db_sync').with(
81             'path'        => '/usr/bin',
82             'command'     => 'glance-manage --config-file=/etc/glance/glance-registry.conf db_sync',
83             'refreshonly' => true,
84             'logoutput'   => 'on_failure',
85             'subscribe'   => ['Package[glance-registry]', 'File[/etc/glance/glance-registry.conf]'],
86             'notify'      => 'Service[glance-registry]'
87           )
88         end
89       end
90       it 'should not sync the db if sync_db is set to false' do
91
92         if param_hash[:enabled] and !param_hash[:sync_db]
93           is_expected.not_to contain_exec('glance-manage db_sync')
94         end
95       end
96       it 'should configure itself' do
97         [
98          'verbose',
99          'debug',
100          'bind_port',
101          'bind_host',
102         ].each do |config|
103           should contain_glance_registry_config("DEFAULT/#{config}").with_value(param_hash[config.intern])
104         end
105         [
106          'database_connection',
107          'database_idle_timeout',
108         ].each do |config|
109           should contain_glance_registry_config("database/#{config.gsub(/database_/,'')}").with_value(param_hash[config.intern])
110         end
111         [
112          'auth_host',
113          'auth_port',
114          'auth_protocol'
115         ].each do |config|
116           should contain_glance_registry_config("keystone_authtoken/#{config}").with_value(param_hash[config.intern])
117         end
118         should contain_glance_registry_config('keystone_authtoken/auth_admin_prefix').with_ensure('absent')
119         if param_hash[:auth_type] == 'keystone'
120           should contain_glance_registry_config("paste_deploy/flavor").with_value('keystone')
121           should contain_glance_registry_config("keystone_authtoken/admin_tenant_name").with_value(param_hash[:keystone_tenant])
122           should contain_glance_registry_config("keystone_authtoken/admin_user").with_value(param_hash[:keystone_user])
123           should contain_glance_registry_config("keystone_authtoken/admin_password").with_value(param_hash[:keystone_password])
124           should contain_glance_registry_config("keystone_authtoken/admin_password").with_value(param_hash[:keystone_password]).with_secret(true)
125         end
126       end
127     end
128   end
129
130   describe 'with disabled service managing' do
131     let :params do
132       {
133         :keystone_password => 'ChangeMe',
134         :manage_service => false,
135         :enabled        => false,
136       }
137     end
138
139     it { should contain_service('glance-registry').with(
140           'ensure'     => nil,
141           'enable'     => false,
142           'hasstatus'  => true,
143           'hasrestart' => true,
144           'subscribe'  => 'File[/etc/glance/glance-registry.conf]',
145           'require'    => 'Class[Glance]'
146       )}
147   end
148
149   describe 'with overridden pipeline' do
150     # At the time of writing there was only blank and keystone as options
151     # but there is no reason that there can't be more options in the future.
152     let :params do
153       {
154         :keystone_password => 'ChangeMe',
155         :pipeline          => 'validoptionstring',
156       }
157     end
158
159     it { should contain_glance_registry_config('paste_deploy/flavor').with_value('validoptionstring') }
160   end
161
162   describe 'with blank pipeline' do
163     let :params do
164       {
165         :keystone_password => 'ChangeMe',
166         :pipeline          => '',
167       }
168     end
169
170     it { should contain_glance_registry_config('paste_deploy/flavor').with_ensure('absent') }
171   end
172
173   [
174     'keystone/',
175     'keystone+',
176     '+keystone',
177     'keystone+cachemanagement+',
178     '+'
179   ].each do |pipeline|
180     describe "with pipeline incorrect value #{pipeline}" do
181       let :params do
182         {
183           :keystone_password => 'ChangeMe',
184           :auth_type         => 'keystone',
185           :pipeline          => pipeline
186         }
187       end
188
189       it { expect { should contain_glance_registry_config('filter:paste_deploy/flavor') }.to\
190         raise_error(Puppet::Error, /validate_re\(\): .* does not match/) }
191     end
192   end
193
194   describe 'with overriden auth_admin_prefix' do
195     let :params do
196       {
197         :keystone_password => 'ChangeMe',
198         :auth_admin_prefix => '/keystone/main'
199       }
200     end
201
202     it { should contain_glance_registry_config('keystone_authtoken/auth_admin_prefix').with_value('/keystone/main') }
203   end
204
205   [
206     '/keystone/',
207     'keystone/',
208     'keystone',
209     '/keystone/admin/',
210     'keystone/admin/',
211     'keystone/admin'
212   ].each do |auth_admin_prefix|
213     describe "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do
214       let :params do
215         {
216           :keystone_password => 'ChangeMe',
217           :auth_admin_prefix => auth_admin_prefix
218         }
219       end
220
221       it { expect { should contain_glance_registry_config('filter:authtoken/auth_admin_prefix') }.to\
222         raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/) }
223     end
224   end
225
226   describe 'with syslog disabled by default' do
227     let :params do
228       default_params
229     end
230
231     it { should contain_glance_registry_config('DEFAULT/use_syslog').with_value(false) }
232     it { should_not contain_glance_registry_config('DEFAULT/syslog_log_facility') }
233   end
234
235   describe 'with syslog enabled' do
236     let :params do
237       default_params.merge({
238         :use_syslog   => 'true',
239       })
240     end
241
242     it { should contain_glance_registry_config('DEFAULT/use_syslog').with_value(true) }
243     it { should contain_glance_registry_config('DEFAULT/syslog_log_facility').with_value('LOG_USER') }
244   end
245
246   describe 'with syslog enabled and custom settings' do
247     let :params do
248       default_params.merge({
249         :use_syslog   => 'true',
250         :log_facility => 'LOG_LOCAL0'
251      })
252     end
253
254     it { should contain_glance_registry_config('DEFAULT/use_syslog').with_value(true) }
255     it { should contain_glance_registry_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0') }
256   end
257
258   describe 'with log_file enabled by default' do
259     let(:params) { default_params }
260
261     it { should contain_glance_registry_config('DEFAULT/log_file').with_value(default_params[:log_file]) }
262
263     context 'with log_file disabled' do
264       let(:params) { default_params.merge!({ :log_file => false }) }
265       it { should contain_glance_registry_config('DEFAULT/log_file').with_ensure('absent') }
266     end
267   end
268
269   describe 'with log_dir enabled by default' do
270     let(:params) { default_params }
271
272     it { should contain_glance_registry_config('DEFAULT/log_dir').with_value(default_params[:log_dir]) }
273
274     context 'with log_dir disabled' do
275       let(:params) { default_params.merge!({ :log_dir => false }) }
276       it { should contain_glance_registry_config('DEFAULT/log_dir').with_ensure('absent') }
277     end
278   end
279
280   describe 'with no ssl options (default)' do
281     let(:params) { default_params }
282
283     it { should contain_glance_registry_config('DEFAULT/ca_file').with_ensure('absent')}
284     it { should contain_glance_registry_config('DEFAULT/cert_file').with_ensure('absent')}
285     it { should contain_glance_registry_config('DEFAULT/key_file').with_ensure('absent')}
286   end
287
288   describe 'with ssl options' do
289     let :params do
290       default_params.merge({
291         :ca_file     => '/tmp/ca_file',
292         :cert_file   => '/tmp/cert_file',
293         :key_file    => '/tmp/key_file'
294       })
295     end
296
297     context 'with ssl options' do
298       it { should contain_glance_registry_config('DEFAULT/ca_file').with_value('/tmp/ca_file') }
299       it { should contain_glance_registry_config('DEFAULT/cert_file').with_value('/tmp/cert_file') }
300       it { should contain_glance_registry_config('DEFAULT/key_file').with_value('/tmp/key_file') }
301     end
302   end
303
304   describe 'with deprecated sql parameters' do
305     let :params do
306       default_params.merge({
307         :sql_connection   => 'mysql://user:pass@db/db',
308         :sql_idle_timeout => '30'
309       })
310     end
311
312     it 'configures database' do
313       should contain_glance_registry_config('database/connection').with_value('mysql://user:pass@db/db')
314       should contain_glance_registry_config('database/idle_timeout').with_value('30')
315     end
316   end
317
318   describe 'on Debian platforms' do
319     let :facts do
320       { :osfamily => 'Debian' }
321     end
322
323     # We only test this on Debian platforms, since on RedHat there isn't a
324     # separate package for glance registry.
325     ['present', 'latest'].each do |package_ensure|
326       context "with package_ensure '#{package_ensure}'" do
327         let(:params) { default_params.merge({ :package_ensure => package_ensure }) }
328         it { should contain_package('glance-registry').with(
329             :ensure => package_ensure,
330             :tag    => ['openstack']
331         )}
332       end
333     end
334   end
335
336   describe 'on RedHat platforms' do
337     let :facts do
338       { :osfamily => 'RedHat' }
339     end
340     let(:params) { default_params }
341
342     it { should contain_package('openstack-glance')}
343   end
344
345   describe 'on unknown platforms' do
346     let :facts do
347       { :osfamily => 'unknown' }
348     end
349     let(:params) { default_params }
350
351     it 'should fails to configure glance-registry' do
352         expect { subject }.to raise_error(Puppet::Error, /module glance only support osfamily RedHat and Debian/)
353     end
354   end
355
356 end