From 0c00e42d1d036a4b0e03d9c09aecd7255a731263 Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Fri, 11 Oct 2024 11:27:32 +0200 Subject: [PATCH 1/5] fix regex and test error --- lib/puppet/provider/cs_clone/pcs.rb | 2 +- spec/classes/corosync_spec.rb | 154 ++++++++++++++++------------ 2 files changed, 87 insertions(+), 69 deletions(-) diff --git a/lib/puppet/provider/cs_clone/pcs.rb b/lib/puppet/provider/cs_clone/pcs.rb index 814f5d21..8387a4e9 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] self.class.run_command_in_cib(cmd, cib) end diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index ec970c27..a2694355 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -17,12 +17,6 @@ ) end - it 'validates the corosync configuration' do - is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( - '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' - ) - end - context 'validates the corosncy configuration when config_validate_cmd is set' do let(:params) do super().merge( @@ -65,16 +59,16 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*$} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*$} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end @@ -83,13 +77,13 @@ it 'supports persistent node IDs' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 3} + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*3} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 11} + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*11} ) end end @@ -104,13 +98,13 @@ it 'supports persistent node names' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 192\.168\.0\.1\n\s*nodeid: 1\n\s*name: node1\.test\.org} + %r{^\s*ring0_addr:\s*192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 192\.168\.0\.2\n\s*nodeid: 2\n\s*name: node2\.test\.org} + %r{^\s*ring0_addr:\s*192\.168\.0\.2(?:\r\n|\n)\s*nodeid:\s*2(?:\r\n|\n)\s*name:\s*node2\.test\.org} ) end end @@ -126,7 +120,7 @@ it 'does not configure two_nodes option' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end end @@ -140,7 +134,7 @@ it 'configures two_node' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end end @@ -155,16 +149,16 @@ it 'configures nodelist' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} + %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} + %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|\n)\s*nodeid:\s*2} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end end @@ -184,14 +178,14 @@ (1..4).each do |node_id| it "configures rings for host #{node_id} correctly" do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 172.31.10.#{node_id}\n\s*ring1_addr: 172.31.11.#{node_id}\n\s*ring2_addr: 172.31.12.#{node_id}\n\s*nodeid: #{node_id}} + %r{ring0_addr: 172.31.10.#{node_id}(?:\r\n|\n)\s*ring1_addr: 172.31.11.#{node_id}(?:\r\n|\n)\s*ring2_addr: 172.31.12.#{node_id}(?:\r\n|\n)\s*nodeid: #{node_id}} ) end end it 'does not configure two_nodes option' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end end @@ -209,14 +203,14 @@ (1..2).each do |node_id| it "configures rings for host #{node_id} correctly" do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 172.31.10.#{node_id}\n\s*ring1_addr: 172.31.11.#{node_id}\n\s*ring2_addr: 172.31.12.#{node_id}\n\s*nodeid: #{node_id}} + %r{ring0_addr: 172.31.10.#{node_id}(?:\r\n|\n)\s*ring1_addr: 172.31.11.#{node_id}(?:\r\n|\n)\s*ring2_addr: 172.31.12.#{node_id}(?:\r\n|\n)\s*nodeid: #{node_id}} ) end end it 'configures two_node' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end end @@ -240,29 +234,31 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} + %r{^\s*ring0_addr: node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} + %r{^\s*ring0_addr: node2\.test\.org(?:\r\n|\n)\s*nodeid:\s*2} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end it 'supports persistent node IDs' do params[:quorum_members_ids] = [3, 11] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} # Match the presence of the word 'nodelist' ) + is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 3} + %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} # Match 'node1.test.org' with 'nodeid 3' ) + is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 11} + %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|(?:\r\n|\n))\s*nodeid:\s*11} # Match 'node2.test.org' with 'nodeid 11' ) end @@ -270,13 +266,13 @@ params[:quorum_members] = ['192.168.0.1', '192.168.0.2'] params[:quorum_members_names] = ['node1.test.org', 'node2.test.org'] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 192\.168\.0\.1\n\s*nodeid: 1\n\s*name: node1\.test\.org} + %r{^\s*ring0_addr: 192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{ring0_addr: 192\.168\.0\.2\n\s*nodeid: 2\n\s*name: node2\.test\.org} + %r{^\s*ring0_addr: 192\.168\.0\.2(?:\r\n|\n)\s*nodeid:\s*2(?:\r\n|\n)\s*name:\s*node2\.test\.org} ) end end @@ -337,7 +333,7 @@ it 'configures cluster_name' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{cluster_name:\s*hacell$} + %r{^\s*cluster_name:\s*hacell} ) end end @@ -542,7 +538,7 @@ it 'is set in corosync.conf' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{#{optional_parameter}:\s*#{possible_value}\n} + %r{#{optional_parameter.to_s}:\s*#{Regexp.escape(possible_value.to_s)}\s*\n} ) end end @@ -601,7 +597,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) end end @@ -616,7 +612,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist} + %r{nodelist\s*\{} ) end end @@ -730,6 +726,27 @@ it_configures 'corosync' + # Check the correct validation command is used for each OS + it 'validates the corosync configuration' do + case os_facts[:os]['family'] + when 'RedHat' + case os_facts[:os]['release']['major'].to_i + when 0..7 + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' + ) + else + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( + '/usr/sbin/corosync -c % -t' + ) + end + else + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' + ) + end + end + # Check default package installations per platform case os_facts[:os]['family'] when 'RedHat' @@ -942,9 +959,7 @@ it 'does not contain the quorum device config in corosync.conf' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r!quorum { - provider: corosync_votequorum -}$!m + %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*$} ) end @@ -963,18 +978,20 @@ it 'contains the quorum configuration' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r!quorum { - provider: corosync_votequorum - device { - model: net - votes: 1 - - net { - algorithm: ffsplit - host: quorum1[.]test[.]org - } - } -}!m + %r{ + quorum\s*\{ # Match 'quorum {' with optional spaces + \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' + \s*device\s*\{ # Match 'device {' with optional spaces + \s*model:\s*net # Match 'model: net' + \s*votes:\s*1 # Match 'votes: 1' + \s* # Match optional empty line + \s*net\s*\{ # Match 'net {' with optional spaces + \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' + \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' + \s*\} # Match closing '}' for 'net' + \s*\} # Match closing '}' for 'device' + \s*\} # Match closing '}' for 'quorum' + }x # 'x' modifier allows free-spacing and comments ) end @@ -1050,18 +1067,19 @@ it 'contains the quorum configuration' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r!quorum { - provider: corosync_votequorum - device { - model: net - votes: 1 - - net { - algorithm: ffsplit - host: quorum1[.]test[.]org - } - } -}!m + %r{ + quorum\s*\{ # Match 'quorum {' with optional spaces + \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' + \s*device\s*\{ # Match 'device {' with optional spaces + \s*model:\s*net # Match 'model: net' + \s*votes:\s*1 # Match 'votes: 1' + \s*net\s*\{ # Match 'net {' with optional spaces + \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' + \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' + \s*\} # Match closing '}' for 'net' + \s*\} # Match closing '}' for 'device' + \s*\} # Match closing '}' for 'quorum' + }x # 'x' modifier allows free-spacing and comments ) end end @@ -1079,7 +1097,7 @@ it 'does not configure two node' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} + %r{^\s*two_node:\s*1} ) end # else - to implement From 23b2109373b59412bc462a630739ffc7b6c1fd99 Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Fri, 11 Oct 2024 11:43:12 +0200 Subject: [PATCH 2/5] fix all rubocop errors --- spec/classes/corosync_spec.rb | 60 ++++++++++++++++------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index a2694355..7596258f 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -250,15 +250,13 @@ it 'supports persistent node IDs' do params[:quorum_members_ids] = [3, 11] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} # Match the presence of the word 'nodelist' + %r{nodelist\s*\{} ) - is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} # Match 'node1.test.org' with 'nodeid 3' + %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} ) - is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|(?:\r\n|\n))\s*nodeid:\s*11} # Match 'node2.test.org' with 'nodeid 11' + %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|(?:\r\n|\n))\s*nodeid:\s*11} ) end @@ -537,9 +535,7 @@ end it 'is set in corosync.conf' do - is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{#{optional_parameter.to_s}:\s*#{Regexp.escape(possible_value.to_s)}\s*\n} - ) + is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(%r{#{optional_parameter}:\s*#{Regexp.escape(possible_value.to_s)}\s*\n}) end end end @@ -979,19 +975,19 @@ it 'contains the quorum configuration' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{ - quorum\s*\{ # Match 'quorum {' with optional spaces - \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' - \s*device\s*\{ # Match 'device {' with optional spaces - \s*model:\s*net # Match 'model: net' - \s*votes:\s*1 # Match 'votes: 1' - \s* # Match optional empty line - \s*net\s*\{ # Match 'net {' with optional spaces - \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' - \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' - \s*\} # Match closing '}' for 'net' - \s*\} # Match closing '}' for 'device' - \s*\} # Match closing '}' for 'quorum' - }x # 'x' modifier allows free-spacing and comments + quorum\s*\{ + \s*provider:\s*corosync_votequorum + \s*device\s*\{ + \s*model:\s*net + \s*votes:\s*1 + \s* + \s*net\s*\{ + \s*algorithm:\s*ffsplit + \s*host:\s*quorum1\.test\.org + \s*\} + \s*\} + \s*\} + }x ) end @@ -1068,18 +1064,18 @@ it 'contains the quorum configuration' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{ - quorum\s*\{ # Match 'quorum {' with optional spaces + quorum\s*\{ \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' - \s*device\s*\{ # Match 'device {' with optional spaces - \s*model:\s*net # Match 'model: net' - \s*votes:\s*1 # Match 'votes: 1' - \s*net\s*\{ # Match 'net {' with optional spaces - \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' - \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' - \s*\} # Match closing '}' for 'net' - \s*\} # Match closing '}' for 'device' - \s*\} # Match closing '}' for 'quorum' - }x # 'x' modifier allows free-spacing and comments + \s*device\s*\{ + \s*model:\s*net + \s*votes:\s*1 + \s*net\s*\{ + \s*algorithm:\s*ffsplit + \s*host:\s*quorum1\.test\.org + \s*\} + \s*\} + \s*\} + }x ) end end From 702cfadfdfa50761a96ef6c4b514ee69591f8ae7 Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Mon, 14 Oct 2024 09:02:45 +0200 Subject: [PATCH 3/5] rolled back regex %r{nodelist} to be less strict Removed typing error "$"char --- spec/classes/corosync_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index 7596258f..32b978c5 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -59,13 +59,13 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*$} + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*$} + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*two_node:\s*1} @@ -77,7 +77,7 @@ it 'supports persistent node IDs' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*3} @@ -98,7 +98,7 @@ it 'supports persistent node names' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} @@ -149,7 +149,7 @@ it 'configures nodelist' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} @@ -234,7 +234,7 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr: node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} @@ -250,7 +250,7 @@ it 'supports persistent node IDs' do params[:quorum_members_ids] = [3, 11] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} @@ -264,7 +264,7 @@ params[:quorum_members] = ['192.168.0.1', '192.168.0.2'] params[:quorum_members_names] = ['node1.test.org', 'node2.test.org'] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr: 192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} @@ -593,7 +593,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) end end @@ -608,7 +608,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) end end @@ -955,7 +955,7 @@ it 'does not contain the quorum device config in corosync.conf' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*$} + %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*} ) end From 26a4cf629dd78ded4c4a0d9548161498119793cc Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Mon, 14 Oct 2024 09:02:45 +0200 Subject: [PATCH 4/5] rolled back regex %r{nodelist} to be less strict Removed typing error "$"char chop -> chomp --- lib/puppet/provider/cs_clone/pcs.rb | 2 +- spec/classes/corosync_spec.rb | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/puppet/provider/cs_clone/pcs.rb b/lib/puppet/provider/cs_clone/pcs.rb index 8387a4e9..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] + 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/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index 7596258f..32b978c5 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -59,13 +59,13 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*$} + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*$} + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*two_node:\s*1} @@ -77,7 +77,7 @@ it 'supports persistent node IDs' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*3} @@ -98,7 +98,7 @@ it 'supports persistent node names' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} @@ -149,7 +149,7 @@ it 'configures nodelist' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} @@ -234,7 +234,7 @@ it 'configures votequorum' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr: node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} @@ -250,7 +250,7 @@ it 'supports persistent node IDs' do params[:quorum_members_ids] = [3, 11] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} @@ -264,7 +264,7 @@ params[:quorum_members] = ['192.168.0.1', '192.168.0.2'] params[:quorum_members_names] = ['node1.test.org', 'node2.test.org'] is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r{^\s*ring0_addr: 192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} @@ -593,7 +593,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) end end @@ -608,7 +608,7 @@ it 'does not contain nodelist' do is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{nodelist\s*\{} + %r{nodelist} ) end end @@ -955,7 +955,7 @@ it 'does not contain the quorum device config in corosync.conf' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*$} + %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*} ) end From b46b52c57c2d775c588403a82fff4e9762d7dc45 Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Mon, 14 Oct 2024 10:49:56 +0200 Subject: [PATCH 5/5] chop-Chomp --- spec/unit/puppet/provider/cs_clone_pcs_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)