2 describe 'glance::registry' do
10 let :default_params do
14 :bind_host => '0.0.0.0',
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',
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,
36 {:keystone_password => 'ChangeMe'},
40 :bind_host => '127.0.0.1',
42 :database_connection => 'sqlite:///var/lib/glance.sqlite',
43 :database_idle_timeout => '360',
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',
57 describe "when #{param_set == {:keystone_password => 'ChangeMe'} ? "using default" : "specifying"} class parameters" do
59 default_params.merge(param_set)
66 it { should contain_class 'glance::registry' }
68 it { should contain_service('glance-registry').with(
69 'ensure' => (param_hash[:manage_service] && param_hash[:enabled]) ? 'running' : 'stopped',
70 'enable' => param_hash[:enabled],
73 'subscribe' => 'File[/etc/glance/glance-registry.conf]',
74 'require' => 'Class[Glance]'
77 it 'should only sync the db if the service is enabled' do
79 if param_hash[:enabled]
80 should contain_exec('glance-manage db_sync').with(
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]'
90 it 'should not sync the db if sync_db is set to false' do
92 if param_hash[:enabled] and !param_hash[:sync_db]
93 is_expected.not_to contain_exec('glance-manage db_sync')
96 it 'should configure itself' do
103 should contain_glance_registry_config("DEFAULT/#{config}").with_value(param_hash[config.intern])
106 'database_connection',
107 'database_idle_timeout',
109 should contain_glance_registry_config("database/#{config.gsub(/database_/,'')}").with_value(param_hash[config.intern])
116 should contain_glance_registry_config("keystone_authtoken/#{config}").with_value(param_hash[config.intern])
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)
130 describe 'with disabled service managing' do
133 :keystone_password => 'ChangeMe',
134 :manage_service => false,
139 it { should contain_service('glance-registry').with(
143 'hasrestart' => true,
144 'subscribe' => 'File[/etc/glance/glance-registry.conf]',
145 'require' => 'Class[Glance]'
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.
154 :keystone_password => 'ChangeMe',
155 :pipeline => 'validoptionstring',
159 it { should contain_glance_registry_config('paste_deploy/flavor').with_value('validoptionstring') }
162 describe 'with blank pipeline' do
165 :keystone_password => 'ChangeMe',
170 it { should contain_glance_registry_config('paste_deploy/flavor').with_ensure('absent') }
177 'keystone+cachemanagement+',
180 describe "with pipeline incorrect value #{pipeline}" do
183 :keystone_password => 'ChangeMe',
184 :auth_type => 'keystone',
185 :pipeline => pipeline
189 it { expect { should contain_glance_registry_config('filter:paste_deploy/flavor') }.to\
190 raise_error(Puppet::Error, /validate_re\(\): .* does not match/) }
194 describe 'with overriden auth_admin_prefix' do
197 :keystone_password => 'ChangeMe',
198 :auth_admin_prefix => '/keystone/main'
202 it { should contain_glance_registry_config('keystone_authtoken/auth_admin_prefix').with_value('/keystone/main') }
212 ].each do |auth_admin_prefix|
213 describe "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do
216 :keystone_password => 'ChangeMe',
217 :auth_admin_prefix => auth_admin_prefix
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/) }
226 describe 'with syslog disabled by default' do
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') }
235 describe 'with syslog enabled' do
237 default_params.merge({
238 :use_syslog => 'true',
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') }
246 describe 'with syslog enabled and custom settings' do
248 default_params.merge({
249 :use_syslog => 'true',
250 :log_facility => 'LOG_LOCAL0'
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') }
258 describe 'with log_file enabled by default' do
259 let(:params) { default_params }
261 it { should contain_glance_registry_config('DEFAULT/log_file').with_value(default_params[:log_file]) }
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') }
269 describe 'with log_dir enabled by default' do
270 let(:params) { default_params }
272 it { should contain_glance_registry_config('DEFAULT/log_dir').with_value(default_params[:log_dir]) }
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') }
280 describe 'with no ssl options (default)' do
281 let(:params) { default_params }
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')}
288 describe 'with ssl options' do
290 default_params.merge({
291 :ca_file => '/tmp/ca_file',
292 :cert_file => '/tmp/cert_file',
293 :key_file => '/tmp/key_file'
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') }
304 describe 'with deprecated sql parameters' do
306 default_params.merge({
307 :sql_connection => 'mysql://user:pass@db/db',
308 :sql_idle_timeout => '30'
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')
318 describe 'on Debian platforms' do
320 { :osfamily => 'Debian' }
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']
336 describe 'on RedHat platforms' do
338 { :osfamily => 'RedHat' }
340 let(:params) { default_params }
342 it { should contain_package('openstack-glance')}
345 describe 'on unknown platforms' do
347 { :osfamily => 'unknown' }
349 let(:params) { default_params }
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/)