Migrate mysql backend to use openstacklib::db::mysql
Change-Id: Ic2711c675fb4a02d7d8e58e1060bded7c72774e6
This commit is contained in:
parent
9ed545a0d8
commit
c59f2755d3
|
@ -4,7 +4,8 @@ fixtures:
|
|||
'keystone': 'git://github.com/stackforge/puppet-keystone.git'
|
||||
'mysql':
|
||||
repo: 'git://github.com/puppetlabs/puppetlabs-mysql.git'
|
||||
ref: 'origin/0.x'
|
||||
ref: 'origin/2.2.x'
|
||||
'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
|
||||
'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
|
||||
symlinks:
|
||||
'ironic': "#{source_dir}"
|
||||
|
|
|
@ -9,5 +9,6 @@ source 'https://github.com/stackforge/puppet-ironic'
|
|||
|
||||
dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0'
|
||||
dependency 'puppetlabs/keystone', '>=2.0.0 <3.0.0'
|
||||
dependency 'puppetlabs/mysql', '>=0.6.1 <1.0.0'
|
||||
dependency 'puppetlabs/mysql', '>=2.2.0 <3.0.0'
|
||||
dependency 'stackforge/openstacklib'
|
||||
dependency 'puppetlabs/stdlib', '>=2.3.0'
|
||||
|
|
|
@ -17,6 +17,35 @@
|
|||
#
|
||||
# ironic::db::mysql
|
||||
#
|
||||
# [*password*]
|
||||
# Password to use for the nova user
|
||||
#
|
||||
# [*dbname*]
|
||||
# (optional) The name of the database
|
||||
# Defaults to 'nova'
|
||||
#
|
||||
# [*user*]
|
||||
# (optional) The mysql user to create
|
||||
# Defaults to 'nova'
|
||||
#
|
||||
# [*host*]
|
||||
# (optional) The IP address of the mysql server
|
||||
# Defaults to '127.0.0.1'
|
||||
#
|
||||
# [*charset*]
|
||||
# (optional) The charset to use for the nova database
|
||||
# Defaults to 'utf8'
|
||||
#
|
||||
# [*collate*]
|
||||
# (optional) The collate to use for the nova database
|
||||
# Defaults to 'utf8_unicode_ci'
|
||||
#
|
||||
# [*allowed_hosts*]
|
||||
# (optional) Additional hosts that are allowed to access this DB
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*cluster_id*]
|
||||
# (optional) Deprecated. Does nothing
|
||||
|
||||
class ironic::db::mysql (
|
||||
$password,
|
||||
|
@ -24,32 +53,23 @@ class ironic::db::mysql (
|
|||
$user = 'ironic',
|
||||
$host = '127.0.0.1',
|
||||
$allowed_hosts = undef,
|
||||
$charset = 'latin1',
|
||||
$cluster_id = 'localzone'
|
||||
$charset = 'utf8',
|
||||
$collate = 'utf8_unicode_ci',
|
||||
$cluster_id = undef,
|
||||
) {
|
||||
|
||||
require mysql::python
|
||||
|
||||
mysql::db { $dbname:
|
||||
user => $user,
|
||||
password => $password,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
require => Class['mysql::config'],
|
||||
if $cluster_id {
|
||||
warning('The cluster_id parameter is deprecated and has no effect.')
|
||||
}
|
||||
|
||||
# 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
|
||||
::openstacklib::db::mysql { 'ironic':
|
||||
user => $user,
|
||||
password_hash => mysql_password($password),
|
||||
dbname => $dbname,
|
||||
host => $host,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
|
||||
if $real_allowed_hosts {
|
||||
ironic::db::mysql::host_access { $real_allowed_hosts:
|
||||
user => $user,
|
||||
password => $password,
|
||||
database => $dbname,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2013 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.
|
||||
#
|
||||
# Used to grant access to the ironic mysql DB
|
||||
#
|
||||
|
||||
define ironic::db::mysql::host_access ($user, $password, $database) {
|
||||
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}"]
|
||||
}
|
||||
}
|
|
@ -39,7 +39,11 @@ describe 'ironic::db::mysql' do
|
|||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
it { should contain_class('ironic::db::mysql') }
|
||||
it { should contain_openstacklib__db__mysql('ironic').with(
|
||||
:user => 'ironic',
|
||||
:password_hash => '*74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3',
|
||||
:charset => 'utf8'
|
||||
)}
|
||||
end
|
||||
|
||||
context 'on RedHat platforms' do
|
||||
|
@ -47,50 +51,37 @@ describe 'ironic::db::mysql' do
|
|||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
it { should contain_class('ironic::db::mysql') }
|
||||
it { should contain_openstacklib__db__mysql('ironic').with(
|
||||
:user => 'ironic',
|
||||
:password_hash => '*74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3',
|
||||
:charset => 'utf8'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
let :params do
|
||||
{ :password => 'ironicpass',
|
||||
:allowed_hosts => ['127.0.0.1','%'] }
|
||||
{
|
||||
:allowed_hosts => ['127.0.0.1','%']
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_ironic__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'ironic',
|
||||
:password => 'ironicpass',
|
||||
:database => 'ironic'
|
||||
)}
|
||||
it {should contain_ironic__db__mysql__host_access("%").with(
|
||||
:user => 'ironic',
|
||||
:password => 'ironicpass',
|
||||
:database => 'ironic'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
let :params do
|
||||
{ :password => 'ironicpass2',
|
||||
:allowed_hosts => '192.168.1.1' }
|
||||
{
|
||||
:allowed_hosts => '192.168.1.1'
|
||||
}
|
||||
end
|
||||
|
||||
it {should contain_ironic__db__mysql__host_access("192.168.1.1").with(
|
||||
:user => 'ironic',
|
||||
:password => 'ironicpass2',
|
||||
:database => 'ironic'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
let :params do
|
||||
{ :password => 'ironicpass2',
|
||||
:allowed_hosts => '127.0.0.1' }
|
||||
{
|
||||
:allowed_hosts => '127.0.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_ironic__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'ironic',
|
||||
:password => 'ironicpass2',
|
||||
:database => 'ironic'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -71,7 +71,6 @@ describe 'ironic' do
|
|||
before do
|
||||
params.merge!(:database_connection => 'mysql://ironic:ironic@localhost/ironic')
|
||||
end
|
||||
it { should contain_class('Mysql::Python') }
|
||||
end
|
||||
|
||||
context 'with sqlite database backend' do
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'ironic::db::mysql::host_access' do
|
||||
|
||||
let :pre_condition do
|
||||
'include mysql'
|
||||
end
|
||||
|
||||
let :title do
|
||||
'127.0.0.1'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{ :user => 'ironic',
|
||||
:password => 'passw0rd',
|
||||
:database => 'ironic' }
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
it { should contain_database_user('ironic@127.0.0.1') }
|
||||
it { should contain_database_grant('ironic@127.0.0.1/ironic') }
|
||||
end
|
Loading…
Reference in New Issue