diff --git a/manifests/compute.pp b/manifests/compute.pp index 9b79af30..4b6e842c 100644 --- a/manifests/compute.pp +++ b/manifests/compute.pp @@ -23,6 +23,11 @@ # (optional) Hostname or IP address to connect to nova database # Defaults to '127.0.0.1' # +# [*nova_db_use_slave*] +# (optional) Enable slave connection for nova, this assume +# the haproxy is used and mysql loadbalanced port for read operation is 3307 +# Defaults to false +# # [*nova_db_user*] # (optional) Username to connect to nova database # Defaults to 'nova' @@ -70,6 +75,7 @@ class cloud::compute( $nova_db_host = '127.0.0.1', + $nova_db_use_slave = false, $nova_db_user = 'nova', $nova_db_password = 'novapassword', $rabbit_hosts = ['127.0.0.1:5672'], @@ -128,6 +134,12 @@ class cloud::compute( nova_shell => '/bin/bash', } + if $nova_db_use_slave { + nova_config {'database/slave_connection': value => "mysql://${encoded_user}:${encoded_password}@${nova_db_host}:3307/nova?charset=utf8" } + } else { + nova_config {'database/slave_connection': ensure => absent } + } + class { 'nova::network::neutron': neutron_admin_password => $neutron_password, neutron_admin_auth_url => "${neutron_protocol}://${neutron_endpoint}:35357/v2.0", diff --git a/manifests/database/sql.pp b/manifests/database/sql.pp index 194f120e..cef86aa1 100644 --- a/manifests/database/sql.pp +++ b/manifests/database/sql.pp @@ -342,4 +342,12 @@ class cloud::database::sql ( inline_template('check inter 2000 rise 2 fall 5 port 9200 <% if @hostname != @galera_master_name -%>backup<% end %>') } + @@haproxy::balancermember{"${::fqdn}-readonly": + listening_service => 'galera_readonly_cluster', + server_names => $::hostname, + ipaddresses => $api_eth, + ports => '3306', + options => + inline_template('check inter 2000 rise 2 fall 5 port 9200 <% if @hostname == @galera_master_name -%>backup<% end %>') + } } diff --git a/manifests/loadbalancer.pp b/manifests/loadbalancer.pp index f81c2be3..0942e0ca 100644 --- a/manifests/loadbalancer.pp +++ b/manifests/loadbalancer.pp @@ -233,6 +233,7 @@ class cloud::loadbalancer( $vip_public_ip = ['127.0.0.1'], $vip_internal_ip = false, $galera_ip = ['127.0.0.1'], + $galera_slave = false, # Deprecated parameters $keepalived_interface = false, $keepalived_ipvs = false, @@ -500,6 +501,21 @@ class cloud::loadbalancer( }, bind_options => $galera_bind_options, } + if $galera_slave { + haproxy::listen { 'galera_readonly_cluster': + ipaddress => $galera_ip, + ports => 3307, + options => { + 'maxconn' => '1000', + 'mode' => 'tcp', + 'balance' => 'roundrobin', + 'option' => ['tcpka', 'tcplog', 'httpchk'], #httpchk mandatory expect 200 on port 9000 + 'timeout client' => '400s', + 'timeout server' => '400s', + }, + bind_options => $galera_bind_options, + } + } # Allow HAProxy to bind to a non-local IP address $haproxy_sysctl_settings = { diff --git a/spec/classes/cloud_compute_api_spec.rb b/spec/classes/cloud_compute_api_spec.rb index 64338e5a..31b32aa2 100644 --- a/spec/classes/cloud_compute_api_spec.rb +++ b/spec/classes/cloud_compute_api_spec.rb @@ -26,6 +26,7 @@ describe 'cloud::compute::api' do "class { 'cloud::compute': availability_zone => 'MyZone', nova_db_host => '10.0.0.1', + nova_db_use_slave => false, nova_db_user => 'nova', nova_db_password => 'secrete', rabbit_hosts => ['10.0.0.1'], @@ -75,6 +76,24 @@ describe 'cloud::compute::api' do should contain_nova_config('DEFAULT/glance_num_retries').with_value('10') end + it 'does not configure nova db slave' do + should contain_nova_config('database/slave_connection').with('ensure' => 'absent') + end + + context "when enabling nova db slave" do + let :pre_condition do + "class { 'cloud::compute': + nova_db_host => '10.0.0.1', + nova_db_use_slave => true, + nova_db_user => 'nova', + nova_db_password => 'secrete' }" + end + it 'configure nova db slave' do + should contain_nova_config('database/slave_connection').with( + 'value' => 'mysql://nova:secrete@10.0.0.1:3307/nova?charset=utf8') + end + end + it 'configure neutron on compute node' do should contain_class('nova::network::neutron').with( :neutron_admin_password => 'secrete', diff --git a/spec/classes/cloud_loadbalancer_spec.rb b/spec/classes/cloud_loadbalancer_spec.rb index a866e366..fef5142f 100644 --- a/spec/classes/cloud_loadbalancer_spec.rb +++ b/spec/classes/cloud_loadbalancer_spec.rb @@ -66,6 +66,7 @@ describe 'cloud::loadbalancer' do :spice_port => '6082', :vip_public_ip => '10.0.0.1', :galera_ip => '10.0.0.2', + :galera_slave => false, :horizon_ssl => false, :horizon_ssl_port => false, :ks_ceilometer_public_port => '8777', @@ -201,7 +202,7 @@ describe 'cloud::loadbalancer' do )} end # configure monitor haproxy listen - context 'configure monitor haproxy listen' do + context 'configure galera haproxy listen' do it { should contain_haproxy__listen('galera_cluster').with( :ipaddress => params[:galera_ip], :ports => '3306', @@ -216,6 +217,28 @@ describe 'cloud::loadbalancer' do )} end # configure monitor haproxy listen + context 'not configure galera slave haproxy listen' do + it { should_not contain_haproxy__listen('galera_readonly_cluster') } + end # configure monitor haproxy listen + + context 'configure galera slave haproxy listen' do + before do + params.merge!( :galera_slave => true ) + end + it { should contain_haproxy__listen('galera_readonly_cluster').with( + :ipaddress => params[:galera_ip], + :ports => '3307', + :options => { + 'maxconn' => '1000', + 'mode' => 'tcp', + 'balance' => 'roundrobin', + 'option' => ['tcpka','tcplog','httpchk'], + 'timeout client' => '400s', + 'timeout server' => '400s' + } + )} + end # configure monitor haproxy listen + # test backward compatibility context 'configure OpenStack binding on public network only' do it { should contain_haproxy__listen('spice_cluster').with(