diff --git a/recipes/nova-common.rb b/recipes/nova-common.rb index 356a500e..c03dfdd3 100644 --- a/recipes/nova-common.rb +++ b/recipes/nova-common.rb @@ -77,6 +77,9 @@ end db_user = node['openstack']['db']['compute']['username'] db_pass = get_password 'db', 'nova' sql_connection = db_uri('compute', db_user, db_pass) +if node['openstack']['endpoints']['db']['enabled_slave'] + slave_connection = db_uri('compute', db_user, db_pass, true) +end mq_service_type = node['openstack']['mq']['compute']['service_type'] @@ -142,6 +145,7 @@ template '/etc/nova/nova.conf' do mode 00640 variables( sql_connection: sql_connection, + slave_connection: slave_connection, novncproxy_base_url: novnc_endpoint.to_s, xvpvncproxy_base_url: xvpvnc_endpoint.to_s, xvpvncproxy_bind_host: xvpvnc_bind.host, diff --git a/spec/nova-common_spec.rb b/spec/nova-common_spec.rb index 6f12035c..f1118a93 100644 --- a/spec/nova-common_spec.rb +++ b/spec/nova-common_spec.rb @@ -984,6 +984,28 @@ describe 'openstack-compute::nova-common' do end end end + + context 'set enabled_slave attribute' do + it 'sets overide database enabled_slave attribute as true' do + node.set['openstack']['endpoints']['db']['enabled_slave'] = true + node.set['openstack']['endpoints']['db']['slave_host'] = '10.10.1.1' + node.set['openstack']['endpoints']['db']['slave_port'] = '3326' + node.set['openstack']['db']['compute']['username'] = 'nova1' + + expect(chef_run).to render_config_file(file.name)\ + .with_section_content('database', %r{slave_connection=mysql://nova1:@10.10.1.1:3326/nova\?charset=utf8$}) + end + + it 'sets overide database enabled_slave attribute as false' do + node.set['openstack']['endpoints']['db']['enabled_slave'] = false + node.set['openstack']['endpoints']['db']['slave_host'] = '10.10.1.1' + node.set['openstack']['endpoints']['db']['slave_port'] = '3326' + node.set['openstack']['db']['compute']['username'] = 'nova1' + + expect(chef_run).to_not render_config_file(file.name)\ + .with_section_content('database', %r{slave_connection=mysql://nova1:@10.10.1.1:3326/nova\?charset=utf8$}) + end + end end describe 'rootwrap.conf' do diff --git a/templates/default/nova.conf.erb b/templates/default/nova.conf.erb index 9411090d..8c0d6728 100644 --- a/templates/default/nova.conf.erb +++ b/templates/default/nova.conf.erb @@ -339,6 +339,9 @@ connection=<%= @sql_connection %> # The SQLAlchemy connection string to use to connect to the # slave database. (string value) #slave_connection= +<% if node['openstack']['endpoints']['db']['enabled_slave'] %> +slave_connection=<%= @slave_connection %> +<% end %> # The SQL mode to be used for MySQL sessions. This option, # including the default, overrides any server-set SQL mode. To