From 1b2725b5518ba2fd422e3ea954efae4a763f9878 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 26 Jan 2015 16:10:54 -0500 Subject: [PATCH] Database: add slave_connection support Nova is able to talk to a read-only database for some tables so it improves the scalability of MySQL server and reduce the access to the server in charge of writes. More documentation: https://wiki.openstack.org/wiki/Slave_usage Change-Id: I1d44332acb381b11d90b63535d274f535be26d55 --- manifests/db.pp | 15 +++++++++++++++ manifests/init.pp | 5 +++++ spec/classes/nova_api_spec.rb | 3 +++ spec/classes/nova_conductor_spec.rb | 3 +++ spec/classes/nova_db_spec.rb | 3 +++ spec/classes/nova_scheduler_spec.rb | 3 +++ 6 files changed, 32 insertions(+) diff --git a/manifests/db.pp b/manifests/db.pp index 50f9798cd..850b9254e 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -24,16 +24,22 @@ # (optional) Connection url to connect to nova database. # Defaults to undef # +# [*slave_connection*] +# (optional) Connection url to connect to nova slave database (read-only). +# Defaults to undef +# # [*database_idle_timeout*] # (optional) Timeout before idle db connections are reaped. # Defaults to undef # class nova::db ( $database_connection = undef, + $slave_connection = undef, $database_idle_timeout = undef, ) { $database_connection_real = pick($database_connection, $::nova::database_connection, false) + $slave_connection_real = pick($slave_connection, $::nova::slave_connection, false) $database_idle_timeout_real = pick($database_idle_timeout, $::nova::database_idle_timeout, false) if $database_connection_real { @@ -51,6 +57,15 @@ class nova::db ( 'database/connection': value => $database_connection_real, secret => true; 'database/idle_timeout': value => $database_idle_timeout_real; } + if $slave_connection_real { + nova_config { + 'database/slave_connection': value => $slave_connection_real, secret => true; + } + } else { + nova_config { + 'database/slave_connection': ensure => absent; + } + } } } diff --git a/manifests/init.pp b/manifests/init.pp index 4630d8d0e..b520f195a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,6 +13,10 @@ # (optional) Connection url to connect to nova database. # Defaults to false # +# [*slave_connection*] +# (optional) Connection url to connect to nova slave database (read-only). +# Defaults to false +# # [*database_idle_timeout*] # (optional) Timeout before idle db connections are reaped. # Defaults to 3600 @@ -227,6 +231,7 @@ class nova( $ensure_package = 'present', $database_connection = false, + $slave_connection = false, $database_idle_timeout = 3600, $rpc_backend = 'rabbit', $image_service = 'nova.image.glance.GlanceImageService', diff --git a/spec/classes/nova_api_spec.rb b/spec/classes/nova_api_spec.rb index 9a6759709..716eba4da 100644 --- a/spec/classes/nova_api_spec.rb +++ b/spec/classes/nova_api_spec.rb @@ -230,6 +230,7 @@ describe 'nova::api' do end it { should_not contain_nova_config('database/connection') } + it { should_not contain_nova_config('database/slave_connection') } it { should_not contain_nova_config('database/idle_timeout').with_value('3600') } end @@ -237,12 +238,14 @@ describe 'nova::api' do let :pre_condition do "class { 'nova': database_connection => 'mysql://user:pass@db/db', + slave_connection => 'mysql://user:pass@slave/db', database_idle_timeout => '30', } " end it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) } + it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) } it { should contain_nova_config('database/idle_timeout').with_value('30') } end diff --git a/spec/classes/nova_conductor_spec.rb b/spec/classes/nova_conductor_spec.rb index f0f2e2cc8..1df7aad70 100644 --- a/spec/classes/nova_conductor_spec.rb +++ b/spec/classes/nova_conductor_spec.rb @@ -56,6 +56,7 @@ describe 'nova::conductor' do end it { should_not contain_nova_config('database/connection') } + it { should_not contain_nova_config('database/slave_connection') } it { should_not contain_nova_config('database/idle_timeout').with_value('3600') } end @@ -63,12 +64,14 @@ describe 'nova::conductor' do let :pre_condition do "class { 'nova': database_connection => 'mysql://user:pass@db/db', + slave_connection => 'mysql://user:pass@slave/db', database_idle_timeout => '30', } " end it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) } + it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) } it { should contain_nova_config('database/idle_timeout').with_value('30') } end diff --git a/spec/classes/nova_db_spec.rb b/spec/classes/nova_db_spec.rb index e7f296155..ec458b212 100644 --- a/spec/classes/nova_db_spec.rb +++ b/spec/classes/nova_db_spec.rb @@ -10,6 +10,7 @@ describe 'nova::db' do context 'with default parameters' do it { should_not contain_nova_config('database/connection') } + it { should_not contain_nova_config('database/slave_connection') } it { should_not contain_nova_config('database/idle_timeout') } end @@ -17,11 +18,13 @@ describe 'nova::db' do before :each do params.merge!( :database_connection => 'mysql://user:pass@db/db', + :slave_connection => 'mysql://user:pass@slave/db', :database_idle_timeout => '30', ) end it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) } + it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) } it { should contain_nova_config('database/idle_timeout').with_value('30') } end diff --git a/spec/classes/nova_scheduler_spec.rb b/spec/classes/nova_scheduler_spec.rb index c7a573265..46836974d 100644 --- a/spec/classes/nova_scheduler_spec.rb +++ b/spec/classes/nova_scheduler_spec.rb @@ -49,6 +49,7 @@ describe 'nova::scheduler' do end it { should_not contain_nova_config('database/connection') } + it { should_not contain_nova_config('database/slave_connection') } it { should_not contain_nova_config('database/idle_timeout').with_value('3600') } end @@ -56,12 +57,14 @@ describe 'nova::scheduler' do let :pre_condition do "class { 'nova': database_connection => 'mysql://user:pass@db/db', + slave_connection => 'mysql://user:pass@slave/db', database_idle_timeout => '30', } " end it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) } + it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) } it { should contain_nova_config('database/idle_timeout').with_value('30') } end