|
17 | 17 | )
|
18 | 18 | end
|
19 | 19 |
|
20 |
| - it 'validates the corosync configuration' do |
21 |
| - is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( |
22 |
| - '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' |
23 |
| - ) |
24 |
| - end |
25 |
| - |
26 | 20 | context 'validates the corosncy configuration when config_validate_cmd is set' do
|
27 | 21 | let(:params) do
|
28 | 22 | super().merge(
|
|
65 | 59 |
|
66 | 60 | it 'configures votequorum' do
|
67 | 61 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
68 |
| - %r{nodelist} |
| 62 | + %r{nodelist\s*\{} |
69 | 63 | )
|
70 | 64 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
71 |
| - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} |
| 65 | + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*1\s*$} |
72 | 66 | )
|
73 | 67 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
74 |
| - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} |
| 68 | + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*2\s*$} |
75 | 69 | )
|
76 | 70 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
77 |
| - %r{two_node: 1\n} |
| 71 | + %r{^\s*two_node:\s*1} |
78 | 72 | )
|
79 | 73 | end
|
80 | 74 |
|
|
83 | 77 |
|
84 | 78 | it 'supports persistent node IDs' do
|
85 | 79 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
86 |
| - %r{nodelist} |
| 80 | + %r{nodelist\s*\{} |
87 | 81 | )
|
88 | 82 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
89 |
| - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 3} |
| 83 | + %r{^\s*ring0_addr:\s*node1\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*3} |
90 | 84 | )
|
91 | 85 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
92 |
| - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 11} |
| 86 | + %r{^\s*ring0_addr:\s*node2\.test\.org\s*(?:\r\n|\n)\s*nodeid:\s*11} |
93 | 87 | )
|
94 | 88 | end
|
95 | 89 | end
|
|
104 | 98 |
|
105 | 99 | it 'supports persistent node names' do
|
106 | 100 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
107 |
| - %r{nodelist} |
| 101 | + %r{nodelist\s*\{} |
108 | 102 | )
|
109 | 103 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
110 |
| - %r{ring0_addr: 192\.168\.0\.1\n\s*nodeid: 1\n\s*name: node1\.test\.org} |
| 104 | + %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} |
111 | 105 | )
|
112 | 106 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
113 |
| - %r{ring0_addr: 192\.168\.0\.2\n\s*nodeid: 2\n\s*name: node2\.test\.org} |
| 107 | + %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} |
114 | 108 | )
|
115 | 109 | end
|
116 | 110 | end
|
|
126 | 120 |
|
127 | 121 | it 'does not configure two_nodes option' do
|
128 | 122 | is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content(
|
129 |
| - %r{two_node: 1\n} |
| 123 | + %r{^\s*two_node:\s*1} |
130 | 124 | )
|
131 | 125 | end
|
132 | 126 | end
|
|
140 | 134 |
|
141 | 135 | it 'configures two_node' do
|
142 | 136 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
143 |
| - %r{two_node: 1\n} |
| 137 | + %r{^\s*two_node:\s*1} |
144 | 138 | )
|
145 | 139 | end
|
146 | 140 | end
|
|
155 | 149 |
|
156 | 150 | it 'configures nodelist' do
|
157 | 151 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
158 |
| - %r{nodelist} |
| 152 | + %r{nodelist\s*\{} |
159 | 153 | )
|
160 | 154 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
161 |
| - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} |
| 155 | + %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} |
162 | 156 | )
|
163 | 157 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
164 |
| - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} |
| 158 | + %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|\n)\s*nodeid:\s*2} |
165 | 159 | )
|
166 | 160 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
167 |
| - %r{two_node: 1\n} |
| 161 | + %r{^\s*two_node:\s*1} |
168 | 162 | )
|
169 | 163 | end
|
170 | 164 | end
|
|
184 | 178 | (1..4).each do |node_id|
|
185 | 179 | it "configures rings for host #{node_id} correctly" do
|
186 | 180 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
187 |
| - %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}} |
| 181 | + %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}} |
188 | 182 | )
|
189 | 183 | end
|
190 | 184 | end
|
191 | 185 |
|
192 | 186 | it 'does not configure two_nodes option' do
|
193 | 187 | is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content(
|
194 |
| - %r{two_node: 1\n} |
| 188 | + %r{^\s*two_node:\s*1} |
195 | 189 | )
|
196 | 190 | end
|
197 | 191 | end
|
|
209 | 203 | (1..2).each do |node_id|
|
210 | 204 | it "configures rings for host #{node_id} correctly" do
|
211 | 205 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
212 |
| - %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}} |
| 206 | + %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}} |
213 | 207 | )
|
214 | 208 | end
|
215 | 209 | end
|
216 | 210 |
|
217 | 211 | it 'configures two_node' do
|
218 | 212 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
219 |
| - %r{two_node: 1\n} |
| 213 | + %r{^\s*two_node:\s*1} |
220 | 214 | )
|
221 | 215 | end
|
222 | 216 | end
|
|
240 | 234 |
|
241 | 235 | it 'configures votequorum' do
|
242 | 236 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
243 |
| - %r{nodelist} |
| 237 | + %r{nodelist\s*\{} |
244 | 238 | )
|
245 | 239 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
246 |
| - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 1} |
| 240 | + %r{^\s*ring0_addr: node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*1} |
247 | 241 | )
|
248 | 242 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
249 |
| - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 2} |
| 243 | + %r{^\s*ring0_addr: node2\.test\.org(?:\r\n|\n)\s*nodeid:\s*2} |
250 | 244 | )
|
251 | 245 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
252 |
| - %r{two_node: 1\n} |
| 246 | + %r{^\s*two_node:\s*1} |
253 | 247 | )
|
254 | 248 | end
|
255 | 249 |
|
256 | 250 | it 'supports persistent node IDs' do
|
257 | 251 | params[:quorum_members_ids] = [3, 11]
|
258 | 252 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
259 |
| - %r{nodelist} |
| 253 | + %r{nodelist\s*\{} # Match the presence of the word 'nodelist' |
260 | 254 | )
|
| 255 | + |
261 | 256 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
262 |
| - %r{ring0_addr: node1\.test\.org\n\s*nodeid: 3} |
| 257 | + %r{^\s*ring0_addr:\s*node1\.test\.org(?:\r\n|\n)\s*nodeid:\s*3} # Match 'node1.test.org' with 'nodeid 3' |
263 | 258 | )
|
| 259 | + |
264 | 260 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
265 |
| - %r{ring0_addr: node2\.test\.org\n\s*nodeid: 11} |
| 261 | + %r{^\s*ring0_addr:\s*node2\.test\.org(?:\r\n|(?:\r\n|\n))\s*nodeid:\s*11} # Match 'node2.test.org' with 'nodeid 11' |
266 | 262 | )
|
267 | 263 | end
|
268 | 264 |
|
269 | 265 | it 'supports persistent node names' do
|
270 | 266 | params[:quorum_members] = ['192.168.0.1', '192.168.0.2']
|
271 | 267 | params[:quorum_members_names] = ['node1.test.org', 'node2.test.org']
|
272 | 268 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
273 |
| - %r{nodelist} |
| 269 | + %r{nodelist\s*\{} |
274 | 270 | )
|
275 | 271 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
276 |
| - %r{ring0_addr: 192\.168\.0\.1\n\s*nodeid: 1\n\s*name: node1\.test\.org} |
| 272 | + %r{^\s*ring0_addr: 192\.168\.0\.1(?:\r\n|\n)\s*nodeid:\s*1(?:\r\n|\n)\s*name:\s*node1\.test\.org} |
277 | 273 | )
|
278 | 274 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
279 |
| - %r{ring0_addr: 192\.168\.0\.2\n\s*nodeid: 2\n\s*name: node2\.test\.org} |
| 275 | + %r{^\s*ring0_addr: 192\.168\.0\.2(?:\r\n|\n)\s*nodeid:\s*2(?:\r\n|\n)\s*name:\s*node2\.test\.org} |
280 | 276 | )
|
281 | 277 | end
|
282 | 278 | end
|
|
337 | 333 |
|
338 | 334 | it 'configures cluster_name' do
|
339 | 335 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
340 |
| - %r{cluster_name:\s*hacell$} |
| 336 | + %r{^\s*cluster_name:\s*hacell} |
341 | 337 | )
|
342 | 338 | end
|
343 | 339 | end
|
|
542 | 538 |
|
543 | 539 | it 'is set in corosync.conf' do
|
544 | 540 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
545 |
| - %r{#{optional_parameter}:\s*#{possible_value}\n} |
| 541 | + %r{#{optional_parameter.to_s}:\s*#{Regexp.escape(possible_value.to_s)}\s*\n} |
546 | 542 | )
|
547 | 543 | end
|
548 | 544 | end
|
|
601 | 597 |
|
602 | 598 | it 'does not contain nodelist' do
|
603 | 599 | is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content(
|
604 |
| - %r{nodelist} |
| 600 | + %r{nodelist\s*\{} |
605 | 601 | )
|
606 | 602 | end
|
607 | 603 | end
|
|
616 | 612 |
|
617 | 613 | it 'does not contain nodelist' do
|
618 | 614 | is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content(
|
619 |
| - %r{nodelist} |
| 615 | + %r{nodelist\s*\{} |
620 | 616 | )
|
621 | 617 | end
|
622 | 618 | end
|
|
730 | 726 |
|
731 | 727 | it_configures 'corosync'
|
732 | 728 |
|
| 729 | + # Check the correct validation command is used for each OS |
| 730 | + it 'validates the corosync configuration' do |
| 731 | + case os_facts[:os]['family'] |
| 732 | + when 'RedHat' |
| 733 | + case os_facts[:os]['release']['major'].to_i |
| 734 | + when 0..7 |
| 735 | + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( |
| 736 | + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' |
| 737 | + ) |
| 738 | + else |
| 739 | + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( |
| 740 | + '/usr/sbin/corosync -c % -t' |
| 741 | + ) |
| 742 | + end |
| 743 | + else |
| 744 | + is_expected.to contain_file('/etc/corosync/corosync.conf').with_validate_cmd( |
| 745 | + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' |
| 746 | + ) |
| 747 | + end |
| 748 | + end |
| 749 | + |
733 | 750 | # Check default package installations per platform
|
734 | 751 | case os_facts[:os]['family']
|
735 | 752 | when 'RedHat'
|
|
942 | 959 |
|
943 | 960 | it 'does not contain the quorum device config in corosync.conf' do
|
944 | 961 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
945 |
| - %r!quorum { |
946 |
| - provider: corosync_votequorum |
947 |
| -}$!m |
| 962 | + %r{quorum\s*\{\s*provider:\s*corosync_votequorum\s*\}\s*$} |
948 | 963 | )
|
949 | 964 | end
|
950 | 965 |
|
|
963 | 978 |
|
964 | 979 | it 'contains the quorum configuration' do
|
965 | 980 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
966 |
| - %r!quorum { |
967 |
| - provider: corosync_votequorum |
968 |
| - device { |
969 |
| - model: net |
970 |
| - votes: 1 |
971 |
| -
|
972 |
| - net { |
973 |
| - algorithm: ffsplit |
974 |
| - host: quorum1[.]test[.]org |
975 |
| - } |
976 |
| - } |
977 |
| -}!m |
| 981 | + %r{ |
| 982 | + quorum\s*\{ # Match 'quorum {' with optional spaces |
| 983 | + \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' |
| 984 | + \s*device\s*\{ # Match 'device {' with optional spaces |
| 985 | + \s*model:\s*net # Match 'model: net' |
| 986 | + \s*votes:\s*1 # Match 'votes: 1' |
| 987 | + \s* # Match optional empty line |
| 988 | + \s*net\s*\{ # Match 'net {' with optional spaces |
| 989 | + \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' |
| 990 | + \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' |
| 991 | + \s*\} # Match closing '}' for 'net' |
| 992 | + \s*\} # Match closing '}' for 'device' |
| 993 | + \s*\} # Match closing '}' for 'quorum' |
| 994 | + }x # 'x' modifier allows free-spacing and comments |
978 | 995 | )
|
979 | 996 | end
|
980 | 997 |
|
|
1050 | 1067 |
|
1051 | 1068 | it 'contains the quorum configuration' do
|
1052 | 1069 | is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
|
1053 |
| - %r!quorum { |
1054 |
| - provider: corosync_votequorum |
1055 |
| - device { |
1056 |
| - model: net |
1057 |
| - votes: 1 |
1058 |
| -
|
1059 |
| - net { |
1060 |
| - algorithm: ffsplit |
1061 |
| - host: quorum1[.]test[.]org |
1062 |
| - } |
1063 |
| - } |
1064 |
| -}!m |
| 1070 | + %r{ |
| 1071 | + quorum\s*\{ # Match 'quorum {' with optional spaces |
| 1072 | + \s*provider:\s*corosync_votequorum # Match 'provider: corosync_votequorum' |
| 1073 | + \s*device\s*\{ # Match 'device {' with optional spaces |
| 1074 | + \s*model:\s*net # Match 'model: net' |
| 1075 | + \s*votes:\s*1 # Match 'votes: 1' |
| 1076 | + \s*net\s*\{ # Match 'net {' with optional spaces |
| 1077 | + \s*algorithm:\s*ffsplit # Match 'algorithm: ffsplit' |
| 1078 | + \s*host:\s*quorum1\.test\.org # Match 'host: quorum1.test.org' |
| 1079 | + \s*\} # Match closing '}' for 'net' |
| 1080 | + \s*\} # Match closing '}' for 'device' |
| 1081 | + \s*\} # Match closing '}' for 'quorum' |
| 1082 | + }x # 'x' modifier allows free-spacing and comments |
1065 | 1083 | )
|
1066 | 1084 | end
|
1067 | 1085 | end
|
|
1079 | 1097 |
|
1080 | 1098 | it 'does not configure two node' do
|
1081 | 1099 | is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content(
|
1082 |
| - %r{two_node: 1\n} |
| 1100 | + %r{^\s*two_node:\s*1} |
1083 | 1101 | )
|
1084 | 1102 | end
|
1085 | 1103 | # else - to implement
|
|
0 commit comments