Configure database parameters on the right nodes
Since Grizzly, nova-compute does not need database access anymore. Currently, only nova-api, nova-scheduler and nova-conductor really need database access. * Keep original nova parameters with backward compatibility * Create nova::db with database parameters * Import nova::db in nova::init for backward compatibility * Import nova::db in nova::{api,conductor,scheduler} * Refactorize unit tests for conductor & scheduler Change-Id: I42b9d2b1efb5856fed6550c25ac3142952690df1 Implements: blueprint move-db-params
This commit is contained in:
@@ -170,6 +170,7 @@ class nova::api(
|
|||||||
$conductor_workers = undef,
|
$conductor_workers = undef,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
include nova::db
|
||||||
include nova::params
|
include nova::params
|
||||||
include nova::policy
|
include nova::policy
|
||||||
require keystone::python
|
require keystone::python
|
||||||
|
@@ -27,6 +27,7 @@ class nova::conductor(
|
|||||||
$workers = undef,
|
$workers = undef,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
include nova::db
|
||||||
include nova::params
|
include nova::params
|
||||||
|
|
||||||
nova::generic_service { 'conductor':
|
nova::generic_service { 'conductor':
|
||||||
|
56
manifests/db.pp
Normal file
56
manifests/db.pp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
||||||
|
#
|
||||||
|
# Author: Emilien Macchi <emilien.macchi@enovance.com>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
# == Class: nova::db
|
||||||
|
# Configures the nova database.
|
||||||
|
#
|
||||||
|
# == Parameters
|
||||||
|
#
|
||||||
|
# [*database_connection*]
|
||||||
|
# (optional) Connection url to connect to nova database.
|
||||||
|
# Defaults to undef
|
||||||
|
#
|
||||||
|
# [*database_idle_timeout*]
|
||||||
|
# (optional) Timeout before idle db connections are reaped.
|
||||||
|
# Defaults to undef
|
||||||
|
#
|
||||||
|
class nova::db (
|
||||||
|
$database_connection = undef,
|
||||||
|
$database_idle_timeout = undef,
|
||||||
|
) {
|
||||||
|
|
||||||
|
$database_connection_real = pick($database_connection, $::nova::database_connection, false)
|
||||||
|
$database_idle_timeout_real = pick($database_idle_timeout, $::nova::database_idle_timeout, false)
|
||||||
|
|
||||||
|
if $database_connection_real {
|
||||||
|
if($database_connection_real =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
|
||||||
|
require 'mysql::bindings'
|
||||||
|
require 'mysql::bindings::python'
|
||||||
|
} elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
|
||||||
|
|
||||||
|
} elsif($database_connection_real =~ /sqlite:\/\//) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fail("Invalid db connection ${database_connection_real}")
|
||||||
|
}
|
||||||
|
nova_config {
|
||||||
|
'database/connection': value => $database_connection_real, secret => true;
|
||||||
|
'database/idle_timeout': value => $database_idle_timeout_real;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -283,6 +283,9 @@ class nova(
|
|||||||
$os_region_name = undef,
|
$os_region_name = undef,
|
||||||
) inherits nova::params {
|
) inherits nova::params {
|
||||||
|
|
||||||
|
# maintain backward compatibility
|
||||||
|
include nova::db
|
||||||
|
|
||||||
if $mysql_module {
|
if $mysql_module {
|
||||||
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
||||||
}
|
}
|
||||||
@@ -416,25 +419,6 @@ class nova(
|
|||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
# both the database_connection and rabbit_host are things
|
|
||||||
# that may need to be collected from a remote host
|
|
||||||
if $database_connection {
|
|
||||||
if($database_connection =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
|
|
||||||
require 'mysql::bindings'
|
|
||||||
require 'mysql::bindings::python'
|
|
||||||
} elsif($database_connection =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
|
|
||||||
|
|
||||||
} elsif($database_connection =~ /sqlite:\/\//) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fail("Invalid db connection ${database_connection}")
|
|
||||||
}
|
|
||||||
nova_config {
|
|
||||||
'database/connection': value => $database_connection, secret => true;
|
|
||||||
'database/idle_timeout': value => $database_idle_timeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nova_config { 'DEFAULT/image_service': value => $image_service }
|
nova_config { 'DEFAULT/image_service': value => $image_service }
|
||||||
|
|
||||||
if $image_service == 'nova.image.glance.GlanceImageService' {
|
if $image_service == 'nova.image.glance.GlanceImageService' {
|
||||||
|
@@ -22,6 +22,7 @@ class nova::scheduler(
|
|||||||
$ensure_package = 'present'
|
$ensure_package = 'present'
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
include nova::db
|
||||||
include nova::params
|
include nova::params
|
||||||
|
|
||||||
nova::generic_service { 'scheduler':
|
nova::generic_service { 'scheduler':
|
||||||
|
@@ -223,6 +223,29 @@ describe 'nova::api' do
|
|||||||
|
|
||||||
it { should contain_service('nova-api').without_ensure }
|
it { should contain_service('nova-api').without_ensure }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with default database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"include nova"
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should_not contain_nova_config('database/connection') }
|
||||||
|
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with overridden database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"class { 'nova':
|
||||||
|
database_connection => 'mysql://user:pass@db/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/idle_timeout').with_value('30') }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on Debian platforms' do
|
context 'on Debian platforms' do
|
||||||
|
@@ -6,42 +6,98 @@ describe 'nova::conductor' do
|
|||||||
'include nova'
|
'include nova'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{ :enabled => true }
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples 'nova-conductor' do
|
||||||
|
|
||||||
|
|
||||||
|
it { should contain_package('nova-conductor').with(
|
||||||
|
:name => platform_params[:conductor_package_name],
|
||||||
|
:ensure => 'present'
|
||||||
|
) }
|
||||||
|
|
||||||
|
it { should contain_service('nova-conductor').with(
|
||||||
|
:name => platform_params[:conductor_service_name],
|
||||||
|
:hasstatus => 'true',
|
||||||
|
:ensure => 'running'
|
||||||
|
)}
|
||||||
|
|
||||||
|
context 'with manage_service as false' do
|
||||||
|
let :params do
|
||||||
|
{ :enabled => true,
|
||||||
|
:manage_service => false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it { should contain_service('nova-conductor').without_ensure }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with package version' do
|
||||||
|
let :params do
|
||||||
|
{ :ensure_package => '2012.1-2' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should contain_package('nova-conductor').with(
|
||||||
|
:ensure => params[:ensure_package]
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with overriden workers parameter' do
|
||||||
|
before do
|
||||||
|
params.merge!({:workers => '5' })
|
||||||
|
end
|
||||||
|
it { should contain_nova_config('conductor/workers').with_value('5') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with default database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"include nova"
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should_not contain_nova_config('database/connection') }
|
||||||
|
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with overridden database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"class { 'nova':
|
||||||
|
database_connection => 'mysql://user:pass@db/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/idle_timeout').with_value('30') }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context 'on Debian platforms' do
|
context 'on Debian platforms' do
|
||||||
let :facts do
|
let :facts do
|
||||||
{ :osfamily => 'Debian' }
|
{ :osfamily => 'Debian' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'generic nova service', {
|
let :platform_params do
|
||||||
:name => 'nova-conductor',
|
{ :conductor_package_name => 'nova-conductor',
|
||||||
:package_name => 'nova-conductor',
|
:conductor_service_name => 'nova-conductor' }
|
||||||
:service_name => 'nova-conductor' }
|
|
||||||
|
|
||||||
it { should_not contain_nova_config('conductor/workers') }
|
|
||||||
|
|
||||||
describe 'when overriding params' do
|
|
||||||
let :params do
|
|
||||||
{:workers => '5' }
|
|
||||||
end
|
|
||||||
it { should contain_nova_config('conductor/workers').with_value('5') }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-conductor'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on RedHat platforms' do
|
context 'on Redhat platforms' do
|
||||||
let :facts do
|
let :facts do
|
||||||
{ :osfamily => 'RedHat' }
|
{ :osfamily => 'RedHat' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'generic nova service', {
|
let :platform_params do
|
||||||
:name => 'nova-conductor',
|
{ :conductor_package_name => 'openstack-nova-conductor',
|
||||||
:package_name => 'openstack-nova-conductor',
|
:conductor_service_name => 'openstack-nova-conductor' }
|
||||||
:service_name => 'openstack-nova-conductor' }
|
|
||||||
it { should_not contain_nova_config('conductor/workers') }
|
|
||||||
|
|
||||||
describe 'when overriding params' do
|
|
||||||
let :params do
|
|
||||||
{:workers => '5' }
|
|
||||||
end
|
|
||||||
it { should contain_nova_config('conductor/workers').with_value('5') }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-conductor'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
46
spec/classes/nova_db_spec.rb
Normal file
46
spec/classes/nova_db_spec.rb
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'nova::db' do
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples 'nova-db' do
|
||||||
|
|
||||||
|
context 'with default parameters' do
|
||||||
|
it { should_not contain_nova_config('database/connection') }
|
||||||
|
it { should_not contain_nova_config('database/idle_timeout') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with overriden parameters' do
|
||||||
|
before :each do
|
||||||
|
params.merge!(
|
||||||
|
:database_connection => 'mysql://user:pass@db/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/idle_timeout').with_value('30') }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Debian platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'Debian' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-db'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Redhat platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'RedHat' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-db'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@@ -48,11 +48,6 @@ describe 'nova' do
|
|||||||
:refreshonly => true
|
:refreshonly => true
|
||||||
)}
|
)}
|
||||||
|
|
||||||
it 'configures database' do
|
|
||||||
should_not contain_nova_config('database/connection')
|
|
||||||
should_not contain_nova_config('database/idle_timeout').with_value('3600')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'configures image service' do
|
it 'configures image service' do
|
||||||
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.glance.GlanceImageService')
|
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.glance.GlanceImageService')
|
||||||
should contain_nova_config('glance/api_servers').with_value('localhost:9292')
|
should contain_nova_config('glance/api_servers').with_value('localhost:9292')
|
||||||
@@ -96,9 +91,7 @@ describe 'nova' do
|
|||||||
context 'with overridden parameters' do
|
context 'with overridden parameters' do
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
{ :database_connection => 'mysql://user:pass@db/db',
|
{ :verbose => true,
|
||||||
:database_idle_timeout => '30',
|
|
||||||
:verbose => true,
|
|
||||||
:debug => true,
|
:debug => true,
|
||||||
:log_dir => '/var/log/nova2',
|
:log_dir => '/var/log/nova2',
|
||||||
:image_service => 'nova.image.local.LocalImageService',
|
:image_service => 'nova.image.local.LocalImageService',
|
||||||
@@ -126,11 +119,6 @@ describe 'nova' do
|
|||||||
should contain_package('python-nova').with('ensure' => '2012.1.1-15.el6')
|
should contain_package('python-nova').with('ensure' => '2012.1.1-15.el6')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configures database' do
|
|
||||||
should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true)
|
|
||||||
should contain_nova_config('database/idle_timeout').with_value('30')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'configures image service' do
|
it 'configures image service' do
|
||||||
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.local.LocalImageService')
|
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.local.LocalImageService')
|
||||||
should_not contain_nova_config('glance/api_servers')
|
should_not contain_nova_config('glance/api_servers')
|
||||||
|
@@ -6,25 +6,91 @@ describe 'nova::scheduler' do
|
|||||||
'include nova'
|
'include nova'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{ :enabled => true }
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples 'nova-scheduler' do
|
||||||
|
|
||||||
|
|
||||||
|
it { should contain_package('nova-scheduler').with(
|
||||||
|
:name => platform_params[:scheduler_package_name],
|
||||||
|
:ensure => 'present'
|
||||||
|
) }
|
||||||
|
|
||||||
|
it { should contain_service('nova-scheduler').with(
|
||||||
|
:name => platform_params[:scheduler_service_name],
|
||||||
|
:hasstatus => 'true',
|
||||||
|
:ensure => 'running'
|
||||||
|
)}
|
||||||
|
|
||||||
|
context 'with manage_service as false' do
|
||||||
|
let :params do
|
||||||
|
{ :enabled => true,
|
||||||
|
:manage_service => false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it { should contain_service('nova-scheduler').without_ensure }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with package version' do
|
||||||
|
let :params do
|
||||||
|
{ :ensure_package => '2012.1-2' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should contain_package('nova-scheduler').with(
|
||||||
|
:ensure => params[:ensure_package]
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with default database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"include nova"
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should_not contain_nova_config('database/connection') }
|
||||||
|
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with overridden database parameters' do
|
||||||
|
let :pre_condition do
|
||||||
|
"class { 'nova':
|
||||||
|
database_connection => 'mysql://user:pass@db/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/idle_timeout').with_value('30') }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context 'on Debian platforms' do
|
context 'on Debian platforms' do
|
||||||
let :facts do
|
let :facts do
|
||||||
{ :osfamily => 'Debian' }
|
{ :osfamily => 'Debian' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'generic nova service', {
|
let :platform_params do
|
||||||
:name => 'nova-scheduler',
|
{ :scheduler_package_name => 'nova-scheduler',
|
||||||
:package_name => 'nova-scheduler',
|
:scheduler_service_name => 'nova-scheduler' }
|
||||||
:service_name => 'nova-scheduler' }
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-scheduler'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on RedHat platforms' do
|
context 'on Redhat platforms' do
|
||||||
let :facts do
|
let :facts do
|
||||||
{ :osfamily => 'RedHat' }
|
{ :osfamily => 'RedHat' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'generic nova service', {
|
let :platform_params do
|
||||||
:name => 'nova-scheduler',
|
{ :scheduler_package_name => 'openstack-nova-scheduler',
|
||||||
:package_name => 'openstack-nova-scheduler',
|
:scheduler_service_name => 'openstack-nova-scheduler' }
|
||||||
:service_name => 'openstack-nova-scheduler' }
|
end
|
||||||
|
|
||||||
|
it_configures 'nova-scheduler'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user