Puppet4 propper support in the mysql module

* Adapt to Puppet 4
* Code cleanup

Change-Id: I540ac66098434aea231aa7711e90f7e109ea3761
Partial-Bug: #1533359
This commit is contained in:
Maksim Malchuk 2016-01-14 10:47:09 +03:00
parent af93a3a3eb
commit 64110deddc
9 changed files with 99 additions and 84 deletions

View File

@ -65,7 +65,7 @@ class mysql::config(
fail('The ignore_db_dirs parameter is expected to be an array')
}
if $custom_setup_class != "pacemaker_mysql" {
if $custom_setup_class != 'pacemaker_mysql' {
File {
owner => 'root',
group => $root_group,

View File

@ -16,7 +16,7 @@ class mysql::params {
$port = 3306
$etc_root_password = false
$ssl = false
$server_id = delete(delete(delete("${::hostname}",'controller-'),'fuel-'),"node-")
$server_id = delete($::hostname, ['controller-', 'fuel-', 'node-'])
$service_provider = undef
#TODO(bogdando) remove code duplication for galera and mysql manifests to openstack::db in 'I' release
#Set buffer pool size to 30% of memory, but not greater than 10G
@ -52,7 +52,7 @@ class mysql::params {
$service_name = 'mysql'
$client_package_name = 'MySQL-client'
$client_version = '5.5.28_wsrep_23.7'
$server_package_name = 'MySQL-server'
$server_package_nam = 'MySQL-server'
$server_version = '5.5.28_wsrep_23.7'
$shared_package_name = 'MySQL-shared'
$shared_version = '5.5.28_wsrep_23.7'

View File

@ -19,8 +19,8 @@ class mysql::python(
) inherits mysql::params {
package { 'python-mysqldb':
name => $package_name,
ensure => $package_ensure,
name => $package_name,
}
}

View File

@ -20,8 +20,8 @@ class mysql::ruby (
) inherits mysql::params {
package{ 'ruby_mysql':
name => $package_name,
ensure => $package_ensure,
name => $package_name,
provider => $package_provider,
}

View File

@ -32,7 +32,7 @@ class mysql::server (
$server_id = $mysql::params::server_id,
$rep_user = 'replicator',
$rep_pass = 'replicant666',
$replication_roles = "SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD",
$replication_roles = 'SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD',
$use_syslog = false,
$initscript_file = 'puppet:///modules/mysql/mysql-single.init',
$root_password = 'UNSET',
@ -50,14 +50,14 @@ class mysql::server (
$config_file_real = $mysql::params::config_file
}
class { 'mysql::password' :
class { '::mysql::password' :
root_password => $root_password,
old_root_password => $old_root_password,
etc_root_password => $etc_root_password,
config_file => $config_file_real,
}
class { 'mysql::config' :
class { '::mysql::config' :
bind_address => $bind_address,
use_syslog => $use_syslog,
custom_setup_class => $custom_setup_class,
@ -67,7 +67,7 @@ class mysql::server (
Exec {path => '/usr/bin:/bin:/usr/sbin:/sbin'}
if ($custom_setup_class == undef) {
class { 'mysql':
class { '::mysql':
package_name => $client_package_name,
}
@ -83,7 +83,7 @@ class mysql::server (
name => $package_name,
}
if $::operatingsystem == 'RedHat' {
file { "/etc/init.d/mysqld":
file { '/etc/init.d/mysqld':
ensure => present,
source => $initscript_file,
mode => '0755',
@ -93,26 +93,31 @@ class mysql::server (
}
Package['mysql-client'] -> Package['mysql-server']
$service_ensure = $enabled ? {
true => 'running',
default => 'stopped'
}
service { 'mysql':
ensure => $service_ensure,
name => $service_name,
ensure => $enabled ? { true => 'running', default => 'stopped' },
enable => $enabled,
require => Package['mysql-server'],
provider => $service_provider,
}
}
elsif ($custom_setup_class == 'pacemaker_mysql') {
class { 'mysql':
class { '::mysql':
package_name => $client_package_name,
}
Package['mysql-server'] -> Class['mysql::config']
Package['mysql-client'] -> Package['mysql-server']
$config_hash['custom_setup_class'] = $custom_setup_class
$mysql_config = merge($config_hash, { custom_setup_class => $custom_setup_class })
$allowed_hosts = '%'
create_resources( 'class', { 'mysql::config' => $config_hash })
create_resources( 'class', { 'mysql::config' => $mysql_config })
Class['mysql::config'] -> Cs_resource["p_${service_name}"]
if !defined(Package['mysql-client']) {
@ -124,10 +129,10 @@ class mysql::server (
package { 'mysql-server':
name => $package_name,
} ->
exec { "create-mysql-table-if-missing":
command => "/usr/bin/mysql_install_db --datadir=$mysql::params::datadir --user=mysql && chown -R mysql:mysql $mysql::params::datadir",
exec { 'create-mysql-table-if-missing':
command => "/usr/bin/mysql_install_db --datadir=${mysql::params::datadir} --user=mysql && chown -R mysql:mysql ${mysql::params::datadir}",
path => '/bin:/usr/bin:/sbin:/usr/sbin',
unless => "test -d $mysql::params::datadir/mysql",
unless => "test -d ${mysql::params::datadir}/mysql",
}
file { '/tmp/repl_create.sql' :
@ -144,7 +149,7 @@ class mysql::server (
source => 'puppet:///modules/mysql/ocf/ocf-mysql',
owner => 'root',
group => 'root',
mode => 0755,
mode => '0755',
require => File['/tmp/repl_create.sql'],
} ->
install_ssh_keys {'root_ssh_key_for_mysql':
@ -170,7 +175,6 @@ class mysql::server (
exec { 'start_mysql_slave_on_second_controller':
command => "ssh -i /root/.ssh/id_rsa_mysql -o StrictHostKeyChecking=no root@${existing_slave} 'mysql -NBe \"start slave;\"'",
unless => "mysql -NBe 'show slave status;' | grep -q ${rep_user}",
}
}
### end hacks
@ -182,27 +186,42 @@ class mysql::server (
primitive_type => 'mysql',
cib => 'mysql',
complex_type => 'master',
ms_metadata => {'notify' => "true"},
ms_metadata => {
'notify' => true
},
parameters => {
'binary' => "/usr/bin/mysqld_safe",
'binary' => '/usr/bin/mysqld_safe',
'test_table' => 'mysql.user',
'replication_user' => $rep_user,
'replication_passwd' => $rep_pass,
'additional_parameters' => '"--init-file=/tmp/repl_create.sql"',
},
operations => {
'monitor' => { 'interval' => '20', 'timeout' => '30' },
'start' => { 'timeout' => '360' },
'stop' => { 'timeout' => '360' },
'promote' => { 'timeout' => '360' },
'demote' => { 'timeout' => '360' },
'notify' => { 'timeout' => '360' },
'monitor' => {
'interval' => '20',
'timeout' => '30'
},
'start' => {
'timeout' => '360'
},
'stop' => {
'timeout' => '360'
},
'promote' => {
'timeout' => '360'
},
'demote' => {
'timeout' => '360'
},
'notify' => {
'timeout' => '360'
},
}
}->
service { 'mysql':
name => "p_${service_name}",
ensure => 'running',
name => "p_${service_name}",
enable => true,
require => [Package['mysql-server']],
provider => 'pacemaker',
@ -218,7 +237,7 @@ class mysql::server (
}
elsif ($custom_setup_class == 'galera') {
Class['galera'] -> Class['mysql::server']
class { 'galera':
class { '::galera':
cluster_name => $galera_cluster_name,
primary_controller => $primary_controller,
node_address => $galera_node_address,
@ -232,7 +251,7 @@ class mysql::server (
}
elsif ($custom_setup_class == 'percona') {
Class['galera'] -> Class['mysql::server']
class { 'galera':
class { '::galera':
cluster_name => $galera_cluster_name,
primary_controller => $primary_controller,
node_address => $galera_node_address,
@ -245,7 +264,7 @@ class mysql::server (
}
} elsif ($custom_setup_class == 'percona_packages') {
Class['galera'] -> Class['mysql::server']
class { 'galera':
class { '::galera':
cluster_name => $galera_cluster_name,
primary_controller => $primary_controller,
node_address => $galera_node_address,
@ -257,10 +276,7 @@ class mysql::server (
use_percona => true,
use_percona_packages => true
}
}
else {
} else {
require($custom_setup_class)
}
}

View File

@ -6,7 +6,6 @@ class mysql::server::account_security {
ensure => 'absent',
require => Class['mysql::config'],
}
}
database_user { [ 'root@127.0.0.1', "root@${::hostname}", "@${::hostname}", '@localhost', '@%' ]:

View File

@ -7,8 +7,8 @@ class mysql::server::monitor (
Class['mysql::server'] -> Class['mysql::server::monitor']
database_user{ "${mysql_monitor_username}@${mysql_monitor_hostname}":
password_hash => mysql_password($mysql_monitor_password),
ensure => present,
password_hash => mysql_password($mysql_monitor_password),
}
database_grant { "${mysql_monitor_username}@${mysql_monitor_hostname}":