Migrate mysql backend to use openstacklib::db::mysql
Implements: blueprint commmon-openstack-database-resource Change-Id: Iaffbc561941461fde7de61af88c02f1ba1197db7
This commit is contained in:
parent
7c0121234b
commit
99c7fab85e
@ -6,6 +6,7 @@ fixtures:
|
||||
'mysql':
|
||||
repo: 'git://github.com/puppetlabs/puppetlabs-mysql.git'
|
||||
ref: 'origin/2.2.x'
|
||||
'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
|
||||
'postgresql':
|
||||
repo: 'git://github.com/puppetlabs/puppet-postgresql.git'
|
||||
ref: '2.5.0'
|
||||
|
@ -10,6 +10,6 @@ source 'https://github.com/stackforge/puppet-cinder'
|
||||
dependency 'dprince/qpid', '>=1.0.0 <2.0.0'
|
||||
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/rabbitmq', '>=2.0.2 <4.0.0'
|
||||
dependency 'puppetlabs/stdlib', '>=4.0.0'
|
||||
dependency 'stackforge/openstacklib', '>=5.0.0'
|
||||
|
@ -163,7 +163,6 @@ Limitations
|
||||
|
||||
* Setup of storage nodes is limited to Linux and LVM, i.e. Puppet won't configure a Nexenta appliance but nova can be configured to use the Nexenta driver with Class['cinder::volume::nexenta'].
|
||||
|
||||
* The Cinder 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,7 +1,33 @@
|
||||
# [*mysql_module*]
|
||||
# (optional) The puppet-mysql module version to use.
|
||||
# Tested versions include 0.9 and 2.2
|
||||
# Defaults to '2.2'
|
||||
# The cinder::db::mysql class creates a MySQL database for cinder.
|
||||
# It must be used on the MySQL server
|
||||
#
|
||||
# == Parameters
|
||||
#
|
||||
# [*password*]
|
||||
# password to connect to the database. Mandatory.
|
||||
#
|
||||
# [*dbname*]
|
||||
# name of the database. Optional. Defaults to cinder.
|
||||
#
|
||||
# [*user*]
|
||||
# user to connect to the database. Optional. Defaults to cinder.
|
||||
#
|
||||
# [*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 cinder::db::mysql (
|
||||
$password,
|
||||
@ -12,51 +38,24 @@ class cinder::db::mysql (
|
||||
$charset = 'utf8',
|
||||
$collate = 'utf8_unicode_ci',
|
||||
$cluster_id = 'localzone',
|
||||
$mysql_module = '2.2'
|
||||
$mysql_module = undef,
|
||||
) {
|
||||
|
||||
Class['cinder::db::mysql'] -> Exec<| title == 'cinder-manage db_sync' |>
|
||||
|
||||
if ($mysql_module >= 2.2) {
|
||||
Mysql_database[$dbname] ~> Exec<| title == 'cinder-manage db_sync' |>
|
||||
|
||||
mysql::db { $dbname:
|
||||
user => $user,
|
||||
password => $password,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
} else {
|
||||
Database[$dbname] ~> Exec<| title == 'cinder-manage db_sync' |>
|
||||
|
||||
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.')
|
||||
}
|
||||
|
||||
validate_string($password)
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
if $real_allowed_hosts {
|
||||
# TODO this class should be in the mysql namespace
|
||||
cinder::db::mysql::host_access { $real_allowed_hosts:
|
||||
user => $user,
|
||||
password => $password,
|
||||
database => $dbname,
|
||||
mysql_module => $mysql_module,
|
||||
}
|
||||
::openstacklib::db::mysql { 'cinder':
|
||||
user => $user,
|
||||
password_hash => mysql_password($password),
|
||||
dbname => $dbname,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
|
||||
::Openstacklib::Db::Mysql['cinder'] ~> Exec<| title == 'cinder-manage db_sync' |>
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
#
|
||||
# Used to grant access to the cinder mysql DB
|
||||
#
|
||||
define cinder::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),
|
||||
provider => 'mysql',
|
||||
require => Mysql_database[$database],
|
||||
}
|
||||
|
||||
mysql_grant { "${user}@${name}/${database}.*":
|
||||
privileges => ['ALL'],
|
||||
options => ['GRANT'],
|
||||
provider => 'mysql',
|
||||
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}"]
|
||||
}
|
||||
}
|
||||
}
|
@ -65,9 +65,7 @@
|
||||
# Defaults to false, not set_
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) Puppetlabs-mysql module version to use
|
||||
# Tested versions include 0.9 and 2.2
|
||||
# Defaults to '2.2'
|
||||
# (optional) Deprecated. Does nothing.
|
||||
#
|
||||
# [*storage_availability_zone*]
|
||||
# (optional) Availability zone of the node.
|
||||
@ -126,10 +124,10 @@ class cinder (
|
||||
$log_dir = '/var/log/cinder',
|
||||
$verbose = false,
|
||||
$debug = false,
|
||||
$mysql_module = '2.2',
|
||||
$storage_availability_zone = 'nova',
|
||||
$default_availability_zone = false,
|
||||
# DEPRECATED PARAMETERS
|
||||
$mysql_module = undef,
|
||||
$sql_connection = undef,
|
||||
$sql_idle_timeout = undef,
|
||||
) {
|
||||
@ -139,6 +137,10 @@ class cinder (
|
||||
Package['cinder'] -> Cinder_config<||>
|
||||
Package['cinder'] -> Cinder_api_paste_ini<||>
|
||||
|
||||
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
|
||||
@ -299,12 +301,8 @@ class cinder (
|
||||
}
|
||||
|
||||
if($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'
|
||||
} elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
|
||||
|
||||
} elsif($database_connection_real =~ /sqlite:\/\//) {
|
||||
|
@ -4,7 +4,7 @@ describe 'cinder::db::mysql' do
|
||||
|
||||
let :req_params do
|
||||
{:password => 'pw',
|
||||
:mysql_module => '0.9'}
|
||||
}
|
||||
end
|
||||
|
||||
let :facts do
|
||||
@ -19,11 +19,11 @@ describe 'cinder::db::mysql' do
|
||||
let :params do
|
||||
req_params
|
||||
end
|
||||
it { should contain_mysql__db('cinder').with(
|
||||
:user => 'cinder',
|
||||
:password => 'pw',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8'
|
||||
it { should contain_openstacklib__db__mysql('cinder').with(
|
||||
:user => 'cinder',
|
||||
:password_hash => '*D821809F681A40A6E379B50D0463EFAE20BDD122',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8'
|
||||
) }
|
||||
end
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
@ -34,16 +34,6 @@ describe 'cinder::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_cinder__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'cinder',
|
||||
:password => 'cinderpass',
|
||||
:database => 'cinder'
|
||||
)}
|
||||
it {should contain_cinder__db__mysql__host_access("%").with(
|
||||
:user => 'cinder',
|
||||
:password => 'cinderpass',
|
||||
:database => 'cinder'
|
||||
)}
|
||||
end
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
let :params do
|
||||
@ -53,11 +43,6 @@ describe 'cinder::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should contain_cinder__db__mysql__host_access("192.168.1.1").with(
|
||||
:user => 'cinder',
|
||||
:password => 'cinderpass2',
|
||||
:database => 'cinder'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
@ -68,10 +53,5 @@ describe 'cinder::db::mysql' do
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_cinder__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'cinder',
|
||||
:password => 'cinderpass2',
|
||||
:database => 'cinder'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user