Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue 447 #450

Merged
merged 18 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/puppet/provider/cs_location/crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
# Decided to just go with relative.
commands crm: 'crm'

# Path to the pacemakerd binary to check version for resource_discovery feature
# Decided to just go with relative.
commands pacemakerd: 'pacemakerd'

mk_resource_methods

# we need to check if we run at least pacemakerd version 1.1.13 before enabling feature discovery
# see http://blog.clusterlabs.org/blog/2014/feature-spotlight-controllable-resource-discovery
begin
pacemakerd_version_string = pacemakerd('--version')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this executed on the agent or during catalog compilation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is executed on the agent.
(We are already using this code in our environment. If it would be executed during compilation it would be done on the puppetserver, where there is no pacemakerd installed and we then wouldn't have the discovery feature, which we have.)

if pacemakerd_version_string
pacemakerd_version = pacemakerd_version_string.scan(%r{\d+\.\d+\.\d+}).first
if pacemakerd_version
if Puppet::Util::Package.versioncmp(pacemakerd_version, '1.1.13') >= 0
has_feature :discovery
end
end
end
igalic marked this conversation as resolved.
Show resolved Hide resolved
rescue Puppet::MissingCommand
# on fresh systems pacemaker is not yet installed when pacemakerd command is executed, so we do just nothing, when the executable is missing
debug('pacemakerd binary not installed. Version is not checked to find out, if discovery feature for cs_location can be used or not, so discovery feature is not set.')
end

def self.instances
block_until_ready

Expand Down Expand Up @@ -81,7 +102,7 @@ def flush
updated = "location #{@property_hash[:name]} #{@property_hash[:primitive]}"

if feature?(:discovery)
updated << " resource-discovery=#{@property_hash[:resource_discovery]}"
updated << " resource-discovery=#{@property_hash[:resource_discovery]}" unless @property_hash[:resource_discovery].nil?
igalic marked this conversation as resolved.
Show resolved Hide resolved
end

unless @property_hash[:node_name].nil?
Expand Down
15 changes: 13 additions & 2 deletions lib/puppet/provider/cs_order/crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def self.instances
items['then']
end

kind = if items['kind']
items['kind']
else
'Mandatory'
end

symmetrical = if items['symmetrical']
(items['symmetrical'] == 'true')
else
Expand All @@ -55,6 +61,7 @@ def self.instances
first: first,
second: second,
score: items['score'],
kind: kind,
symmetrical: symmetrical,
provider: name
}
Expand Down Expand Up @@ -93,9 +100,13 @@ def flush
return if @property_hash.empty?

updated = 'order '
updated << "#{@property_hash[:name]} #{@property_hash[:score]}: "
updated << "#{@property_hash[:name]} "
if @property_hash[:score]
updated << "#{@property_hash[:score]}: "
elsif feature? :kindness
updated << "#{@property_hash[:kind]}: "
end
updated << "#{@property_hash[:first]} #{@property_hash[:second]} symmetrical=#{@property_hash[:symmetrical]}"
updated << " kind=#{@property_hash[:kind]}" if feature? :kindness
debug("Loading update: #{updated}")
Tempfile.open('puppet_crm_update') do |tmpfile|
tmpfile.write(updated)
Expand Down
8 changes: 0 additions & 8 deletions lib/puppet/provider/cs_order/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def self.instances
else
items['then']
end
score = if items['score']
items['score']
else
'INFINITY'
end
kind = if items['kind']
items['kind']
else
Expand All @@ -70,7 +65,6 @@ def self.instances
ensure: :present,
first: first,
second: second,
score: score,
kind: kind,
symmetrical: symmetrical,
provider: name,
Expand All @@ -90,7 +84,6 @@ def create
ensure: :present,
first: @resource[:first],
second: @resource[:second],
score: @resource[:score],
kind: @resource[:kind],
symmetrical: @resource[:symmetrical],
new: true
Expand Down Expand Up @@ -126,7 +119,6 @@ def flush
items = @property_hash[:second].split(':')
cmd << items[1]
cmd << items[0]
cmd << @property_hash[:score]
cmd << "kind=#{@property_hash[:kind]}"
cmd << "id=#{@property_hash[:name]}"
cmd << "symmetrical=#{@property_hash[:symmetrical]}"
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/type/cs_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
of multiple order groups and so there is a way to control which
primitives get priority when forcing the order of state changes on
other primitives. This value can be an integer but is often defined
as the string INFINITY."

defaultto 'INFINITY'
as the string INFINITY.
When using pcs as provider this value is not used.
It is generally preferred to use the `kind` parameter."
end

newproperty(:kind, required_features: :kindness) do
Expand Down
17 changes: 4 additions & 13 deletions spec/acceptance/cs_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,10 @@ class { 'corosync':
end
end

if fact('osfamily') == 'RedHat'
it 'creates a location with resource-discovery=exclusive on EL-based systems' do
shell('cibadmin --query | grep duncan_vip_there') do |r|
expect(r.stdout).to match(%r{resource-discovery="exclusive"})
end
end
end

if fact('osfamily') != 'RedHat'
it 'creates a location without resource-discovery=exclusive on non-RH systems' do
shell('cibadmin --query | grep duncan_vip_there') do |r|
expect(r.stdout).not_to match(%r{resource-discovery="exclusive"})
end
# this requires pacemaker >= 1.1.13. All tested distributions have higher versions than 1.1.13
it 'creates a location with resource-discovery=exclusive' do
shell('cibadmin --query | grep duncan_vip_there') do |r|
expect(r.stdout).to match(%r{resource-discovery="exclusive"})
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
on host, 'mkdir /etc/systemd/system/corosync.service.d'
on host, 'echo -e "[Service]\nType=simple" > /etc/systemd/system/corosync.service.d/10-type-simple.conf'
end
# Issue 455: On Centos-based there are recurring problems with the pacemaker systemd service
# refusing to stop its crmd subprocess leading to test timeouts. Force a fast SigKill here.
if host[:hypervisor] =~ %r{docker} && fact_on(host, 'os.family') == 'RedHat' && fact_on(host, 'os.release.major') == '7'
on host, 'mkdir /etc/systemd/system/pacemaker.service.d'
on host, 'echo -e "[Service]\nSendSIGKILL=yes\nTimeoutStopSec=60s" > /etc/systemd/system/pacemaker.service.d/10-timeout.conf'
end
end

def cleanup_cs_resources
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/puppet/provider/cs_order_crm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
expect(instance.second).to eq('nul-interface-2:start')
end

it 'has kind equal to absent' do
expect(instance.kind).to eq(:absent)
it 'has kind equal to Mandatory' do
expect(instance.kind).to eq('Mandatory')
end

it 'has symmetrical set to true' do
Expand All @@ -79,8 +79,8 @@
expect(instance.second).to eq('nul-interface-2b:start')
end

it 'has kind equal to absent' do
expect(instance.kind).to eq(:absent)
it 'has kind equal to Optional' do
expect(instance.kind).to eq('Optional')
end

it 'has symmetrical set to false' do
Expand Down