blob: 980c184d576494f3b419eb9d20839c20c6525276 [file] [log] [blame]
Frederic Lecaille9be34892018-12-13 22:15:06 +01001varnishtest "Health-check test"
2feature ignore_unknown_macro
3
Christopher Faulet85a81362020-12-15 17:13:39 +01004#REQUIRE_VERSION=2.4
Frédéric Lécaille15685c72018-12-20 09:55:45 +01005#EXCLUDE_TARGETS=freebsd
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +01006#REGTEST_TYPE=slow
Frederic Lecaille9be34892018-12-13 22:15:06 +01007
8# This script test health-checks for four backends with one server by backend.
9# A syslog server is attached to each backend to check the syslog messages
10# in the righ order.
11
12# First, we check a health-check has passed for all the servers thanks to the syslog
13# messages. Then each server is disabled. The health-check status are checked.
14# Then each server is re-enabled. Finally health-check status
15# verifications for each server terminate the execution of this script.
16
17# Note that the CLI is synchronized with the syslog servers so that
18# to be sure to receive the passed health-checks status messages before
19# disabling the servers. Same thing, when we check that the servers are down
20# before enabling the servers.
21
Ilya Shipitsin77e3b4a2020-03-10 12:06:11 +050022# Cyclic barrier to synchronize the CLI with the syslog servers
Frédéric Lécaille3b3a8832018-12-20 09:55:42 +010023barrier b1 cond 5 -cyclic
Frederic Lecaille9be34892018-12-13 22:15:06 +010024
25# These servers are there only for the health-check test.
26server s1 {
27} -start
28
29server s2 {
30} -start
31
32server s3 {
33} -start
34
35server s4 {
36} -start
37
38syslog S1 -level notice {
39 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020040 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP"
Frederic Lecaille9be34892018-12-13 22:15:06 +010041 barrier b1 sync
42 recv alert
43 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Server be1/srv1 is going DOWN for maintenance. 0 active and 0 backup servers left. [01] sessions active, 0 requeued, 0 remaining in queue."
44 recv emerg
45 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be1 has no server available!"
46 barrier b1 sync
47 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020048 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: (Server be1/srv1 is UP/READY \\(leaving forced maintenance\\).|Health check for server be1/srv1 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP)"
Frederic Lecaille9be34892018-12-13 22:15:06 +010049 barrier b1 sync
50} -start
51
52syslog S2 -level notice {
53 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020054 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv2 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP"
Frederic Lecaille9be34892018-12-13 22:15:06 +010055 barrier b1 sync
56 recv alert
57 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Server be2/srv2 is going DOWN for maintenance. 0 active and 0 backup servers left. [01] sessions active, 0 requeued, 0 remaining in queue."
58 recv emerg
59 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be2 has no server available!"
60 barrier b1 sync
61 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020062 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: (Server be2/srv2 is UP/READY \\(leaving forced maintenance\\).|Health check for server be2/srv2 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP)"
Frederic Lecaille9be34892018-12-13 22:15:06 +010063 barrier b1 sync
64} -start
65
66syslog S3 -level notice {
67 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020068 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be3/srv3 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP"
Frederic Lecaille9be34892018-12-13 22:15:06 +010069 barrier b1 sync
70 recv alert
71 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Server be3/srv3 is going DOWN for maintenance. 0 active and 0 backup servers left. [01] sessions active, 0 requeued, 0 remaining in queue."
72 recv emerg
73 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be3 has no server available!"
74 barrier b1 sync
75 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020076 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: (Server be3/srv3 is UP/READY \\(leaving forced maintenance\\).|Health check for server be3/srv3 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP)"
Frederic Lecaille9be34892018-12-13 22:15:06 +010077 barrier b1 sync
78} -start
79
80syslog S4 -level notice {
81 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020082 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be4/srv4 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP"
Frederic Lecaille9be34892018-12-13 22:15:06 +010083 barrier b1 sync
84 recv alert
85 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Server be4/srv4 is going DOWN for maintenance. 0 active and 0 backup servers left. [01] sessions active, 0 requeued, 0 remaining in queue."
86 recv emerg
87 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be4 has no server available!"
88 barrier b1 sync
89 recv
Christopher Faulet617780f2020-04-07 08:00:35 +020090 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: (Server be4/srv4 is UP/READY \\(leaving forced maintenance\\).|Health check for server be4/srv4 succeeded.+reason: Layer4 check passed.+check duration: [[:digit:]]+ms.+status: 1/1 UP)"
Frederic Lecaille9be34892018-12-13 22:15:06 +010091 barrier b1 sync
92} -start
93
94
95haproxy h1 -conf {
96 defaults
97 timeout client 1s
98 timeout server 1s
99 timeout connect 1s
Christopher Faulet617780f2020-04-07 08:00:35 +0200100 default-server check inter 200ms downinter 100s rise 1 fall 1
Frederic Lecaille9be34892018-12-13 22:15:06 +0100101
102 frontend fe1
103 bind "fd@${fe1}"
104 use_backend be1
105
106 frontend fe2
107 bind "fd@${fe2}"
108 use_backend be2
109
110 frontend fe3
111 bind "fd@${fe3}"
112 use_backend be3
113
114 frontend fe4
115 bind "fd@${fe4}"
116 use_backend be4
117
118 backend be1
119 option log-health-checks
120 log ${S1_addr}:${S1_port} daemon
121 server srv1 ${s1_addr}:${s1_port}
122
123 backend be2
124 option log-health-checks
125 log ${S2_addr}:${S2_port} daemon
126 server srv2 ${s2_addr}:${s2_port}
127
128 backend be3
129 option log-health-checks
130 log ${S3_addr}:${S3_port} daemon
131 server srv3 ${s3_addr}:${s3_port}
132
133 backend be4
134 option log-health-checks
135 log ${S4_addr}:${S4_port} daemon
136 server srv4 ${s4_addr}:${s4_port}
137} -start
138
139haproxy h1 -cli {
140 barrier b1 sync
141 send "show servers state"
William Dauchyd1a7b852021-02-11 22:51:26 +0100142 expect ~ "# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord srv_use_ssl srv_check_port srv_check_addr srv_agent_addr srv_agent_port\n6 be1 1 srv1 ${s1_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 [67] 0 0 0 - ${s1_port} - 0 0 - - 0\n7 be2 1 srv2 ${s2_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 [67] 0 0 0 - ${s2_port} - 0 0 - - 0\n8 be3 1 srv3 ${s3_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 [67] 0 0 0 - ${s3_port} - 0 0 - - 0\n9 be4 1 srv4 ${s4_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 [67] 0 0 0 - ${s4_port} - 0 0 - - 0"
Frederic Lecaille9be34892018-12-13 22:15:06 +0100143}
144
145haproxy h1 -cli {
146 send "disable server be1/srv1"
147 expect ~ .*
148}
149
150haproxy h1 -cli {
151 send "disable server be2/srv2"
152 expect ~ .*
153}
154
155haproxy h1 -cli {
156 send "disable server be3/srv3"
157 expect ~ .*
158}
159
160haproxy h1 -cli {
161 send "disable server be4/srv4"
162 expect ~ .*
163}
164
165haproxy h1 -cli {
166 barrier b1 sync
167 send "show servers state"
William Dauchyd1a7b852021-02-11 22:51:26 +0100168 expect ~ "# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord srv_use_ssl srv_check_port srv_check_addr srv_agent_addr srv_agent_port\n6 be1 1 srv1 ${s1_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 1[45] 0 0 0 - ${s1_port} - 0 0 - - 0\n7 be2 1 srv2 ${s2_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 1[45] 0 0 0 - ${s2_port} - 0 0 - - 0\n8 be3 1 srv3 ${s3_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 1[45] 0 0 0 - ${s3_port} - 0 0 - - 0\n9 be4 1 srv4 ${s4_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 1[45] 0 0 0 - ${s4_port} - 0 0 - - 0"
Frederic Lecaille9be34892018-12-13 22:15:06 +0100169}
170
171haproxy h1 -cli {
172 send "enable server be1/srv1"
173 expect ~ .*
174}
175
176haproxy h1 -cli {
177 send "enable server be2/srv2"
178 expect ~ .*
179}
180
181haproxy h1 -cli {
182 send "enable server be3/srv3"
183 expect ~ .*
184}
185
186haproxy h1 -cli {
187 send "enable server be4/srv4"
188 expect ~ .*
189}
190
191haproxy h1 -cli {
192 barrier b1 sync
193 send "show servers state"
William Dauchyd1a7b852021-02-11 22:51:26 +0100194 expect ~ "# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord srv_use_ssl srv_check_port srv_check_addr srv_agent_addr srv_agent_port\n6 be1 1 srv1 ${s1_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s1_port} - 0 0 - - 0\n7 be2 1 srv2 ${s2_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s2_port} - 0 0 - - 0\n8 be3 1 srv3 ${s3_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s3_port} - 0 0 - - 0\n9 be4 1 srv4 ${s4_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s4_port} - 0 0 - - 0"
Frederic Lecaille9be34892018-12-13 22:15:06 +0100195}
196
197syslog S1 -wait
198syslog S2 -wait
199syslog S3 -wait
200syslog S4 -wait
201