Always wait for database backend

Previously when using the detached-database functionality, the various
tasks that require the database task on the primary controller will run
immediately after the primary controller database task has executed.
Because the wait for the mysql backend was included within the enabled
if block, when detached db is used the database task finishes
immediately without the database actually being ready. This change
takes the mysql backend wait code and puts it in it's own class that
can be included anywhere the mysql backend wait needs to occur.
Additionally this code can be leveraged as a task if necessary.

Change-Id: Ia1d45f45cbbd91b7c6cacd4aa46dae0a92e4156e
Closes-Bug: #1588387
This commit is contained in:
Alex Schultz 2016-06-02 12:16:15 -06:00
parent e15ac3fcf9
commit 39ba427e5f
3 changed files with 45 additions and 28 deletions

View File

@ -9,17 +9,12 @@ class osnailyfacter::database::database {
$primary_controller = hiera('primary_controller')
$mysql_hash = hiera_hash('mysql', {})
$debug = pick($mysql_hash['debug'], hiera('debug', false))
$management_vip = hiera('management_vip')
$database_vip = hiera('database_vip', $management_vip)
$mgmt_iface = get_network_role_property('mgmt/database', 'interface')
$direct_networks = split(direct_networks($network_scheme['endpoints'], $mgmt_iface, 'netmask'), ' ')
# localhost is covered by mysql::server so we use this for detached db
$access_networks = flatten(['240.0.0.0/255.255.0.0', $direct_networks])
$haproxy_stats_port = '10000'
$haproxy_stats_url = "http://${database_vip}:${haproxy_stats_port}/;csv"
$mysql_root_password = $mysql_hash['root_password']
$enabled = pick($mysql_hash['enabled'], true)
@ -42,8 +37,6 @@ class osnailyfacter::database::database {
$backend_port = '3307'
$backend_timeout = '10'
$external_lb = hiera('external_lb', false)
$configuration = hiera_hash('configuration', {})
$mysql_user_defined_configuration = pick($configuration['mysql'], {})
#############################################################################
@ -51,6 +44,13 @@ class osnailyfacter::database::database {
validate_string($mysql_root_password)
validate_string($status_password)
# NOTE(aschultz): wait for backend is outside of the $enabled so that in the
# case of detached-db, the database task on the controllers simply waits
# until the database is up on the other systems. This will prevent the
# various tasks from the primary controller from continuing until the database
# is available.
include ::osnailyfacter::database::database_backend_wait
if $enabled {
if '/var/lib/mysql' in $::mounts {
@ -306,26 +306,6 @@ class osnailyfacter::database::database {
mysql_socket => $mysql_socket,
}
$lb_defaults = { 'provider' => 'haproxy', 'url' => $haproxy_stats_url }
if $external_lb {
$lb_backend_provider = 'http'
$lb_url = "http://${database_vip}:49000"
}
$lb_hash = {
mysql => {
name => 'mysqld',
provider => $lb_backend_provider,
url => $lb_url
}
}
::osnailyfacter::wait_for_backend {'mysql':
lb_hash => $lb_hash,
lb_defaults => $lb_defaults
}
# this overrides /root/.my.cnf created by mysql::server::root_password
# TODO: (sgolovatiuk): This class should be removed once
# https://github.com/puppetlabs/puppetlabs-mysql/pull/801/files is accepted

View File

@ -0,0 +1,36 @@
# == Class: osnailyfacter::database::database_backend_wait
#
# This is the code to use to ensure the mysql backends are up before preceding.
# It can be used as a standalone task or included anywhere where you need to
# wait for the mysql backend to be up.
#
# === Parameters
#
# None
#
class osnailyfacter::database::database_backend_wait {
$management_vip = hiera('management_vip')
$database_vip = hiera('database_vip', $management_vip)
$haproxy_stats_port = '10000'
$haproxy_stats_url = "http://${database_vip}:${haproxy_stats_port}/;csv"
$external_lb = hiera('external_lb', false)
$lb_defaults = { 'provider' => 'haproxy', 'url' => $haproxy_stats_url }
if $external_lb {
$lb_backend_provider = 'http'
$lb_url = "http://${database_vip}:49000"
}
$lb_hash = {
mysql => {
name => 'mysqld',
provider => $lb_backend_provider,
url => $lb_url
}
}
::osnailyfacter::wait_for_backend {'mysql':
lb_hash => $lb_hash,
lb_defaults => $lb_defaults
}
}

View File

@ -229,7 +229,8 @@ describe manifest do
provider = Puppet::Type.type(:haproxy_backend_status).defaultprovider.name
end
it 'should configure haproxy backend' do
it 'should wait for mysql backend to be ready' do
should contain_class('osnailyfacter::database::database_backend_wait')
should contain_haproxy_backend_status('mysql').with(
:url => url,
:provider => provider