From 180c3b343baba1f5fbd8d76015d059b9c991d691 Mon Sep 17 00:00:00 2001 From: Doninelli Davide Date: Mon, 14 Oct 2024 13:47:57 +0200 Subject: [PATCH] automatic test for RH failing install repository --- lib/puppet/provider/cs_clone/pcs.rb | 2 +- metadata.json | 6 +- spec/classes/corosync_spec.rb | 111 +++++++++--------- .../unit/puppet/provider/cs_clone_pcs_spec.rb | 2 +- 4 files changed, 59 insertions(+), 62 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/metadata.json b/metadata.json index 9cb851f5..1008c04f 100644 --- a/metadata.json +++ b/metadata.json @@ -12,15 +12,13 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "7", - "8", - "9" + "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "7", - "9" + "7" ] }, { diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index f37a3316..c3359b25 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -62,13 +62,13 @@ %r{nodelist} ) 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 @@ -80,10 +80,10 @@ %r{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\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 @@ -101,10 +101,10 @@ %r{nodelist} ) 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 @@ -120,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 @@ -134,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 @@ -152,13 +152,13 @@ %r{nodelist} ) 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 @@ -178,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 @@ -203,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 @@ -237,13 +237,13 @@ %r{nodelist} ) 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 @@ -253,10 +253,10 @@ %r{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} ) 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} ) end @@ -267,10 +267,10 @@ %r{nodelist} ) 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 @@ -331,7 +331,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 @@ -535,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}:\s*#{possible_value}\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 @@ -957,9 +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 { - provider: corosync_votequorum -}$!m + %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*} ) end @@ -978,18 +974,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*\{ + \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 @@ -1065,18 +1063,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*\{ + \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' + \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 @@ -1094,7 +1093,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 @@ -1103,4 +1102,4 @@ end end end -end +end \ No newline at end of file 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)