diff --git a/recipes/cinder-common.rb b/recipes/cinder-common.rb index 125c613..4128ecd 100644 --- a/recipes/cinder-common.rb +++ b/recipes/cinder-common.rb @@ -33,6 +33,9 @@ end db_user = node['openstack']['db']['block-storage']['username'] db_pass = get_password 'db', 'cinder' sql_connection = db_uri('block-storage', db_user, db_pass) +if node['openstack']['endpoints']['db']['enabled_slave'] + slave_connection = db_uri('block-storage', db_user, db_pass, true) +end mq_service_type = node['openstack']['mq']['block-storage']['service_type'] @@ -100,6 +103,7 @@ template '/etc/cinder/cinder.conf' do mode 00640 variables( sql_connection: sql_connection, + slave_connection: slave_connection, mq_service_type: mq_service_type, mq_password: mq_password, rabbit_hosts: rabbit_hosts, diff --git a/spec/cinder_common_spec.rb b/spec/cinder_common_spec.rb index dacc1e0..40c928f 100644 --- a/spec/cinder_common_spec.rb +++ b/spec/cinder_common_spec.rb @@ -275,11 +275,25 @@ describe 'openstack-block-storage::cinder-common' do end it 'has a db connection attribute' do + node.set['openstack']['endpoints']['db']['enabled_slave'] = false allow_any_instance_of(Chef::Recipe).to receive(:db_uri) - .with('block-storage', anything, '').and_return('sql_connection_value') + .and_return('sql_connection_value') expect(chef_run).to render_config_file(file.name) .with_section_content('database', /^connection=sql_connection_value$/) + expect(chef_run).to_not render_config_file(file.name) + .with_section_content('database', /^slave_connection=sql_connection_value$/) + end + + it 'has a slave db connection attribute' do + node.set['openstack']['endpoints']['db']['enabled_slave'] = true + allow_any_instance_of(Chef::Recipe).to receive(:db_uri) + .and_return('sql_connection_value') + + expect(chef_run).to render_config_file(file.name) + .with_section_content('database', /^connection=sql_connection_value$/) + expect(chef_run).to render_config_file(file.name) + .with_section_content('database', /^slave_connection=sql_connection_value$/) end it 'has a db backend attribute' do diff --git a/templates/default/cinder.conf.erb b/templates/default/cinder.conf.erb index e66c2cc..7401f47 100644 --- a/templates/default/cinder.conf.erb +++ b/templates/default/cinder.conf.erb @@ -1031,6 +1031,9 @@ connection=<%= @sql_connection %> # sql_connection_debug=0 #### (IntOpt) Verbosity of SQL debugging information. 0=None, #### 100=Everything +<% if node['openstack']['endpoints']['db']['enabled_slave'] %> +slave_connection=<%= @slave_connection %> +<% end %> [keymgr]