diff --git a/lib/facter/pcs_version.rb b/lib/facter/pcs_version.rb new file mode 100644 index 00000000..83941037 --- /dev/null +++ b/lib/facter/pcs_version.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Facter.add(:pcs_version) do + confine kernel: :Linux + setcode do + Facter::Util::Resolution.exec('pcs --version').match(%r{\d+\.\d+\.\d+}).to_s + end +end diff --git a/lib/puppet/provider/cs_primitive/pcs.rb b/lib/puppet/provider/cs_primitive/pcs.rb index 74f9ac62..489e183a 100644 --- a/lib/puppet/provider/cs_primitive/pcs.rb +++ b/lib/puppet/provider/cs_primitive/pcs.rb @@ -142,7 +142,9 @@ 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') + # TODO: Harmonize this with all the other version gatings + 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 +245,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 +267,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 +289,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..6ec89421 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,45 +1,31 @@ require 'voxpupuli/acceptance/spec_helper_acceptance' configure_beaker do |host| - case fact_on(host, 'os.family') - when 'RedHat' - default_provider = 'pcs' - pcs_version = if fact_on(host, 'os.release.major').to_i > 7 - '0.10.0' - else - '0.9.0' - end - when 'Debian' - case fact_on(host, 'os.name') - when 'Debian' - if fact_on(host, 'os.release.major').to_i > 9 - default_provider = 'pcs' - pcs_version = '0.10.0' - else - default_provider = 'crm' - pcs_version = 'undef' - end - when 'Ubuntu' - if fact_on(host, 'os.release.major').to_i > 18 - default_provider = 'pcs' - pcs_version = '0.10.0' - elsif fact_on(host, 'os.release.major').to_i > 16 - default_provider = 'pcs' - pcs_version = '0.9.0' - else - default_provider = 'crm' - pcs_version = 'undef' - end - end - when 'Suse' - default_provider = 'crm' - pcs_version = 'undef' - else - default_provider = 'crm' - pcs_version = 'undef' - end + default_provider = case fact_on(host, 'os.family') + when 'RedHat' + 'pcs' + when 'Debian' + case fact_on(host, 'os.name') + when 'Debian' + if fact_on(host, 'os.release.major').to_i > 9 + 'pcs' + else + 'crm' + end + when 'Ubuntu' + if fact_on(host, 'os.release.major').to_i > 18 + 'pcs' + elsif fact_on(host, 'os.release.major').to_i > 16 + 'pcs' + else + 'crm' + end + end + else + 'crm' + 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.