Skip to content

Commit

Permalink
Add fact and port versioning diff (FIXME: harmonize)
Browse files Browse the repository at this point in the history
  • Loading branch information
towo committed Dec 27, 2021
1 parent 7a7a2c2 commit 8958a8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
13 changes: 13 additions & 0 deletions lib/facter/pcs_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

Facter.add(:pcs_version) do
confine kernel: :Linux
setcode do
version = Facter::Util::Resolution.exec('pcs --version')
if version
version.match(%r{\d+\.\d+\.\d+}).to_s
else
nil
end
end
end
12 changes: 8 additions & 4 deletions lib/puppet/provider/cs_primitive/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def promotable=(should)
@property_hash[:promotable] = should
when :false
@property_hash[:promotable] = should
if Gem::Version.new(self.class.version) >= Gem::Version.new('0.10.0')
pcs_version = Facter.value('pcs_version')
if pcs_version && Puppet::Util::Package.versioncmp(pcs_version, '0.10.0') >= 0
self.class.run_command_in_cib([command(:pcs), 'resource', 'delete', @resource[:name].to_s] - clone, @resource[:cib])
else
self.class.run_command_in_cib([command(:pcs), 'resource', 'delete', "ms_#{@resource[:name]}"], @resource[:cib])
Expand Down Expand Up @@ -243,7 +244,8 @@ def _flush_resource(operations, parameters, utilization, metadatas)
# if we are using a multistate/promotable resource, prepend ms_ before its name
# and declare it as a multistate/promotable resource
if @property_hash[:promotable] == :true
cmd = if Gem::Version.new(self.class.version) >= Gem::Version.new('0.10.0')
pcs_version = Facter.value('pcs_version')
cmd = if pcs_version && Puppet::Util::Package.versioncmp(pcs_version, '0.10.0') >= 0
[command(:pcs), pcs_subcommand, 'promotable', (@property_hash[:name]).to_s]
else
[command(:pcs), pcs_subcommand, 'master', "ms_#{@property_hash[:name]}", (@property_hash[:name]).to_s]
Expand All @@ -264,7 +266,8 @@ def _flush_resource(operations, parameters, utilization, metadatas)
end
else
if @property_hash[:promotable] == :false && @property_hash[:existing_promotable] == :true
if Gem::Version.new(self.class.version) >= Gem::Version.new('0.10.0')
pcs_version = Facter.value('pcs_version')
if pcs_version && Puppet::Util::Package.versioncmp(pcs_version, '0.10.0') >= 0
self.class.run_command_in_cib([command(:pcs), pcs_subcommand, 'delete', '--force', "#{@property_hash[:name]}-clone"], @resource[:cib])
else
self.class.run_command_in_cib([command(:pcs), pcs_subcommand, 'delete', '--force', "ms_#{@property_hash[:name]}"], @resource[:cib])
Expand All @@ -285,7 +288,8 @@ def _flush_resource(operations, parameters, utilization, metadatas)
cmd += metadatas unless metadatas.nil?
self.class.run_command_in_cib(cmd, @resource[:cib])
if @property_hash[:promotable] == :true
cmd = if Gem::Version.new(self.class.version) >= Gem::Version.new('0.10.0')
pcs_version = Facter.value('pcs_version')
cmd = if pcs_version && Puppet::Util::Package.versioncmp(pcs_version, '0.10.0') >= 0
[command(:pcs), pcs_subcommand, 'update', "#{@property_hash[:name]}-clone"]
else
[command(:pcs), pcs_subcommand, 'update', "ms_#{@property_hash[:name]}"]
Expand Down
8 changes: 4 additions & 4 deletions spec/acceptance/cs_primitive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class { 'corosync':
}
EOS

apply_manifest(pp, catch_failures: true, debug: false, trace: true)
apply_manifest(pp, catch_changes: true, debug: false, trace: true)
apply_manifest(pp, catch_failures: true, debug: true, trace: true)
apply_manifest(pp, catch_changes: true, debug: true, trace: true)
end

describe service('corosync') do
Expand Down Expand Up @@ -106,8 +106,8 @@ class { 'corosync':
}
EOS

apply_manifest(pp_master_update, expect_changes: true, debug: false, trace: true)
apply_manifest(pp_master_update, catch_changes: true, debug: false, trace: true)
apply_manifest(pp_master_update, expect_changes: true, debug: true, trace: true)
apply_manifest(pp_master_update, catch_changes: true, debug: true, trace: true)
end

it 'creates a haproxy_vip resources' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
pcs_version = 'undef'
end
on host, "echo default_provider=#{default_provider} > /opt/puppetlabs/facter/facts.d/pacemaker-provider.txt"
on host, "echo pcs_version=#{pcs_version} >> /opt/puppetlabs/facter/facts.d/pacemaker-provider.txt"
#on host, "echo pcs_version=#{pcs_version} >> /opt/puppetlabs/facter/facts.d/pacemaker-provider.txt"
# On Debian-based, service state transitions (restart, stop) hang indefinitely and
# lead to test timeouts if there is a service unit of Type=notify involved.
# Use Type=simple as a workaround. See issue 455.
Expand Down

0 comments on commit 8958a8a

Please sign in to comment.