From 94d875d7e14edc98809c1061602b0e1c73d12642 Mon Sep 17 00:00:00 2001 From: Min Min Ren Date: Mon, 20 Jul 2015 05:40:20 -0500 Subject: [PATCH] Add database slave connection configure - According to the bool attribute node['openstack']['endpoints']['db']['enabled_slave'], enable/disable neutron database slave_connection - Add the slave_connection generated from db_uri function Implements: blueprint sql-slave-connection-support Change-Id: I19fc7fb4ab4a62fcdea77c9c4d18135fb2f49d41 --- recipes/default.rb | 4 ++++ spec/default_spec.rb | 9 +++++++++ templates/default/neutron.conf.erb | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/recipes/default.rb b/recipes/default.rb index dad78db6..3acecdab 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -155,6 +155,9 @@ identity_uri = identity_uri_transform(identity_admin_endpoint) db_user = node['openstack']['db']['network']['username'] db_pass = get_password 'db', 'neutron' sql_connection = db_uri('network', db_user, db_pass) +if node['openstack']['endpoints']['db']['enabled_slave'] + slave_connection = db_uri('network', db_user, db_pass, true) +end network_api_bind = endpoint 'network-api-bind' service_pass = get_password 'service', 'openstack-network' @@ -233,6 +236,7 @@ template '/etc/neutron/neutron.conf' do identity_admin_endpoint: identity_admin_endpoint, service_pass: service_pass, sql_connection: sql_connection, + slave_connection: slave_connection, nova_endpoint: nova_endpoint, nova_admin_pass: nova_admin_pass, nova_auth_url: nova_auth_url, diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 8cddf6b6..a5e180b1 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -893,6 +893,15 @@ describe 'openstack-network' do expect(chef_run).to render_file(file.name).with_content(/^connection = connection_value$/) end + it 'sets enabled_slave attribute' do + node.set['openstack']['endpoints']['db']['enabled_slave'] = true + node.set['openstack']['db']['network']['username'] = 'db_username_value' + allow_any_instance_of(Chef::Recipe).to receive(:db_uri) + .and_return('slave_connection_value') + expect(chef_run).to render_file(file.name) + .with_content(/^slave_connection = slave_connection_value$/) + end + %w(slave_connection max_retries retry_interval min_pool_size max_pool_size idle_timeout max_overflow connection_debug connection_trace pool_timeout).each do |attr| it "sets the #{attr} attribute" do diff --git a/templates/default/neutron.conf.erb b/templates/default/neutron.conf.erb index 5847039d..27157481 100644 --- a/templates/default/neutron.conf.erb +++ b/templates/default/neutron.conf.erb @@ -560,7 +560,11 @@ connection = <%= @sql_connection %> # engine = # The SQLAlchemy connection string used to connect to the slave database +<% if node['openstack']['endpoints']['db']['enabled_slave'] %> +slave_connection = <%= @slave_connection %> +<% else %> slave_connection = <%= node['openstack']['db']['network']['slave_connection'] %> +<% end %> # Database reconnection retry times - in event connectivity is lost # set to -1 implies an infinite retry count