Skip to content

Commit 6e108f2

Browse files
author
Colleen Murphy
committed
Migrate mysql backend to use openstacklib::db::mysql
Implements: blueprint commmon-openstack-database-resource Change-Id: I5dc293c1b8033000523fae504f789199599cf447
1 parent de177f5 commit 6e108f2

9 files changed

Lines changed: 37 additions & 150 deletions

File tree

.fixtures.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ fixtures:
55
'apt': 'git://github.com/puppetlabs/puppetlabs-apt.git'
66
'mysql':
77
repo: 'git://github.com/puppetlabs/puppetlabs-mysql.git'
8-
ref: 'origin/0.x'
8+
ref: 'origin/2.2.x'
9+
'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
910
'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
1011
'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile'
1112
'postgresql':

Modulefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ source 'https://github.com/stackforge/puppet-keystone'
99

1010
dependency 'puppetlabs/apache', '>=1.0.0 <2.0.0'
1111
dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0'
12-
dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0'
1312
dependency 'puppetlabs/stdlib', '>= 3.2.0'
13+
dependency 'stackforge/openstacklib', '>=5.0.0'

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ Limitations
148148

149149
* If you've setup Openstack using previous versions of this module you need to be aware that it used UUID as the dedault to the token_format parameter but now defaults to PKI. If you're using this module to manage a Grizzly Openstack deployment that was set up using a development release of the modules or are attempting an upgrade from Folsom then you'll need to make sure you set the token_format to UUID at classification time.
150150

151-
* The Keystone 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.
152-
153151
Development
154152
-----------
155153

manifests/db/mysql.pp

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#
2-
# implements mysql backend for keystone
1+
# The keystone::db::mysql class implements mysql backend for keystone
32
#
43
# This class can be used to create tables, users and grant
54
# privelege for a mysql keystone database.
@@ -18,10 +17,7 @@
1817
#
1918
# [allowed_hosts] Hosts allowed to use the database
2019
#
21-
# [*mysql_module*]
22-
# (optional) The mysql puppet module version to use
23-
# Tested versions include 0.9 and 2.2
24-
# Default to '0.9'
20+
# [*mysql_module*] Deprecated. Does nothing.
2521
#
2622
# == Dependencies
2723
# Class['mysql::server']
@@ -42,52 +38,25 @@
4238
$host = '127.0.0.1',
4339
$charset = 'utf8',
4440
$collate = 'utf8_unicode_ci',
45-
$mysql_module = '0.9',
41+
$mysql_module = undef,
4642
$allowed_hosts = undef
4743
) {
4844

49-
Class['keystone::db::mysql'] -> Exec<| title == 'keystone-manage db_sync' |>
50-
Class['keystone::db::mysql'] -> Service<| title == 'keystone' |>
51-
Mysql::Db[$dbname] ~> Exec<| title == 'keystone-manage db_sync' |>
52-
53-
if ($mysql_module >= 2.2) {
54-
mysql::db { $dbname:
55-
user => $user,
56-
password => $password,
57-
host => $host,
58-
charset => $charset,
59-
collate => $collate,
60-
require => Class['mysql::server'],
61-
}
62-
} else {
63-
require mysql::python
64-
65-
mysql::db { $dbname:
66-
user => $user,
67-
password => $password,
68-
host => $host,
69-
charset => $charset,
70-
require => Class['mysql::config'],
71-
}
45+
if $mysql_module {
46+
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
7247
}
7348

74-
# Check allowed_hosts to avoid duplicate resource declarations
75-
if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] {
76-
$real_allowed_hosts = delete($allowed_hosts,$host)
77-
} elsif is_string($allowed_hosts) and ($allowed_hosts != $host) {
78-
$real_allowed_hosts = $allowed_hosts
79-
}
80-
81-
if $real_allowed_hosts {
82-
keystone::db::mysql::host_access { $real_allowed_hosts:
83-
user => $user,
84-
password => $password,
85-
database => $dbname,
86-
mysql_module => $mysql_module,
87-
}
88-
89-
Keystone::Db::Mysql::Host_access[$real_allowed_hosts] -> Exec<| title == 'keystone-manage db_sync' |>
49+
validate_string($password)
9050

51+
::openstacklib::db::mysql { 'keystone':
52+
user => $user,
53+
password_hash => mysql_password($password),
54+
dbname => $dbname,
55+
host => $host,
56+
charset => $charset,
57+
collate => $collate,
58+
allowed_hosts => $allowed_hosts,
9159
}
9260

61+
::Openstacklib::Db::Mysql['keystone'] ~> Exec<| title == 'keystone-manage db_sync' |>
9362
}

manifests/db/mysql/host_access.pp

Lines changed: 0 additions & 34 deletions
This file was deleted.

manifests/db/sync.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
subscribe => [Package['keystone'], Keystone_config['database/connection']],
1010
require => User['keystone'],
1111
}
12+
13+
Exec['keystone-manage db_sync'] ~> Service<| title == 'keystone' |>
1214
}

manifests/init.pp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@
166166
# Defaults to '/C=US/ST=Unset/L=Unset/O=Unset/CN=localhost'
167167
#
168168
# [*mysql_module*]
169-
# (optional) The mysql puppet module version to use
170-
# Tested versions include 0.9 and 2.2
171-
# Default to '0.9'
169+
# (optional) Deprecated. Does nothing.
172170
#
173171
# [*validate_service*]
174172
# (optional) Whether to validate keystone connections after
@@ -251,7 +249,6 @@
251249
$signing_keyfile = '/etc/keystone/ssl/private/signing_key.pem',
252250
$signing_ca_certs = '/etc/keystone/ssl/certs/ca.pem',
253251
$signing_ca_key = '/etc/keystone/ssl/private/cakey.pem',
254-
$mysql_module = '0.9',
255252
$rabbit_host = 'localhost',
256253
$rabbit_hosts = false,
257254
$rabbit_password = 'guest',
@@ -271,6 +268,7 @@
271268
$validate_cacert = undef,
272269
$service_provider = $::keystone::params::service_provider,
273270
# DEPRECATED PARAMETERS
271+
$mysql_module = undef,
274272
$sql_connection = undef,
275273
$idle_timeout = undef,
276274
) {
@@ -279,6 +277,10 @@
279277
validate_re($catalog_type, 'template|sql')
280278
}
281279

280+
if $mysql_module {
281+
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
282+
}
283+
282284
if $sql_connection {
283285
warning('The sql_connection parameter is deprecated, use database_connection instead.')
284286
$database_connection_real = $sql_connection
@@ -417,12 +419,8 @@
417419
}
418420

419421
if($database_connection_real =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
420-
if ($mysql_module >= 2.2) {
421-
require 'mysql::bindings'
422-
require 'mysql::bindings::python'
423-
} else {
424-
require 'mysql::python'
425-
}
422+
require 'mysql::bindings'
423+
require 'mysql::bindings::python'
426424
} elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
427425

428426
} elsif($database_connection_real =~ /sqlite:\/\//) {

spec/classes/keystone_db_mysql_spec.rb

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,22 @@
1313
{ :osfamily => 'Debian' }
1414
end
1515

16-
let :param_defaults do
16+
let :params do
1717
{
1818
'password' => 'keystone_default_password',
19-
'dbname' => 'keystone',
20-
'user' => 'keystone',
21-
'charset' => 'utf8',
22-
'collate' => 'utf8_unicode_ci',
23-
'host' => '127.0.0.1',
24-
'allowed_hosts' => ['127.0.0.%', '192.168.1.%']
2519
}
2620
end
2721

28-
[
29-
{},
30-
{
31-
'password' => 'password',
32-
'dbname' => 'not_keystone',
33-
'user' => 'dan',
34-
'host' => '127.0.0.2',
35-
'charset' => 'utf8'
36-
}
37-
].each do |p|
38-
39-
let :params do
40-
p
41-
end
42-
43-
let :param_values do
44-
param_defaults.merge(p)
45-
end
46-
47-
it { should contain_class('mysql::python') }
48-
49-
it { should contain_mysql__db(param_values['dbname']).with(
50-
'user' => param_values['user'],
51-
'password' => param_values['password'],
52-
'host' => param_values['host'],
53-
'charset' => param_values['charset'],
54-
'require' => 'Class[Mysql::Config]'
22+
describe 'with only required params' do
23+
it { should contain_openstacklib__db__mysql('keystone').with(
24+
'user' => 'keystone',
25+
'password_hash' => '*B552157B14BCEDDCEAA06767A012F31BDAA9CE3D',
26+
'dbname' => 'keystone',
27+
'host' => '127.0.0.1',
28+
'charset' => 'utf8'
5529
)}
56-
5730
end
31+
5832
describe "overriding allowed_hosts param to array" do
5933
let :params do
6034
{
@@ -63,16 +37,6 @@
6337
}
6438
end
6539

66-
it {should_not contain_keystone__db__mysql__host_access("127.0.0.1").with(
67-
:user => 'keystone',
68-
:password => 'keystonepass',
69-
:database => 'keystone'
70-
)}
71-
it {should contain_keystone__db__mysql__host_access("%").with(
72-
:user => 'keystone',
73-
:password => 'keystonepass',
74-
:database => 'keystone'
75-
)}
7640
end
7741
describe "overriding allowed_hosts param to string" do
7842
let :params do
@@ -82,11 +46,6 @@
8246
}
8347
end
8448

85-
it {should contain_keystone__db__mysql__host_access("192.168.1.1").with(
86-
:user => 'keystone',
87-
:password => 'keystonepass2',
88-
:database => 'keystone'
89-
)}
9049
end
9150

9251
describe "overriding allowed_hosts param equals to host param " do
@@ -97,11 +56,6 @@
9756
}
9857
end
9958

100-
it {should_not contain_keystone__db__mysql__host_access("127.0.0.1").with(
101-
:user => 'keystone',
102-
:password => 'keystonepass2',
103-
:database => 'keystone'
104-
)}
10559
end
10660

10761
end

spec/classes/keystone_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
'signing_keyfile' => '/etc/keystone/ssl/private/signing_key.pem',
3737
'signing_ca_certs' => '/etc/keystone/ssl/certs/ca.pem',
3838
'signing_ca_key' => '/etc/keystone/ssl/private/cakey.pem',
39-
'mysql_module' => '0.9',
4039
'rabbit_host' => 'localhost',
4140
'rabbit_password' => 'guest',
4241
'rabbit_userid' => 'guest',

0 commit comments

Comments
 (0)