Improve stonith leves idempotency.
This commit improves the way stonith levels are set up and their resiliency against redeployments by introducing a stonith_levels custom fact that collects the current stonith levels defined for the specific server, so we can compare against the desired number of levels defined in hiera. If these do not match (for example if there are additional levels that are no longer necessary), the clean up step also introduced by this commit takes care of deleting the ones no longer necessary. Change-Id: Ifae73ac2bf4481d0a11e89c0ea0916e85dd2db1d
This commit is contained in:
parent
18a9016b7a
commit
7c30bd791f
|
@ -0,0 +1,25 @@
|
|||
# Copyright 2016 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
Facter.add('stonith_levels') do
|
||||
setcode do
|
||||
|
||||
hostname = Facter::Core::Execution.execute("crm_node -n 2> /dev/null", {})
|
||||
|
||||
stonith_levels = Facter::Core::Execution.execute("pcs stonith level | sed -n \"/^Target: #{hostname}$/,/^Target:/{/^Target: #{hostname}$/b;/^Target:/b;p}\" |tail -1 | awk '{print $2}' 2> /dev/null", {})
|
||||
|
||||
stonith_levels
|
||||
end
|
||||
end
|
|
@ -84,7 +84,7 @@ class tripleo::fencing(
|
|||
$content = $config['devices']
|
||||
|
||||
# check if the devices: section in fence.yaml contains levels.
|
||||
# if it doesn't, assume level=1 an build a hash with the content.
|
||||
# if it doesn't, assume level=1 and build a hash with the content.
|
||||
if is_array($content) {
|
||||
$all_levels = {'level1' => $content}
|
||||
}
|
||||
|
@ -92,6 +92,26 @@ class tripleo::fencing(
|
|||
$all_levels = $content
|
||||
}
|
||||
|
||||
# collect the number of stonith levels currently defined for this system
|
||||
# and convert it to integer.
|
||||
$local_levels = 0 + $facts['stonith_levels']
|
||||
|
||||
# if the number of levels defined on this system is greather than the number in hiera
|
||||
# we need to delete the delta.
|
||||
if $local_levels > $all_levels.length {
|
||||
$begin = $all_levels.length + 1
|
||||
range("${begin}", "${local_levels}").each |$level|{
|
||||
pacemaker::stonith::level{ "stonith-${level}":
|
||||
ensure => 'absent',
|
||||
level => $level,
|
||||
target => '$(/usr/sbin/crm_node -n)',
|
||||
stonith_resources => [''],
|
||||
tries => $tries,
|
||||
try_sleep => $try_sleep,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$all_levels.each |$index, $levelx_devices |{
|
||||
|
||||
$level = regsubst($index, 'level', '', 'G')
|
||||
|
|
Loading…
Reference in New Issue