Match node properties more strictly

We currently do the following in order to detect if a property
is already set with the correct values:

  cmd = "property show | grep #{property}"
  if not_empty_string(node)
    cmd += " | grep #{node}"
  end
  if not_empty_string(value)
    cmd += " | grep #{value}"
  end
  cmd += " > /dev/null 2>&1"
  ret = pcs('show', @resource[:property], cmd, @resource[:tries], @resource[:try_sleep])
  Puppet.debug("property exists: #{cmd} -> #{ret}")
  return ret == false ? false : true

The problem above is that the above will match in the presence of the following
lines:
controller-1: cinder-volume-role=true galera-role=true haproxy-role=true rabbitmq-role=true redis-role=true rmq-node-attr-last-known-rabbitmq=rabbit@controller-1
controller-11: cinder-volume-role=true galera-role=true haproxy-role=true rabbitmq-role=true redis-role=true rmq-node-attr-last-known-rabbitmq=rabbit@controller-1

Let's make sure the grep for the node includes the terminating ':' so as to match
the exact node-name and not trip up on a subset. Let's also make sure
that the match is exactly on the key=value match since there can be many
properties on a single line.

Tested by deploying an overcloud successfully, changing a property and
then redeploying to verify that the property has been set back to the
correct value.

Change-Id: I5d3353d221bd33cbb0f9393c10721f9d057f2c8b
Closes-Bug: #1805786
This commit is contained in:
Michele Baldessari 2018-11-29 12:52:43 +01:00
parent 5800e93e17
commit 6632d50f54
1 changed files with 18 additions and 5 deletions

View File

@ -45,12 +45,25 @@ Puppet::Type.type(:pcmk_property).provide(:default) do
else
value = ''
end
cmd = "property show | grep #{property}"
cmd = "property show"
# We need to distinguish between per node properties and global ones as the output is
# different:
# Cluster Properties:
# cluster-infrastructure: corosync
# cluster-name: tripleo_cluster
# dc-version: 1.1.19-8.el7-c3c624ea3d
# have-watchdog: false
# maintenance-mode: false
# redis_REPL_INFO: controller-0
# stonith-enabled: false
# Node Attributes:
# controller-0: cinder-volume-role=true galera-role=true haproxy-role=true rabbitmq-role=true redis-role=true rmq-node-attr-last-known-rabbitmq=rabbit@controller-0
# controller-1: cinder-volume-role=true galera-role=true haproxy-role=true rabbitmq-role=true redis-role=true rmq-node-attr-last-known-rabbitmq=rabbit@controller-1
# controller-2: cinder-volume-role=true galera-role=true haproxy-role=true rabbitmq-role=true redis-role=true rmq-node-attr-last-known-rabbitmq=rabbit@controller-2
if not_empty_string(node)
cmd += " | grep #{node}"
end
if not_empty_string(value)
cmd += " | grep #{value}"
cmd += " | grep -e '#{node}:.*#{property}=#{value}'"
else
cmd += " | grep -e '#{property}:.*#{value}'"
end
cmd += " > /dev/null 2>&1"
ret = pcs('show', @resource[:property], cmd, @resource[:tries], @resource[:try_sleep])