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 cde46ca
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
8 changes: 8 additions & 0 deletions lib/facter/pcs_version.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 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,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])
Expand Down Expand Up @@ -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]
Expand All @@ -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])
Expand All @@ -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]}"]
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
62 changes: 24 additions & 38 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit cde46ca

Please sign in to comment.