Classes to create and sync new nova_api DB
Per Mitaka nova commit 8e8e839ef748be242fd0ad02e3ae233cc98da8b2 we now need to create and sync the 'nova_api' database. Closes-bug: #1539793 Co-Authored-By: Dan Prince <dprince@redhat.com> Co-Authored-By: Emilien Macchi <emilien@redhat.com> Change-Id: I234d2e9e219c6ea4235c3d3c5193b8924d6e6f8e
This commit is contained in:
parent
69870241d1
commit
1e12e9c45c
@ -106,6 +106,10 @@
|
||||
# (optional) Run nova-manage db sync on api nodes after installing the package.
|
||||
# Defaults to true
|
||||
#
|
||||
# [*sync_db_api*]
|
||||
# (optional) Run nova-manage api_db sync on api nodes after installing the package.
|
||||
# Defaults to false
|
||||
#
|
||||
# [*neutron_metadata_proxy_shared_secret*]
|
||||
# (optional) Shared secret to validate proxies Neutron metadata requests
|
||||
# Defaults to undef
|
||||
@ -178,6 +182,7 @@ class nova::api(
|
||||
$osapi_compute_workers = $::processorcount,
|
||||
$metadata_workers = $::processorcount,
|
||||
$sync_db = true,
|
||||
$sync_db_api = false,
|
||||
$neutron_metadata_proxy_shared_secret = undef,
|
||||
$osapi_v3 = false,
|
||||
$default_floating_pool = 'nova',
|
||||
@ -288,6 +293,9 @@ class nova::api(
|
||||
if $sync_db {
|
||||
include ::nova::db::sync
|
||||
}
|
||||
if $sync_db_api {
|
||||
include ::nova::db::sync_api
|
||||
}
|
||||
|
||||
# Remove auth configuration from api-paste.ini
|
||||
nova_paste_api_ini {
|
||||
|
@ -29,6 +29,14 @@
|
||||
# (optional) Connection url to connect to nova slave database (read-only).
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*api_database_connection*]
|
||||
# (optional) Connection url to connect to nova api database.
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*api_slave_connection*]
|
||||
# (optional) Connection url to connect to nova api slave database (read-only).
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*database_idle_timeout*]
|
||||
# Timeout when db connections should be reaped.
|
||||
# (Optional) Defaults to $::os_service_default
|
||||
@ -57,6 +65,8 @@
|
||||
class nova::db (
|
||||
$database_connection = $::os_service_default,
|
||||
$slave_connection = $::os_service_default,
|
||||
$api_database_connection = $::os_service_default,
|
||||
$api_slave_connection = $::os_service_default,
|
||||
$database_idle_timeout = $::os_service_default,
|
||||
$database_min_pool_size = $::os_service_default,
|
||||
$database_max_pool_size = $::os_service_default,
|
||||
@ -72,6 +82,8 @@ class nova::db (
|
||||
# to use nova::<myparam> first the nova::db::<myparam>
|
||||
$database_connection_real = pick($::nova::database_connection, $database_connection)
|
||||
$slave_connection_real = pick($::nova::slave_connection, $slave_connection)
|
||||
$api_database_connection_real = pick($::nova::api_database_connection, $api_database_connection)
|
||||
$api_slave_connection_real = pick($::nova::api_slave_connection, $api_slave_connection)
|
||||
$database_idle_timeout_real = pick($::nova::database_idle_timeout, $database_idle_timeout)
|
||||
$database_min_pool_size_real = pick($::nova::database_min_pool_size, $database_min_pool_size)
|
||||
$database_max_pool_size_real = pick($::nova::database_max_pool_size, $database_max_pool_size)
|
||||
@ -127,4 +139,16 @@ class nova::db (
|
||||
|
||||
}
|
||||
|
||||
if !is_service_default($api_database_connection_real) {
|
||||
|
||||
validate_re($api_database_connection_real,
|
||||
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
|
||||
nova_config {
|
||||
'api_database/connection': value => $api_database_connection_real, secret => true;
|
||||
'api_database/slave_connection': value => $api_slave_connection_real, secret => true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
59
manifests/db/mysql_api.pp
Normal file
59
manifests/db/mysql_api.pp
Normal file
@ -0,0 +1,59 @@
|
||||
# == Class: nova::db::mysql_api
|
||||
#
|
||||
# Class that configures mysql for the nova_api database.
|
||||
#
|
||||
# === Parameters:
|
||||
#
|
||||
# [*password*]
|
||||
# Password to use for the nova user
|
||||
#
|
||||
# [*dbname*]
|
||||
# (optional) The name of the database
|
||||
# Defaults to 'nova_api'
|
||||
#
|
||||
# [*user*]
|
||||
# (optional) The mysql user to create
|
||||
# Defaults to 'nova_api'
|
||||
#
|
||||
# [*host*]
|
||||
# (optional) The IP address of the mysql server
|
||||
# Defaults to '127.0.0.1'
|
||||
#
|
||||
# [*charset*]
|
||||
# (optional) The charset to use for the nova database
|
||||
# Defaults to 'utf8'
|
||||
#
|
||||
# [*collate*]
|
||||
# (optional) The collate to use for the nova database
|
||||
# Defaults to 'utf8_general_ci'
|
||||
#
|
||||
# [*allowed_hosts*]
|
||||
# (optional) Additional hosts that are allowed to access this DB
|
||||
# Defaults to undef
|
||||
#
|
||||
class nova::db::mysql_api(
|
||||
$password,
|
||||
$dbname = 'nova_api',
|
||||
$user = 'nova_api',
|
||||
$host = '127.0.0.1',
|
||||
$charset = 'utf8',
|
||||
$collate = 'utf8_general_ci',
|
||||
$allowed_hosts = undef,
|
||||
) {
|
||||
|
||||
include ::nova::deps
|
||||
|
||||
::openstacklib::db::mysql { 'nova_api':
|
||||
user => $user,
|
||||
password_hash => mysql_password($password),
|
||||
dbname => $dbname,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
|
||||
Anchor['nova::db::begin']
|
||||
~> Class['nova::db::mysql_api']
|
||||
~> Anchor['nova::db::end']
|
||||
}
|
48
manifests/db/postgresql_api.pp
Normal file
48
manifests/db/postgresql_api.pp
Normal file
@ -0,0 +1,48 @@
|
||||
# == Class: nova::db::postgresql_api
|
||||
#
|
||||
# Class that configures postgresql for the nova_api database.
|
||||
# Requires the Puppetlabs postgresql module.
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# [*password*]
|
||||
# (Required) Password to connect to the database.
|
||||
#
|
||||
# [*dbname*]
|
||||
# (Optional) Name of the database.
|
||||
# Defaults to 'nova_api'.
|
||||
#
|
||||
# [*user*]
|
||||
# (Optional) User to connect to the database.
|
||||
# Defaults to 'nova_api'.
|
||||
#
|
||||
# [*encoding*]
|
||||
# (Optional) The charset to use for the database.
|
||||
# Default to undef.
|
||||
#
|
||||
# [*privileges*]
|
||||
# (Optional) Privileges given to the database user.
|
||||
# Default to 'ALL'
|
||||
#
|
||||
class nova::db::postgresql_api(
|
||||
$password,
|
||||
$dbname = 'nova_api',
|
||||
$user = 'nova_api',
|
||||
$encoding = undef,
|
||||
$privileges = 'ALL',
|
||||
) {
|
||||
|
||||
include ::nova::deps
|
||||
|
||||
::openstacklib::db::postgresql { 'nova_api':
|
||||
password_hash => postgresql_password($user, $password),
|
||||
dbname => $dbname,
|
||||
user => $user,
|
||||
encoding => $encoding,
|
||||
privileges => $privileges,
|
||||
}
|
||||
|
||||
Anchor['nova::db::begin']
|
||||
~> Class['nova::db::postgresql_api']
|
||||
~> Anchor['nova::db::end']
|
||||
}
|
30
manifests/db/sync_api.pp
Normal file
30
manifests/db/sync_api.pp
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# Class to execute nova api_db sync
|
||||
#
|
||||
# ==Parameters
|
||||
#
|
||||
# [*extra_params*]
|
||||
# (optional) String of extra command line parameters to append
|
||||
# to the nova-manage db sync command. These will be inserted in
|
||||
# the command line between 'nova-manage' and 'db sync'.
|
||||
# Defaults to undef
|
||||
#
|
||||
class nova::db::sync_api(
|
||||
$extra_params = undef,
|
||||
) {
|
||||
|
||||
include ::nova::deps
|
||||
include ::nova::params
|
||||
|
||||
exec { 'nova-db-sync-api':
|
||||
command => "/usr/bin/nova-manage ${extra_params} api_db sync",
|
||||
refreshonly => true,
|
||||
logoutput => on_failure,
|
||||
subscribe => [
|
||||
Anchor['nova::install::end'],
|
||||
Anchor['nova::config::end'],
|
||||
Anchor['nova::dbsync_api::begin']
|
||||
],
|
||||
notify => Anchor['nova::dbsync_api::end'],
|
||||
}
|
||||
}
|
@ -17,6 +17,14 @@
|
||||
# (optional) Connection url to connect to nova slave database (read-only).
|
||||
# Defaults to undef.
|
||||
#
|
||||
# [*api_database_connection*]
|
||||
# (optional) Connection url for the nova API database.
|
||||
# Defaults to undef.
|
||||
#
|
||||
# [*api_slave_connection*]
|
||||
# (optional) Connection url to connect to nova API slave database (read-only).
|
||||
# Defaults to undef.
|
||||
#
|
||||
# [*database_max_retries*]
|
||||
# (optional) Maximum database connection retries during startup.
|
||||
# Defaults to undef.
|
||||
@ -338,6 +346,8 @@ class nova(
|
||||
$ensure_package = 'present',
|
||||
$database_connection = undef,
|
||||
$slave_connection = undef,
|
||||
$api_database_connection = undef,
|
||||
$api_slave_connection = undef,
|
||||
$database_idle_timeout = undef,
|
||||
$database_min_pool_size = undef,
|
||||
$database_max_pool_size = undef,
|
||||
|
@ -212,21 +212,32 @@ describe 'nova::api' do
|
||||
|
||||
it { is_expected.to_not contain_nova_config('database/connection') }
|
||||
it { is_expected.to_not contain_nova_config('database/slave_connection') }
|
||||
it { is_expected.to_not contain_nova_config('api_database/connection') }
|
||||
it { is_expected.to_not contain_nova_config('api_database/slave_connection') }
|
||||
it { is_expected.to_not contain_nova_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
|
||||
end
|
||||
|
||||
context 'with overridden database parameters' 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',
|
||||
database_connection => 'mysql://user:pass@db/db1',
|
||||
slave_connection => 'mysql://user:pass@slave/db1',
|
||||
api_database_connection => 'mysql://user:pass@db/db2',
|
||||
api_slave_connection => 'mysql://user:pass@slave/db2',
|
||||
database_idle_timeout => '30',
|
||||
}
|
||||
"
|
||||
end
|
||||
before do
|
||||
params.merge!({
|
||||
:sync_db_api => true,
|
||||
})
|
||||
end
|
||||
|
||||
it { is_expected.to contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/connection').with_value('mysql://user:pass@db/db1').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db1').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('api_database/connection').with_value('mysql://user:pass@db/db2').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('api_database/slave_connection').with_value('mysql://user:pass@slave/db2').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/idle_timeout').with_value('30') }
|
||||
end
|
||||
|
||||
|
105
spec/classes/nova_db_mysql_api_spec.rb
Normal file
105
spec/classes/nova_db_mysql_api_spec.rb
Normal file
@ -0,0 +1,105 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nova::db::mysql_api' do
|
||||
|
||||
let :pre_condition do
|
||||
'include mysql::server'
|
||||
end
|
||||
|
||||
let :required_params do
|
||||
{ :password => "qwerty" }
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({ :osfamily => "Debian" })
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
required_params
|
||||
end
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('nova_api').with(
|
||||
:user => 'nova_api',
|
||||
:password_hash => '*AA1420F182E88B9E5F874F6FBE7459291E8F4601',
|
||||
:charset => 'utf8',
|
||||
:collate => 'utf8_general_ci',
|
||||
)}
|
||||
end
|
||||
|
||||
context 'when overriding charset' do
|
||||
let :params do
|
||||
{ :charset => 'latin1' }.merge(required_params)
|
||||
end
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('nova_api').with_charset(params[:charset]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({ :osfamily => 'RedHat' })
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
required_params
|
||||
end
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('nova_api').with(
|
||||
:user => 'nova_api',
|
||||
:password_hash => '*AA1420F182E88B9E5F874F6FBE7459291E8F4601',
|
||||
:charset => 'utf8',
|
||||
:collate => 'utf8_general_ci',
|
||||
)}
|
||||
end
|
||||
|
||||
context 'when overriding charset' do
|
||||
let :params do
|
||||
{ :charset => 'latin1' }.merge(required_params)
|
||||
end
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('nova_api').with_charset(params[:charset]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
let :facts do
|
||||
@default_facts.merge({ :osfamily => "Debian" })
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass',
|
||||
:allowed_hosts => ['127.0.0.1','%']
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
let :facts do
|
||||
@default_facts.merge({ :osfamily => 'RedHat' })
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass2',
|
||||
:allowed_hosts => '192.168.1.1'
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
let :facts do
|
||||
@default_facts.merge({ :osfamily => 'RedHat' })
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass2',
|
||||
:allowed_hosts => '127.0.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
58
spec/classes/nova_db_postgresql_api_spec.rb
Normal file
58
spec/classes/nova_db_postgresql_api_spec.rb
Normal file
@ -0,0 +1,58 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nova::db::postgresql_api' do
|
||||
|
||||
let :req_params do
|
||||
{ :password => 'pw' }
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
'include postgresql::server'
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystemrelease => '7.0',
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
})
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
req_params
|
||||
end
|
||||
|
||||
it { is_expected.to contain_postgresql__server__db('nova_api').with(
|
||||
:user => 'nova_api',
|
||||
:password => 'md581802bf81b206888b50950e640d70549'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:operatingsystemrelease => '7.8',
|
||||
:operatingsystem => 'Debian',
|
||||
:osfamily => 'Debian',
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
})
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
req_params
|
||||
end
|
||||
|
||||
it { is_expected.to contain_postgresql__server__db('nova_api').with(
|
||||
:user => 'nova_api',
|
||||
:password => 'md581802bf81b206888b50950e640d70549'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -11,6 +11,8 @@ describe 'nova::db' do
|
||||
context 'with default parameters' do
|
||||
it { is_expected.to_not contain_nova_config('database/connection') }
|
||||
it { is_expected.to_not contain_nova_config('database/slave_connection') }
|
||||
it { is_expected.to_not contain_nova_config('api_database/connection') }
|
||||
it { is_expected.to_not contain_nova_config('api_database/slave_connection') }
|
||||
it { is_expected.to_not contain_nova_config('database/idle_timeout') }
|
||||
it { is_expected.to_not contain_nova_config('database/min_pool_size') }
|
||||
it { is_expected.to_not contain_nova_config('database/max_retries') }
|
||||
@ -20,13 +22,17 @@ describe 'nova::db' do
|
||||
context 'with overriden parameters' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
:database_connection => 'mysql+pymysql://user:pass@db/db',
|
||||
:slave_connection => 'mysql+pymysql://user:pass@slave/db',
|
||||
:database_connection => 'mysql+pymysql://user:pass@db/db1',
|
||||
:slave_connection => 'mysql+pymysql://user:pass@slave/db1',
|
||||
:api_database_connection => 'mysql+pymysql://user:pass@db/db2',
|
||||
:api_slave_connection => 'mysql+pymysql://user:pass@slave/db2',
|
||||
)
|
||||
end
|
||||
|
||||
it { is_expected.to contain_nova_config('database/connection').with_value('mysql+pymysql://user:pass@db/db').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/slave_connection').with_value('mysql+pymysql://user:pass@slave/db').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/connection').with_value('mysql+pymysql://user:pass@db/db1').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/slave_connection').with_value('mysql+pymysql://user:pass@slave/db1').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('api_database/connection').with_value('mysql+pymysql://user:pass@db/db2').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('api_database/slave_connection').with_value('mysql+pymysql://user:pass@slave/db2').with_secret(true) }
|
||||
it { is_expected.to contain_nova_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
|
||||
|
59
spec/classes/nova_db_sync_api_spec.rb
Normal file
59
spec/classes/nova_db_sync_api_spec.rb
Normal file
@ -0,0 +1,59 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nova::db::sync_api' do
|
||||
|
||||
shared_examples_for 'nova-dbsync-api' do
|
||||
|
||||
it 'runs nova-db-sync-api' do
|
||||
is_expected.to contain_exec('nova-db-sync-api').with(
|
||||
:command => '/usr/bin/nova-manage api_db sync',
|
||||
:refreshonly => 'true',
|
||||
:logoutput => 'on_failure'
|
||||
)
|
||||
end
|
||||
|
||||
describe "overriding extra_params" do
|
||||
let :params do
|
||||
{
|
||||
:extra_params => '--config-file /etc/nova/nova.conf',
|
||||
}
|
||||
end
|
||||
|
||||
it {
|
||||
is_expected.to contain_exec('nova-db-sync-api').with(
|
||||
:command => '/usr/bin/nova-manage --config-file /etc/nova/nova.conf api_db sync',
|
||||
:refreshonly => 'true',
|
||||
:logoutput => 'on_failure'
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystemrelease => '7.0',
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
})
|
||||
end
|
||||
|
||||
it_configures 'nova-dbsync-api'
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:operatingsystemrelease => '7.8',
|
||||
:operatingsystem => 'Debian',
|
||||
:osfamily => 'Debian',
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
})
|
||||
end
|
||||
|
||||
it_configures 'nova-dbsync-api'
|
||||
end
|
||||
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user