Migrate mysql backend to use openstacklib::db::mysql
Implements: blueprint commmon-openstack-database-resource Change-Id: I181ffa8ead34d37c4a5dacf2aecb3dd0506a5173
This commit is contained in:
parent
48aa3fbbe2
commit
513602100d
@ -7,6 +7,7 @@ fixtures:
|
||||
repo: "git://github.com/puppetlabs/puppetlabs-mysql.git"
|
||||
ref: 'origin/2.2.x'
|
||||
"nova": "git://github.com/stackforge/puppet-nova.git"
|
||||
"openstacklib": "git://github.com/stackforge/puppet-openstacklib.git"
|
||||
"vswitch": "git://github.com/stackforge/puppet-vswitch"
|
||||
'sysctl': 'git://github.com/duritong/puppet-sysctl.git'
|
||||
symlinks:
|
||||
|
@ -9,8 +9,8 @@ source 'https://github.com/stackforge/puppet-neutron'
|
||||
|
||||
dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0'
|
||||
dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0'
|
||||
dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0'
|
||||
dependency 'puppetlabs/nova', '>=4.0.0 <5.0.0'
|
||||
dependency 'puppetlabs/stdlib', '>=3.2.0'
|
||||
dependency 'puppetlabs/vswitch', '>=0.2.0 <1.0.0'
|
||||
dependency 'duritong/sysctl', '>=0.0.1 <1.0.0'
|
||||
dependency 'stackforge/openstacklib', '>=5.0.0'
|
||||
|
@ -109,7 +109,6 @@ The following platforms are supported:
|
||||
* RHEL 6
|
||||
* Fedora 18
|
||||
|
||||
* The Neutron Openstack service depends on a sqlalchemy database. If you are using puppetlabs-mysql to achieve this, there is a parameter called mysql_module that can be used to swap between the two supported versions: 0.9 and 2.2. This is needed because the puppetlabs-mysql module was rewritten and the custom type names have changed between versions.
|
||||
Development
|
||||
-----------
|
||||
|
||||
|
@ -1,8 +1,33 @@
|
||||
# The neutron::db::mysql class creates a MySQL database for neutron.
|
||||
# It must be used on the MySQL server
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) The mysql puppet module version to use. Tested versions
|
||||
# include 0.9 and 2.2
|
||||
# Default to '2.2'
|
||||
# == Parameters
|
||||
#
|
||||
# [*password*]
|
||||
# password to connect to the database. Mandatory.
|
||||
#
|
||||
# [*dbname*]
|
||||
# name of the database. Optional. Defaults to neutron.
|
||||
#
|
||||
# [*user*]
|
||||
# user to connect to the database. Optional. Defaults to neutron.
|
||||
#
|
||||
# [*host*]
|
||||
# the default source host user is allowed to connect from.
|
||||
# Optional. Defaults to 'localhost'
|
||||
#
|
||||
# [*allowed_hosts*]
|
||||
# other hosts the user is allowd to connect from.
|
||||
# Optional. Defaults to undef.
|
||||
#
|
||||
# [*charset*]
|
||||
# the database charset. Optional. Defaults to 'utf8'
|
||||
#
|
||||
# [*collate*]
|
||||
# the database collation. Optional. Defaults to 'utf8_unicode_ci'
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) Deprecated. Does nothing.
|
||||
#
|
||||
class neutron::db::mysql (
|
||||
$password,
|
||||
@ -13,43 +38,24 @@ class neutron::db::mysql (
|
||||
$charset = 'utf8',
|
||||
$collate = 'utf8_unicode_ci',
|
||||
$cluster_id = 'localzone',
|
||||
$mysql_module = '2.2'
|
||||
$mysql_module = undef,
|
||||
) {
|
||||
|
||||
if ($mysql_module >= 2.2) {
|
||||
mysql::db { $dbname:
|
||||
user => $user,
|
||||
password => $password,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
require => Class['mysql::server'],
|
||||
} -> Service <| title == 'neutron-server' |>
|
||||
} else {
|
||||
require mysql::python
|
||||
|
||||
mysql::db { $dbname:
|
||||
user => $user,
|
||||
password => $password,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
require => Class['mysql::config'],
|
||||
}
|
||||
if $mysql_module {
|
||||
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
||||
}
|
||||
|
||||
# Check allowed_hosts to avoid duplicate resource declarations
|
||||
if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] {
|
||||
$real_allowed_hosts = delete($allowed_hosts,$host)
|
||||
} elsif is_string($allowed_hosts) and ($allowed_hosts != $host) {
|
||||
$real_allowed_hosts = $allowed_hosts
|
||||
}
|
||||
validate_string($password)
|
||||
|
||||
if $real_allowed_hosts {
|
||||
neutron::db::mysql::host_access { $real_allowed_hosts:
|
||||
user => $user,
|
||||
password => $password,
|
||||
database => $dbname,
|
||||
mysql_module => $mysql_module,
|
||||
}
|
||||
|
||||
::openstacklib::db::mysql { 'neutron':
|
||||
user => $user,
|
||||
password_hash => mysql_password($password),
|
||||
dbname => $dbname,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
::Openstacklib::Db::Mysql['neutron'] ~> Service <| title == 'neutron-server' |>
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
#
|
||||
# Used to grant access to the neutron mysql DB
|
||||
#
|
||||
define neutron::db::mysql::host_access ($user, $password, $database, $mysql_module = '2.2') {
|
||||
if ($mysql_module >= 2.2) {
|
||||
mysql_user { "${user}@${name}":
|
||||
password_hash => mysql_password($password),
|
||||
require => Mysql_database[$database],
|
||||
}
|
||||
|
||||
mysql_grant { "${user}@${name}/${database}.*":
|
||||
privileges => ['ALL'],
|
||||
options => ['GRANT'],
|
||||
table => "${database}.*",
|
||||
require => Mysql_user["${user}@${name}"],
|
||||
user => "${user}@${name}"
|
||||
}
|
||||
} else {
|
||||
database_user { "${user}@${name}":
|
||||
password_hash => mysql_password($password),
|
||||
provider => 'mysql',
|
||||
require => Database[$database],
|
||||
}
|
||||
database_grant { "${user}@${name}/${database}":
|
||||
# TODO figure out which privileges to grant.
|
||||
privileges => 'all',
|
||||
provider => 'mysql',
|
||||
require => Database_user["${user}@${name}"]
|
||||
}
|
||||
}
|
||||
}
|
@ -130,9 +130,7 @@
|
||||
# Defaults to: neutron.scheduler.l3_agent_scheduler.ChanceScheduler
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) Mysql puppet module version to use. Tested versions
|
||||
# include 0.9 and 2.2
|
||||
# Defaults to: '2.2'
|
||||
# (optional) Deprecated. Does nothing.
|
||||
#
|
||||
class neutron::server (
|
||||
$package_ensure = 'present',
|
||||
@ -155,8 +153,8 @@ class neutron::server (
|
||||
$api_workers = '0',
|
||||
$agent_down_time = '75',
|
||||
$router_scheduler_driver = 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler',
|
||||
$mysql_module = '2.2',
|
||||
# DEPRECATED PARAMETERS
|
||||
$mysql_module = undef,
|
||||
$sql_connection = undef,
|
||||
$connection = undef,
|
||||
$sql_max_retries = undef,
|
||||
@ -177,6 +175,10 @@ class neutron::server (
|
||||
Neutron_config<||> ~> Service['neutron-server']
|
||||
Neutron_api_config<||> ~> Service['neutron-server']
|
||||
|
||||
if $mysql_module {
|
||||
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
||||
}
|
||||
|
||||
if $sql_connection {
|
||||
warning('The sql_connection parameter is deprecated, use database_connection instead.')
|
||||
$database_connection_real = $sql_connection
|
||||
@ -233,12 +235,8 @@ class neutron::server (
|
||||
|
||||
case $database_connection_real {
|
||||
/mysql:\/\/\S+:\S+@\S+\/\S+/: {
|
||||
if ($mysql_module >= 2.2) {
|
||||
require 'mysql::bindings'
|
||||
require 'mysql::bindings::python'
|
||||
} else {
|
||||
require 'mysql::python'
|
||||
}
|
||||
require 'mysql::bindings'
|
||||
require 'mysql::bindings::python'
|
||||
}
|
||||
/postgresql:\/\/\S+:\S+@\S+\/\S+/: {
|
||||
$backend_package = 'python-psycopg2'
|
||||
|
@ -8,7 +8,6 @@ describe 'neutron::db::mysql' do
|
||||
|
||||
let :params do
|
||||
{ :password => 'passw0rd',
|
||||
:mysql_module => '2.2'
|
||||
}
|
||||
end
|
||||
let :facts do
|
||||
@ -21,7 +20,12 @@ describe 'neutron::db::mysql' do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
it { should contain_class('neutron::db::mysql') }
|
||||
it { should contain_openstacklib__db__mysql('neutron').with(
|
||||
:user => 'neutron',
|
||||
:password_hash => '*74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8'
|
||||
) }
|
||||
end
|
||||
|
||||
context 'on RedHat platforms' do
|
||||
@ -29,7 +33,12 @@ describe 'neutron::db::mysql' do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
it { should contain_class('neutron::db::mysql') }
|
||||
it { should contain_openstacklib__db__mysql('neutron').with(
|
||||
:user => 'neutron',
|
||||
:password_hash => '*74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8'
|
||||
) }
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
@ -40,16 +49,6 @@ describe 'neutron::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_neutron__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'neutron',
|
||||
:password => 'neutronpass',
|
||||
:database => 'neutron'
|
||||
)}
|
||||
it {should contain_neutron__db__mysql__host_access("%").with(
|
||||
:user => 'neutron',
|
||||
:password => 'neutronpass',
|
||||
:database => 'neutron'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
@ -60,11 +59,6 @@ describe 'neutron::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should contain_neutron__db__mysql__host_access("192.168.1.1").with(
|
||||
:user => 'neutron',
|
||||
:password => 'neutronpass2',
|
||||
:database => 'neutron'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
@ -75,11 +69,6 @@ describe 'neutron::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_neutron__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'neutron',
|
||||
:password => 'neutronpass2',
|
||||
:database => 'neutron'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,7 +27,7 @@ describe 'neutron::server' do
|
||||
:api_workers => '0',
|
||||
:agent_down_time => '75',
|
||||
:router_scheduler_driver => 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler',
|
||||
:mysql_module => '0.9'}
|
||||
}
|
||||
end
|
||||
|
||||
shared_examples_for 'a neutron server' do
|
||||
|
@ -1,25 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'neutron::db::mysql::host_access' do
|
||||
|
||||
let :pre_condition do
|
||||
'include mysql::server'
|
||||
end
|
||||
|
||||
let :title do
|
||||
'127.0.0.1'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{ :user => 'neutron',
|
||||
:password => 'passw0rd',
|
||||
:database => 'neutron' }
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
it { should contain_mysql_user('neutron@127.0.0.1') }
|
||||
it { should contain_mysql_grant('neutron@127.0.0.1/neutron.*') }
|
||||
end
|
Loading…
Reference in New Issue
Block a user