From 162dbef5873e5ff8b835648cf0e6f0adebe4f0b4 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Mon, 8 Apr 2024 23:00:13 +0200 Subject: [PATCH 1/5] remove frozen string literal for cs group crm provider --- lib/puppet/provider/cs_group/crm.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/puppet/provider/cs_group/crm.rb b/lib/puppet/provider/cs_group/crm.rb index fa115700..22484cd6 100644 --- a/lib/puppet/provider/cs_group/crm.rb +++ b/lib/puppet/provider/cs_group/crm.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - begin require 'puppet_x/voxpupuli/corosync/provider/crmsh' rescue LoadError From 1ac4ad190a227e0c63de06c1b5ae4a18240ca0de Mon Sep 17 00:00:00 2001 From: markuszilch Date: Mon, 8 Apr 2024 23:03:10 +0200 Subject: [PATCH 2/5] regenerate rubocop todo --- .rubocop_todo.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a195e25..208124dc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-02-20 13:57:00 UTC using RuboCop version 1.50.2. +# on 2024-04-08 21:01:49 UTC using RuboCop version 1.60.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -15,6 +15,7 @@ Lint/DuplicateBranch: - 'spec/spec_helper_corosync.rb' # Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: @@ -51,10 +52,24 @@ RSpec/RepeatedExampleGroupBody: - 'spec/acceptance/corosync_class_spec.rb' # Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedMethods, AllowedPatterns. # AllowedMethods: ==, equal?, eql? Style/ClassEqualityComparison: Exclude: - 'lib/puppet/provider/cs_primitive/crm.rb' - 'lib/puppet/provider/cs_primitive/pcs.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'lib/puppet/provider/cs_group/crm.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantLineContinuation: + Exclude: + - 'spec/unit/puppet/type/cs_clone_spec.rb' From 48a115412580e325fdac15ab02dea4e48532d3ba Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Sun, 13 Oct 2024 11:57:19 +0200 Subject: [PATCH 3/5] fix: use chomp instead of chop in test there where instances where a required '>' was chopped off --- lib/puppet/provider/cs_clone/pcs.rb | 2 +- spec/acceptance/cs_location_spec.rb | 4 +++- spec/acceptance/cs_order_spec.rb | 4 +++- spec/unit/puppet/provider/cs_clone_pcs_spec.rb | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/cs_clone/pcs.rb b/lib/puppet/provider/cs_clone/pcs.rb index 814f5d21..81d153d0 100644 --- a/lib/puppet/provider/cs_clone/pcs.rb +++ b/lib/puppet/provider/cs_clone/pcs.rb @@ -28,7 +28,7 @@ def change_clone_id(type, primitive, id, cib) return unless doc.root.attributes['id'] != id doc.root.attributes['id'] = id - cmd = [command(:cibadmin), '--replace', '--xpath', xpath, '--xml-text', doc.to_s.chop] + cmd = [command(:cibadmin), '--replace', '--xpath', xpath, '--xml-text', doc.to_s.chomp] self.class.run_command_in_cib(cmd, cib) end diff --git a/spec/acceptance/cs_location_spec.rb b/spec/acceptance/cs_location_spec.rb index 80f4a7c8..4665e9e5 100755 --- a/spec/acceptance/cs_location_spec.rb +++ b/spec/acceptance/cs_location_spec.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# rubocop:disable Style/FrozenStringLiteralComment require 'spec_helper_acceptance' @@ -243,3 +243,5 @@ class { 'corosync': end end end + +# rubocop:enable Style/FrozenStringLiteralComment diff --git a/spec/acceptance/cs_order_spec.rb b/spec/acceptance/cs_order_spec.rb index f008f800..ad69242c 100644 --- a/spec/acceptance/cs_order_spec.rb +++ b/spec/acceptance/cs_order_spec.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# rubocop:disable Style/FrozenStringLiteralComment require 'spec_helper_acceptance' @@ -173,3 +173,5 @@ class { 'corosync': end end end + +# rubocop:enable Style/FrozenStringLiteralComment diff --git a/spec/unit/puppet/provider/cs_clone_pcs_spec.rb b/spec/unit/puppet/provider/cs_clone_pcs_spec.rb index f4782389..290c8f9e 100644 --- a/spec/unit/puppet/provider/cs_clone_pcs_spec.rb +++ b/spec/unit/puppet/provider/cs_clone_pcs_spec.rb @@ -245,7 +245,7 @@ def clone_xml(name) Puppet::Util::Execution.expects(:execute).with(['cibadmin', '--query', '--xpath', xpath], failonfail: true, combine: true).at_least_once.returns( Puppet::Util::Execution::ProcessOutput.new(clone_xml('apache_service-clone'), 0) ) - Puppet::Util::Execution.expects(:execute).with(['cibadmin', '--replace', '--xpath', xpath, '--xml-text', clone_xml('apache_service-newclone').chop], failonfail: true, combine: true).at_least_once.returns( + Puppet::Util::Execution.expects(:execute).with(['cibadmin', '--replace', '--xpath', xpath, '--xml-text', clone_xml('apache_service-newclone').chomp], failonfail: true, combine: true).at_least_once.returns( Puppet::Util::Execution::ProcessOutput.new('', 0) ) instance.change_clone_id('primitive', 'apache_service', 'apache_service-newclone', nil) From 13fc08f63fb6efac8056f3cd128351e656294a8f Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Sun, 13 Oct 2024 18:29:31 +0200 Subject: [PATCH 4/5] fix: cs_commit_spec.rb default provider on ubuntu not detected correctly --- spec/acceptance/cs_commit_spec.rb | 10 +++++----- spec/spec_helper_acceptance.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/acceptance/cs_commit_spec.rb b/spec/acceptance/cs_commit_spec.rb index dff1f2b9..550735df 100644 --- a/spec/acceptance/cs_commit_spec.rb +++ b/spec/acceptance/cs_commit_spec.rb @@ -102,7 +102,7 @@ class { 'corosync': end it 'creates the vip resource in the cib' do - command = if fact('default_provider') == 'pcs' + command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') 'pcs resource show' else @@ -139,7 +139,7 @@ class { 'corosync': end it 'creates the vip resource in the shadow cib' do - command = if fact('default_provider') == 'pcs' + command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') "pcs resource show -f #{pcs_shadow_cib}" else @@ -154,7 +154,7 @@ class { 'corosync': end it 'creates the service resource in the shadow cib' do - command = if fact('default_provider') == 'pcs' + command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') "pcs resource show -f #{pcs_shadow_cib}" else @@ -169,7 +169,7 @@ class { 'corosync': end it 'creates the colocation in the shadow cib and apache2_vip is the "with" resource' do - command = if fact('default_provider') == 'pcs' + command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' "pcs cluster cib -f #{pcs_shadow_cib} | grep apache2_vip_with_service" else 'CIB_shadow=puppet cibadmin --query | grep apache2_vip_with_service' @@ -180,7 +180,7 @@ class { 'corosync': end it 'creates the colocation in the shadow cib and apache2_service is the main resource' do - command = if fact('default_provider') == 'pcs' + command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' "pcs cluster cib -f #{pcs_shadow_cib} | grep apache2_vip_with_service" else 'CIB_shadow=puppet cibadmin --query | grep apache2_vip_with_service' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 00177b0d..1eae24b2 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -26,13 +26,13 @@ # 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. - if host[:hypervisor] =~ %r{docker} && fact_on(host, 'os.family') == 'Debian' + if host[:hypervisor] =~ %r{(vagrant|docker|container_other)} && fact_on(host, 'os.family') == 'Debian' 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' + if host[:hypervisor] =~ %r{(vagrant|docker|container_other)} && 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 From 165ad73a6f2b6f8b2afb29f2fa59b9fe1a30cc49 Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Sun, 13 Oct 2024 19:48:25 +0200 Subject: [PATCH 5/5] set default providers to pcs for debian/ubuntu --- lib/puppet/provider/cs_clone/pcs.rb | 2 +- lib/puppet/provider/cs_colocation/pcs.rb | 2 +- lib/puppet/provider/cs_commit/pcs.rb | 2 ++ lib/puppet/provider/cs_group/pcs.rb | 2 +- lib/puppet/provider/cs_location/pcs.rb | 2 +- lib/puppet/provider/cs_order/pcs.rb | 2 +- lib/puppet/provider/cs_primitive/pcs.rb | 2 +- lib/puppet/provider/cs_property/pcs.rb | 2 +- lib/puppet/provider/cs_rsc_defaults/pcs.rb | 2 +- lib/puppet/provider/cs_shadow/pcs.rb | 2 ++ spec/acceptance/cs_commit_spec.rb | 10 +++++----- spec/spec_helper_acceptance.rb | 4 ++-- 12 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/puppet/provider/cs_clone/pcs.rb b/lib/puppet/provider/cs_clone/pcs.rb index 81d153d0..1580d2a5 100644 --- a/lib/puppet/provider/cs_clone/pcs.rb +++ b/lib/puppet/provider/cs_clone/pcs.rb @@ -18,7 +18,7 @@ mk_resource_methods - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] def change_clone_id(type, primitive, id, cib) xpath = "/cib/configuration/resources/clone[descendant::#{type}[@id='#{primitive}']]" diff --git a/lib/puppet/provider/cs_colocation/pcs.rb b/lib/puppet/provider/cs_colocation/pcs.rb index 725c4012..b8bb7287 100644 --- a/lib/puppet/provider/cs_colocation/pcs.rb +++ b/lib/puppet/provider/cs_colocation/pcs.rb @@ -16,7 +16,7 @@ of current primitive colocations on the system; add, delete, or adjust various aspects.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] commands pcs: 'pcs' diff --git a/lib/puppet/provider/cs_commit/pcs.rb b/lib/puppet/provider/cs_commit/pcs.rb index 979e098c..f80bd4fe 100644 --- a/lib/puppet/provider/cs_commit/pcs.rb +++ b/lib/puppet/provider/cs_commit/pcs.rb @@ -15,6 +15,8 @@ abstract corosync/pacemaker vs. keepalived. This provider flushes the CIB generated by previous commands to cluster.' + defaultfor 'os.family' => %i[redhat debian] + commands cibadmin: 'cibadmin' # Required for block_until_ready commands pcs: 'pcs' diff --git a/lib/puppet/provider/cs_group/pcs.rb b/lib/puppet/provider/cs_group/pcs.rb index 8e3a7702..caf34da7 100644 --- a/lib/puppet/provider/cs_group/pcs.rb +++ b/lib/puppet/provider/cs_group/pcs.rb @@ -13,7 +13,7 @@ Puppet::Type.type(:cs_group).provide(:pcs, parent: PuppetX::Voxpupuli::Corosync::Provider::Pcs) do desc 'Provider to add, delete, manipulate primitive groups.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] # Path to the pcs binary for interacting with the cluster configuration. commands pcs: '/usr/sbin/pcs' diff --git a/lib/puppet/provider/cs_location/pcs.rb b/lib/puppet/provider/cs_location/pcs.rb index 00650558..2defb0d7 100644 --- a/lib/puppet/provider/cs_location/pcs.rb +++ b/lib/puppet/provider/cs_location/pcs.rb @@ -16,7 +16,7 @@ of current primitive locations on the system; add, delete, or adjust various aspects.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] has_feature :discovery commands pcs: 'pcs' diff --git a/lib/puppet/provider/cs_order/pcs.rb b/lib/puppet/provider/cs_order/pcs.rb index a527910a..73dc81e3 100644 --- a/lib/puppet/provider/cs_order/pcs.rb +++ b/lib/puppet/provider/cs_order/pcs.rb @@ -16,7 +16,7 @@ of current primitive start orders on the system; add, delete, or adjust various aspects.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] has_feature :kindness diff --git a/lib/puppet/provider/cs_primitive/pcs.rb b/lib/puppet/provider/cs_primitive/pcs.rb index 7e27a1d5..be13ede2 100644 --- a/lib/puppet/provider/cs_primitive/pcs.rb +++ b/lib/puppet/provider/cs_primitive/pcs.rb @@ -23,7 +23,7 @@ mk_resource_methods - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] # given an XML element (a from cibadmin), produce a hash suitible # for creating a new provider instance. diff --git a/lib/puppet/provider/cs_property/pcs.rb b/lib/puppet/provider/cs_property/pcs.rb index 3132c2aa..6e1a5f54 100644 --- a/lib/puppet/provider/cs_property/pcs.rb +++ b/lib/puppet/provider/cs_property/pcs.rb @@ -15,7 +15,7 @@ abstract corosync/pacemaker vs. keepalived. This provider will check the state of Corosync cluster configuration properties.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] # Path to the pcs binary for interacting with the cluster configuration. commands pcs: 'pcs' diff --git a/lib/puppet/provider/cs_rsc_defaults/pcs.rb b/lib/puppet/provider/cs_rsc_defaults/pcs.rb index a730c3b4..e7065bd7 100644 --- a/lib/puppet/provider/cs_rsc_defaults/pcs.rb +++ b/lib/puppet/provider/cs_rsc_defaults/pcs.rb @@ -15,7 +15,7 @@ abstract corosync/pacemaker vs. keepalived. This provider will check the state of Corosync global defaults for resource options.' - defaultfor operatingsystem: %i[fedora centos redhat] + defaultfor 'os.family' => %i[redhat debian] # Path to the pcs binary for interacting with the cluster configuration. commands pcs: 'pcs' diff --git a/lib/puppet/provider/cs_shadow/pcs.rb b/lib/puppet/provider/cs_shadow/pcs.rb index d89d9ea1..64c6bc47 100644 --- a/lib/puppet/provider/cs_shadow/pcs.rb +++ b/lib/puppet/provider/cs_shadow/pcs.rb @@ -15,6 +15,8 @@ abstract corosync/pacemaker vs. keepalived. This provider initializes a new CIB to begin tracking cluster changes.' + defaultfor 'os.family' => %i[redhat debian] + commands cibadmin: 'cibadmin' # Required for block_until_ready commands pcs: 'pcs' diff --git a/spec/acceptance/cs_commit_spec.rb b/spec/acceptance/cs_commit_spec.rb index 550735df..dff1f2b9 100644 --- a/spec/acceptance/cs_commit_spec.rb +++ b/spec/acceptance/cs_commit_spec.rb @@ -102,7 +102,7 @@ class { 'corosync': end it 'creates the vip resource in the cib' do - command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' + command = if fact('default_provider') == 'pcs' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') 'pcs resource show' else @@ -139,7 +139,7 @@ class { 'corosync': end it 'creates the vip resource in the shadow cib' do - command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' + command = if fact('default_provider') == 'pcs' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') "pcs resource show -f #{pcs_shadow_cib}" else @@ -154,7 +154,7 @@ class { 'corosync': end it 'creates the service resource in the shadow cib' do - command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' + command = if fact('default_provider') == 'pcs' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') "pcs resource show -f #{pcs_shadow_cib}" else @@ -169,7 +169,7 @@ class { 'corosync': end it 'creates the colocation in the shadow cib and apache2_vip is the "with" resource' do - command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' + command = if fact('default_provider') == 'pcs' "pcs cluster cib -f #{pcs_shadow_cib} | grep apache2_vip_with_service" else 'CIB_shadow=puppet cibadmin --query | grep apache2_vip_with_service' @@ -180,7 +180,7 @@ class { 'corosync': end it 'creates the colocation in the shadow cib and apache2_service is the main resource' do - command = if fact('default_provider') == 'pcs' && fact('os.name') != 'Ubuntu' + command = if fact('default_provider') == 'pcs' "pcs cluster cib -f #{pcs_shadow_cib} | grep apache2_vip_with_service" else 'CIB_shadow=puppet cibadmin --query | grep apache2_vip_with_service' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 1eae24b2..afdd8adc 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -26,13 +26,13 @@ # 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. - if host[:hypervisor] =~ %r{(vagrant|docker|container_other)} && fact_on(host, 'os.family') == 'Debian' + if host[:hypervisor] =~ %r{(vagrant|docker)} && fact_on(host, 'os.family') == 'Debian' 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{(vagrant|docker|container_other)} && fact_on(host, 'os.family') == 'RedHat' && fact_on(host, 'os.release.major') == '7' + if host[:hypervisor] =~ %r{(vagrant|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