Skip to content

Commit

Permalink
Migrate mysql backend to use openstacklib::db::mysql
Browse files Browse the repository at this point in the history
Implements: blueprint commmon-openstack-database-resource
Change-Id: I71e1bf084139524e41276e5cbd7f5be02d07e825
  • Loading branch information
Colleen Murphy committed Sep 8, 2014
1 parent a4a20a9 commit a95a943
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 123 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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'
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
"heat": "#{source_dir}"
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ project_page 'https://launchpad.net/puppet-heat'
source 'https://github.com/stackforge/puppet-heat'

dependency 'puppetlabs/inifile', '>= 1.0.0 <2.0.0'
dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0'
dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0'
dependency 'puppetlabs/stdlib', '>= 3.2.0'
dependency 'stackforge/openstacklib', '>=5.0.0'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extra functionality through types and providers.
Limitations
-----------

The Heat 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.
None

Development
-----------
Expand Down
56 changes: 16 additions & 40 deletions manifests/db/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,34 @@
# Defaults to 'utf8_unicode_ci'
#
# [*mysql_module*]
# The version of the mysql puppet module to use.
# Tested versions include 0.9 and 2.2
# Defaults to '2.2'.
# (optional) Deprecated. Does nothing.
#
class heat::db::mysql(
$password = false,
$dbname = 'heat',
$user = 'heat',
$host = 'localhost',
$host = '127.0.0.1',
$allowed_hosts = undef,
$charset = 'utf8',
$collate = 'utf8_unicode_ci',
$mysql_module = '2.2'
$mysql_module = undef
) {

validate_string($password)

Class['heat::db::mysql'] -> Exec<| title == 'heat-dbsync' |>
Mysql::Db[$dbname] ~> Exec<| title == 'heat-dbsync' |>

if ($mysql_module >= 2.2) {
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
collate => $collate,
require => Class['mysql::server'],
}
} else {
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 {
heat::db::mysql::host_access { $real_allowed_hosts:
user => $user,
password => $password,
database => $dbname,
mysql_module => $mysql_module,
}
::openstacklib::db::mysql { 'heat':
user => $user,
password_hash => mysql_password($password),
dbname => $dbname,
host => $host,
charset => $charset,
collate => $collate,
allowed_hosts => $allowed_hosts,
}

::Openstacklib::Db::Mysql['heat'] ~> Exec<| title == 'heat-dbsync' |>
}
43 changes: 0 additions & 43 deletions manifests/db/mysql/host_access.pp

This file was deleted.

18 changes: 8 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@
# Defaults to LOG_USER
#
# [*mysql_module*]
# (optional) The mysql puppet module version.
# Tested versions include 0.9 and 2.2
# Defaults to '2.2'
# (optional) Deprecated. Does nothing.
#
class heat(
$auth_uri = false,
Expand Down Expand Up @@ -136,7 +134,8 @@
$database_idle_timeout = 3600,
$use_syslog = false,
$log_facility = 'LOG_USER',
$mysql_module = '2.2',
#Deprecated parameters
$mysql_module = undef,
) {

include heat::params
Expand All @@ -153,6 +152,9 @@
if ($kombu_ssl_certfile and !$kombu_ssl_keyfile) or ($kombu_ssl_keyfile and !$kombu_ssl_certfile) {
fail('The kombu_ssl_certfile and kombu_ssl_keyfile parameters must be used together')
}
if $mysql_module {
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
}

File {
require => Package['heat-common'],
Expand Down Expand Up @@ -317,12 +319,8 @@
case $sql_connection {
/^mysql:\/\//: {
$backend_package = false
if ($mysql_module >= 2.2) {
require mysql::bindings
require mysql::bindings::python
} else {
include mysql::python
}
require mysql::bindings
require mysql::bindings::python
}
/^postgresql:\/\//: {
$backend_package = 'python-psycopg2'
Expand Down
33 changes: 6 additions & 27 deletions spec/classes/heat_db_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
:user => 'heat',
:host => 'localhost',
:charset => 'utf8',
:mysql_module => '0.9'
}
end

Expand All @@ -23,12 +22,12 @@
end

it 'creates a mysql database' do
should contain_mysql__db( params[:dbname] ).with(
:user => params[:user],
:password => params[:password],
:host => params[:host],
:charset => params[:charset],
:require => 'Class[Mysql::Config]'
should contain_openstacklib__db__mysql( params[:dbname] ).with(
:user => params[:user],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:require => 'Class[Mysql::Config]'
)
end
end
Expand All @@ -41,16 +40,6 @@
}
end

it {should_not contain_heat__db__mysql__host_access("localhost").with(
:user => 'heat',
:password => 'heatpass',
:database => 'heat'
)}
it {should contain_heat__db__mysql__host_access("%").with(
:user => 'heat',
:password => 'heatpass',
:database => 'heat'
)}
end

describe "overriding allowed_hosts param to string" do
Expand All @@ -61,11 +50,6 @@
}
end

it {should contain_heat__db__mysql__host_access("192.168.1.1").with(
:user => 'heat',
:password => 'heatpass2',
:database => 'heat'
)}
end

describe "overriding allowed_hosts param equals to host param " do
Expand All @@ -76,10 +60,5 @@
}
end

it {should_not contain_heat__db__mysql__host_access("localhost").with(
:user => 'heat',
:password => 'heatpass2',
:database => 'heat'
)}
end
end
1 change: 0 additions & 1 deletion spec/classes/heat_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
:database_idle_timeout => 3600,
:auth_uri => 'http://127.0.0.1:5000/v2.0',
:keystone_ec2_uri => 'http://127.0.0.1:5000/v2.0/ec2tokens',
:mysql_module => '2.2'
}
end

Expand Down

0 comments on commit a95a943

Please sign in to comment.