diff --git a/lib/facter/pcs_version.rb b/lib/facter/pcs_version.rb new file mode 100644 index 00000000..da18e0b6 --- /dev/null +++ b/lib/facter/pcs_version.rb @@ -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 \ No newline at end of file diff --git a/lib/puppet/provider/cs_primitive/pcs.rb b/lib/puppet/provider/cs_primitive/pcs.rb index 74f9ac62..70b8f730 100644 --- a/lib/puppet/provider/cs_primitive/pcs.rb +++ b/lib/puppet/provider/cs_primitive/pcs.rb @@ -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]) @@ -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] @@ -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]) @@ -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]}"] diff --git a/spec/acceptance/cs_primitive_spec.rb b/spec/acceptance/cs_primitive_spec.rb index 5df55ae7..e6c4b942 100644 --- a/spec/acceptance/cs_primitive_spec.rb +++ b/spec/acceptance/cs_primitive_spec.rb @@ -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 @@ -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 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index a770b0fe..6315e9e8 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -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.