-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix regex and test error #554
base: master
Are you sure you want to change the base?
Changes from 2 commits
0c00e42
23b2109
702cfad
26a4cf6
b46b52c
28fa0e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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*\{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if those additional regular expressions provide any value? Do you think the original tests weren't sufficient enough, or did they cause problems? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really add value, just checking whole line. |
||
) | ||
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,43 +234,43 @@ | |
|
||
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*\{} | ||
) | ||
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 | ||
|
||
it 'supports persistent node names' do | ||
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 +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 | ||
|
@@ -541,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 | ||
|
@@ -601,7 +593,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 +608,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 +722,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 +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 | ||
|
||
|
@@ -963,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 | ||
|
||
|
@@ -1050,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 | ||
|
@@ -1079,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which errors did that cause? Maybe this was meant to be chomp. not chop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree chomp is the best solution! i it was cutting in half a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh you did find that also. wasn't aware of it