3 describe 'glance::api' do
8 :processorcount => '7',
12 let :default_params do
16 :bind_host => '0.0.0.0',
18 :registry_host => '0.0.0.0',
19 :registry_port => '9191',
20 :registry_client_protocol => 'http',
21 :log_file => '/var/log/glance/api.log',
22 :log_dir => '/var/log/glance',
23 :auth_type => 'keystone',
25 :manage_service => true,
28 :auth_host => '127.0.0.1',
29 :auth_port => '35357',
30 :auth_protocol => 'http',
31 :auth_uri => 'http://127.0.0.1:5000/',
32 :keystone_tenant => 'services',
33 :keystone_user => 'glance',
34 :keystone_password => 'ChangeMe',
35 :database_idle_timeout => '3600',
36 :database_connection => 'sqlite:///var/lib/glance/glance.sqlite',
37 :show_image_direct_url => false,
38 :purge_config => false,
39 :known_stores => false,
40 :image_cache_dir => '/var/lib/glance/image-cache',
41 :os_region_name => 'RegionOne',
45 [{:keystone_password => 'ChangeMe'},
49 :bind_host => '127.0.0.1',
51 :registry_host => '127.0.0.1',
52 :registry_port => '9111',
53 :registry_client_protocol => 'https',
54 :auth_type => 'not_keystone',
58 :auth_host => '127.0.0.2',
59 :auth_port => '35358',
60 :auth_protocol => 'https',
61 :auth_uri => 'https://127.0.0.2:5000/v2.0/',
62 :keystone_tenant => 'admin2',
63 :keystone_user => 'admin2',
64 :keystone_password => 'ChangeMe2',
65 :database_idle_timeout => '36002',
66 :database_connection => 'mysql:///var:lib@glance/glance',
67 :show_image_direct_url => true,
68 :image_cache_dir => '/tmp/glance',
69 :os_region_name => 'RegionOne2',
73 describe "when #{param_set == {:keystone_password => 'ChangeMe'} ? "using default" : "specifying"} class parameters" do
76 default_params.merge(param_set)
83 it { should contain_class 'glance' }
84 it { should contain_class 'glance::policy' }
86 it { should contain_service('glance-api').with(
87 'ensure' => (param_hash[:manage_service] && param_hash[:enabled]) ? 'running': 'stopped',
88 'enable' => param_hash[:enabled],
93 it { should_not contain_exec('validate_nova_api') }
95 it 'should lay down default api config' do
103 'registry_client_protocol',
104 'show_image_direct_url',
107 should contain_glance_api_config("DEFAULT/#{config}").with_value(param_hash[config.intern])
111 it 'should lay down default cache config' do
119 should contain_glance_cache_config("DEFAULT/#{config}").with_value(param_hash[config.intern])
123 it 'should config db' do
124 should contain_glance_api_config('database/connection').with_value(param_hash[:database_connection])
125 should contain_glance_api_config('database/connection').with_value(param_hash[:database_connection]).with_secret(true)
126 should contain_glance_api_config('database/idle_timeout').with_value(param_hash[:database_idle_timeout])
129 it 'should have no ssl options' do
130 should contain_glance_api_config('DEFAULT/ca_file').with_ensure('absent')
131 should contain_glance_api_config('DEFAULT/cert_file').with_ensure('absent')
132 should contain_glance_api_config('DEFAULT/key_file').with_ensure('absent')
135 it 'should lay down default auth config' do
141 should contain_glance_api_config("keystone_authtoken/#{config}").with_value(param_hash[config.intern])
144 it { should contain_glance_api_config('keystone_authtoken/auth_admin_prefix').with_ensure('absent') }
146 it 'should configure itself for keystone if that is the auth_type' do
147 if params[:auth_type] == 'keystone'
148 should contain('paste_deploy/flavor').with_value('keystone+cachemanagement')
150 ['admin_tenant_name', 'admin_user', 'admin_password'].each do |config|
151 should contain_glance_api_config("keystone_authtoken/#{config}").with_value(param_hash[config.intern])
153 should contain_glance_api_config('keystone_authtoken/admin_password').with_value(param_hash[:keystone_password]).with_secret(true)
155 ['admin_tenant_name', 'admin_user', 'admin_password'].each do |config|
156 should contain_glance_cache_config("keystone_authtoken/#{config}").with_value(param_hash[config.intern])
158 should contain_glance_cache_config('keystone_authtoken/admin_password').with_value(param_hash[:keystone_password]).with_secret(true)
165 describe 'with disabled service managing' do
168 :keystone_password => 'ChangeMe',
169 :manage_service => false,
174 it { should contain_service('glance-api').with(
182 describe 'with overridden pipeline' do
185 :keystone_password => 'ChangeMe',
186 :pipeline => 'keystone',
190 it { should contain_glance_api_config('paste_deploy/flavor').with_value('keystone') }
193 describe 'with blank pipeline' do
196 :keystone_password => 'ChangeMe',
201 it { should contain_glance_api_config('paste_deploy/flavor').with_ensure('absent') }
208 'keystone+cachemanagement+',
211 describe "with pipeline incorrect value #{pipeline}" do
214 :keystone_password => 'ChangeMe',
215 :pipeline => pipeline
219 it { expect { should contain_glance_api_config('filter:paste_deploy/flavor') }.to\
220 raise_error(Puppet::Error, /validate_re\(\): .* does not match/) }
224 describe 'with overriden auth_admin_prefix' do
227 :keystone_password => 'ChangeMe',
228 :auth_admin_prefix => '/keystone/main'
232 it { should contain_glance_api_config('keystone_authtoken/auth_admin_prefix').with_value('/keystone/main') }
242 ].each do |auth_admin_prefix|
243 describe "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do
246 :keystone_password => 'ChangeMe',
247 :auth_admin_prefix => auth_admin_prefix
251 it { expect { should contain_glance_api_config('filter:authtoken/auth_admin_prefix') }.to\
252 raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/) }
256 describe 'with syslog disabled by default' do
261 it { should contain_glance_api_config('DEFAULT/use_syslog').with_value(false) }
262 it { should_not contain_glance_api_config('DEFAULT/syslog_log_facility') }
265 describe 'with syslog enabled' do
267 default_params.merge({
268 :use_syslog => 'true',
272 it { should contain_glance_api_config('DEFAULT/use_syslog').with_value(true) }
273 it { should contain_glance_api_config('DEFAULT/syslog_log_facility').with_value('LOG_USER') }
276 describe 'with syslog enabled and custom settings' do
278 default_params.merge({
279 :use_syslog => 'true',
280 :log_facility => 'LOG_LOCAL0'
284 it { should contain_glance_api_config('DEFAULT/use_syslog').with_value(true) }
285 it { should contain_glance_api_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0') }
288 describe 'with log_file enabled by default' do
289 let(:params) { default_params }
291 it { should contain_glance_api_config('DEFAULT/log_file').with_value(default_params[:log_file]) }
293 context 'with log_file disabled' do
294 let(:params) { default_params.merge!({ :log_file => false }) }
295 it { should contain_glance_api_config('DEFAULT/log_file').with_ensure('absent') }
299 describe 'with log_dir enabled by default' do
300 let(:params) { default_params }
302 it { should contain_glance_api_config('DEFAULT/log_dir').with_value(default_params[:log_dir]) }
304 context 'with log_dir disabled' do
305 let(:params) { default_params.merge!({ :log_dir => false }) }
306 it { should contain_glance_api_config('DEFAULT/log_dir').with_ensure('absent') }
310 describe 'with ssl options' do
312 default_params.merge({
313 :ca_file => '/tmp/ca_file',
314 :cert_file => '/tmp/cert_file',
315 :key_file => '/tmp/key_file'
319 context 'with ssl options' do
320 it { should contain_glance_api_config('DEFAULT/ca_file').with_value('/tmp/ca_file') }
321 it { should contain_glance_api_config('DEFAULT/cert_file').with_value('/tmp/cert_file') }
322 it { should contain_glance_api_config('DEFAULT/key_file').with_value('/tmp/key_file') }
325 describe 'with known_stores by default' do
330 it { should_not contain_glance_api_config('glance_store/stores').with_value('false') }
333 describe 'with known_stores override' do
335 default_params.merge({
336 :known_stores => ['glance.store.filesystem.Store','glance.store.http.Store'],
340 it { should contain_glance_api_config('glance_store/stores').with_value("glance.store.filesystem.Store,glance.store.http.Store") }
343 describe 'with deprecated sql parameters' do
345 default_params.merge({
346 :sql_connection => 'mysql://user:pass@db/db',
347 :sql_idle_timeout => '30'
351 it 'configures database' do
352 should contain_glance_api_config('database/connection').with_value('mysql://user:pass@db/db')
353 should contain_glance_api_config('database/idle_timeout').with_value('30')
357 describe 'while validating the service with default command' do
359 default_params.merge({
363 it { should contain_exec('execute glance-api validation').with(
364 :path => '/usr/bin:/bin:/usr/sbin:/sbin',
365 :provider => 'shell',
368 :command => 'glance --os-auth-url http://localhost:5000/v2.0 --os-tenant-name services --os-username glance --os-password ChangeMe image-list',
371 it { should contain_anchor('create glance-api anchor').with(
372 :require => 'Exec[execute glance-api validation]',
376 describe 'while validating the service with custom command' do
378 default_params.merge({
380 :validation_options => { 'glance-api' => { 'command' => 'my-script' } }
383 it { should contain_exec('execute glance-api validation').with(
384 :path => '/usr/bin:/bin:/usr/sbin:/sbin',
385 :provider => 'shell',
388 :command => 'my-script',
391 it { should contain_anchor('create glance-api anchor').with(
392 :require => 'Exec[execute glance-api validation]',
396 describe 'on Debian platforms' do
398 { :osfamily => 'Debian' }
400 let(:params) { default_params }
402 it { should contain_package('glance-api').with(
403 :tag => ['openstack'],
407 describe 'on RedHat platforms' do
409 { :osfamily => 'RedHat' }
411 let(:params) { default_params }
413 it { should contain_package('openstack-glance').with(
414 :tag => ['openstack'],
418 describe 'on unknown platforms' do
420 { :osfamily => 'unknown' }
422 let(:params) { default_params }
424 it 'should fails to configure glance-api' do
425 expect { subject }.to raise_error(Puppet::Error, /module glance only support osfamily RedHat and Debian/)