Migrate mysql backend to use openstacklib::db::mysql
Implements: blueprint commmon-openstack-database-resource Change-Id: I03bd33d7c78ea69702650688c28e9d0b7cac2911
This commit is contained in:
parent
82f4a55342
commit
dbcb82fa36
|
@ -5,6 +5,7 @@ fixtures:
|
|||
"mysql":
|
||||
repo: "git://github.com/puppetlabs/puppetlabs-mysql.git"
|
||||
ref: 'origin/2.2.x'
|
||||
'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
|
||||
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
|
||||
"rabbitmq":
|
||||
repo: "git://github.com/puppetlabs/puppetlabs-rabbitmq"
|
||||
|
|
|
@ -9,5 +9,5 @@ source 'https://github.com/stackforge/puppet-glance'
|
|||
|
||||
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/stdlib', '>= 3.2.0'
|
||||
dependency 'stackforge/openstacklib', '>=5.0.0'
|
||||
|
|
|
@ -118,8 +118,6 @@ Limitations
|
|||
|
||||
* Only supports configuring the file, swift and rbd storage backends.
|
||||
|
||||
* The Glance 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
|
||||
-----------
|
||||
|
||||
|
|
|
@ -146,9 +146,7 @@
|
|||
# Defaults to false, not set
|
||||
#
|
||||
# [*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.
|
||||
#
|
||||
# [*known_stores*]
|
||||
# (optional)List of which store classes and store class locations are
|
||||
|
@ -191,18 +189,22 @@ class glance::api(
|
|||
$cert_file = false,
|
||||
$key_file = false,
|
||||
$ca_file = false,
|
||||
$mysql_module = '2.2',
|
||||
$known_stores = false,
|
||||
$database_connection = 'sqlite:///var/lib/glance/glance.sqlite',
|
||||
$database_idle_timeout = 3600,
|
||||
$image_cache_dir = '/var/lib/glance/image-cache',
|
||||
# DEPRECATED PARAMETERS
|
||||
$mysql_module = undef,
|
||||
$sql_idle_timeout = false,
|
||||
$sql_connection = false,
|
||||
) inherits glance {
|
||||
|
||||
require keystone::python
|
||||
|
||||
if $mysql_module {
|
||||
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
||||
}
|
||||
|
||||
if ( $glance::params::api_package_name != $glance::params::registry_package_name ) {
|
||||
ensure_packages([$glance::params::api_package_name])
|
||||
}
|
||||
|
@ -244,12 +246,8 @@ class glance::api(
|
|||
|
||||
if $database_connection_real {
|
||||
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:\/\//) {
|
||||
|
|
|
@ -1,11 +1,33 @@
|
|||
# The glance::db::mysql class creates a MySQL database for glance.
|
||||
# It must be used on the MySQL server
|
||||
#
|
||||
# I should change this to mysql
|
||||
# for consistency
|
||||
# == Parameters
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) The mysql puppet module version to use. Tested
|
||||
# versions include 0.9 and 2.2
|
||||
# Default to '2.2'
|
||||
# [*password*]
|
||||
# password to connect to the database. Mandatory.
|
||||
#
|
||||
# [*dbname*]
|
||||
# name of the database. Optional. Defaults to glance.
|
||||
#
|
||||
# [*user*]
|
||||
# user to connect to the database. Optional. Defaults to glance.
|
||||
#
|
||||
# [*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 glance::db::mysql(
|
||||
$password,
|
||||
|
@ -16,54 +38,25 @@ class glance::db::mysql(
|
|||
$charset = 'utf8',
|
||||
$collate = 'utf8_unicode_ci',
|
||||
$cluster_id = 'localzone',
|
||||
$mysql_module = '2.2'
|
||||
$mysql_module = undef,
|
||||
) {
|
||||
|
||||
Class['glance::db::mysql'] -> Exec<| title == 'glance-manage db_sync' |>
|
||||
|
||||
if ($mysql_module >= 2.2) {
|
||||
require mysql::bindings
|
||||
require mysql::bindings::python
|
||||
Mysql_database[$dbname] ~> Exec<| title == 'glance-manage db_sync' |>
|
||||
|
||||
mysql::db { $dbname:
|
||||
user => $user,
|
||||
password => $password,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
} else {
|
||||
require mysql::python
|
||||
Database[$dbname] ~> Exec<| title == 'glance-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.')
|
||||
}
|
||||
|
||||
# Check allowed_hosts to avoid duplicate resource declarations
|
||||
# If $host in $allowed_hosts, then remove it
|
||||
if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] {
|
||||
$real_allowed_hosts = delete($allowed_hosts,$host)
|
||||
# If $host = $allowed_hosts, then set it to undef
|
||||
} elsif is_string($allowed_hosts) and ($allowed_hosts != $host) {
|
||||
$real_allowed_hosts = $allowed_hosts
|
||||
validate_string($password)
|
||||
|
||||
::openstacklib::db::mysql { 'glance':
|
||||
user => $user,
|
||||
password_hash => mysql_password($password),
|
||||
dbname => $dbname,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
|
||||
if $real_allowed_hosts {
|
||||
# TODO this class should be in the mysql namespace
|
||||
glance::db::mysql::host_access { $real_allowed_hosts:
|
||||
user => $user,
|
||||
password => $password,
|
||||
database => $dbname,
|
||||
mysql_module => $mysql_module,
|
||||
}
|
||||
}
|
||||
::Openstacklib::Db::Mysql['glance'] ~> Exec<| title == 'glance-manage db_sync' |>
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#
|
||||
# Used to grant access to the glance mysql DB
|
||||
#
|
||||
define glance::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'],
|
||||
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}"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -105,9 +105,7 @@
|
|||
# Defaults to false, not set
|
||||
#
|
||||
# [*mysql_module*]
|
||||
# (optional) The version of puppet-mysql to use. Tested versions
|
||||
# include 0.9 and 2.2
|
||||
# Defaults to '2.2'
|
||||
# (optional) Deprecated. Does nothing.
|
||||
#
|
||||
class glance::registry(
|
||||
$keystone_password,
|
||||
|
@ -135,14 +133,18 @@ class glance::registry(
|
|||
$cert_file = false,
|
||||
$key_file = false,
|
||||
$ca_file = false,
|
||||
$mysql_module = '2.2',
|
||||
# DEPRECATED PARAMETERS
|
||||
$mysql_module = undef,
|
||||
$sql_idle_timeout = false,
|
||||
$sql_connection = false,
|
||||
) inherits glance {
|
||||
|
||||
require keystone::python
|
||||
|
||||
if $mysql_module {
|
||||
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
|
||||
}
|
||||
|
||||
if ( $glance::params::api_package_name != $glance::params::registry_package_name ) {
|
||||
ensure_packages([$glance::params::registry_package_name])
|
||||
}
|
||||
|
@ -178,12 +180,8 @@ class glance::registry(
|
|||
|
||||
if $database_connection_real {
|
||||
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:\/\//) {
|
||||
|
|
|
@ -35,7 +35,6 @@ describe 'glance::api' do
|
|||
:database_connection => 'sqlite:///var/lib/glance/glance.sqlite',
|
||||
:show_image_direct_url => false,
|
||||
:purge_config => false,
|
||||
:mysql_module => '2.2',
|
||||
:known_stores => false,
|
||||
:image_cache_dir => '/var/lib/glance/image-cache',
|
||||
}
|
||||
|
|
|
@ -15,16 +15,12 @@ describe 'glance::db::mysql' do
|
|||
let :params do
|
||||
{
|
||||
:password => 'glancepass1',
|
||||
:mysql_module => '2.2'
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class('mysql::bindings::python') }
|
||||
|
||||
it { should contain_mysql__db('glance').with(
|
||||
:password => 'glancepass1',
|
||||
:require => 'Class[Mysql::Server]',
|
||||
:charset => 'utf8'
|
||||
it { should contain_openstacklib__db__mysql('glance').with(
|
||||
:password_hash => '*41C910F70EB213CF4CB7B2F561B4995503C0A87B',
|
||||
:charset => 'utf8'
|
||||
)}
|
||||
|
||||
end
|
||||
|
@ -38,9 +34,10 @@ describe 'glance::db::mysql' do
|
|||
}
|
||||
end
|
||||
|
||||
it { should contain_mysql__db('glancedb2').with(
|
||||
:password => 'glancepass2',
|
||||
:charset => 'utf8'
|
||||
it { should contain_openstacklib__db__mysql('glance').with(
|
||||
:password_hash => '*6F9A1CB9BD83EE06F3903BDFF9F4188764E694CA',
|
||||
:dbname => 'glancedb2',
|
||||
:charset => 'utf8'
|
||||
)}
|
||||
|
||||
end
|
||||
|
@ -54,17 +51,6 @@ describe 'glance::db::mysql' do
|
|||
}
|
||||
end
|
||||
|
||||
it {should_not contain_glance__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'glance',
|
||||
:password => 'glancepass2',
|
||||
:database => 'glancedb2'
|
||||
)}
|
||||
it {should contain_glance__db__mysql__host_access("%").with(
|
||||
:user => 'glance',
|
||||
:password => 'glancepass2',
|
||||
:database => 'glancedb2'
|
||||
)}
|
||||
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
|
@ -76,11 +62,6 @@ describe 'glance::db::mysql' do
|
|||
}
|
||||
end
|
||||
|
||||
it {should contain_glance__db__mysql__host_access("192.168.1.1").with(
|
||||
:user => 'glance',
|
||||
:password => 'glancepass2',
|
||||
:database => 'glancedb2'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
|
@ -92,11 +73,6 @@ describe 'glance::db::mysql' do
|
|||
}
|
||||
end
|
||||
|
||||
it {should_not contain_glance__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'glance',
|
||||
:password => 'glancepass2',
|
||||
:database => 'glancedb2'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -27,7 +27,6 @@ describe 'glance::registry' do
|
|||
:keystone_user => 'glance',
|
||||
:keystone_password => 'ChangeMe',
|
||||
:purge_config => false,
|
||||
:mysql_module => '2.2'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue