blob: 35d0a988e18128b41e21982b7ca7be55e89132fb [file] [log] [blame]
Frederic Lecaille9be34892018-12-13 22:15:06 +01001varnishtest "Health-check test"
2feature ignore_unknown_macro
3
4#REQUIRE_VERSION=1.8
5
6# This script test health-checks for four backends with one server by backend.
7# A syslog server is attached to each backend to check the syslog messages
8# in the righ order.
9
10# First, we check a health-check has passed for all the servers thanks to the syslog
11# messages. Then each server is disabled. The health-check status are checked.
12# Then each server is re-enabled. Finally health-check status
13# verifications for each server terminate the execution of this script.
14
15# Note that the CLI is synchronized with the syslog servers so that
16# to be sure to receive the passed health-checks status messages before
17# disabling the servers. Same thing, when we check that the servers are down
18# before enabling the servers.
19
20# Cyclic barrier to synchonize the CLI with the syslog servers
21barrier b1 sock 5 -cyclic
22
23# These servers are there only for the health-check test.
24server s1 {
25} -start
26
27server s2 {
28} -start
29
30server s3 {
31} -start
32
33server s4 {
34} -start
35
36syslog S1 -level notice {
37 recv
38 expect ~ "Proxy be1 started"
39 recv
40 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 succeeded, reason: Layer4 check passed, check duration: [[:digit:]]+ms, status: 1/1 UP"
41 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
48 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)"
49 barrier b1 sync
50} -start
51
52syslog S2 -level notice {
53 recv
54 expect ~ "Proxy be2 started"
55 recv
56 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv2 succeeded, reason: Layer4 check passed, check duration: [[:digit:]]+ms, status: 1/1 UP"
57 barrier b1 sync
58 recv alert
59 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."
60 recv emerg
61 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be2 has no server available!"
62 barrier b1 sync
63 recv
64 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)"
65 barrier b1 sync
66} -start
67
68syslog S3 -level notice {
69 recv
70 expect ~ "Proxy be3 started"
71 recv
72 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be3/srv3 succeeded, reason: Layer4 check passed, check duration: [[:digit:]]+ms, status: 1/1 UP"
73 barrier b1 sync
74 recv alert
75 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."
76 recv emerg
77 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be3 has no server available!"
78 barrier b1 sync
79 recv
80 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)"
81 barrier b1 sync
82} -start
83
84syslog S4 -level notice {
85 recv
86 expect ~ "Proxy be4 started"
87 recv
88 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be4/srv4 succeeded, reason: Layer4 check passed, check duration: [[:digit:]]+ms, status: 1/1 UP"
89 barrier b1 sync
90 recv alert
91 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."
92 recv emerg
93 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: backend be4 has no server available!"
94 barrier b1 sync
95 recv
96 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)"
97 barrier b1 sync
98} -start
99
100
101haproxy h1 -conf {
102 defaults
103 timeout client 1s
104 timeout server 1s
105 timeout connect 1s
106 default-server check downinter 1s rise 1 fall 1
107
108 frontend fe1
109 bind "fd@${fe1}"
110 use_backend be1
111
112 frontend fe2
113 bind "fd@${fe2}"
114 use_backend be2
115
116 frontend fe3
117 bind "fd@${fe3}"
118 use_backend be3
119
120 frontend fe4
121 bind "fd@${fe4}"
122 use_backend be4
123
124 backend be1
125 option log-health-checks
126 log ${S1_addr}:${S1_port} daemon
127 server srv1 ${s1_addr}:${s1_port}
128
129 backend be2
130 option log-health-checks
131 log ${S2_addr}:${S2_port} daemon
132 server srv2 ${s2_addr}:${s2_port}
133
134 backend be3
135 option log-health-checks
136 log ${S3_addr}:${S3_port} daemon
137 server srv3 ${s3_addr}:${s3_port}
138
139 backend be4
140 option log-health-checks
141 log ${S4_addr}:${S4_port} daemon
142 server srv4 ${s4_addr}:${s4_port}
143} -start
144
145haproxy h1 -cli {
146 barrier b1 sync
147 send "show servers state"
148 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\n6 be1 1 srv1 ${s1_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 6 0 0 0 - ${s1_port} -\n7 be2 1 srv2 ${s2_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 6 0 0 0 - ${s2_port} -\n8 be3 1 srv3 ${s3_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 6 0 0 0 - ${s3_port} -\n9 be4 1 srv4 ${s4_addr} 2 0 1 1 [[:digit:]]+ 6 3 1 6 0 0 0 - ${s4_port} -"
149}
150
151haproxy h1 -cli {
152 send "disable server be1/srv1"
153 expect ~ .*
154}
155
156haproxy h1 -cli {
157 send "disable server be2/srv2"
158 expect ~ .*
159}
160
161haproxy h1 -cli {
162 send "disable server be3/srv3"
163 expect ~ .*
164}
165
166haproxy h1 -cli {
167 send "disable server be4/srv4"
168 expect ~ .*
169}
170
171haproxy h1 -cli {
172 barrier b1 sync
173 send "show servers state"
174 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\n6 be1 1 srv1 ${s1_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 14 0 0 0 - ${s1_port} -\n7 be2 1 srv2 ${s2_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 14 0 0 0 - ${s2_port} -\n8 be3 1 srv3 ${s3_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 14 0 0 0 - ${s3_port} -\n9 be4 1 srv4 ${s4_addr} 0 1 1 1 [[:digit:]]+ 6 3 [01] 14 0 0 0 - ${s4_port} -"
175}
176
177haproxy h1 -cli {
178 send "enable server be1/srv1"
179 expect ~ .*
180}
181
182haproxy h1 -cli {
183 send "enable server be2/srv2"
184 expect ~ .*
185}
186
187haproxy h1 -cli {
188 send "enable server be3/srv3"
189 expect ~ .*
190}
191
192haproxy h1 -cli {
193 send "enable server be4/srv4"
194 expect ~ .*
195}
196
197haproxy h1 -cli {
198 barrier b1 sync
199 send "show servers state"
200 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\n6 be1 1 srv1 ${s1_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s1_port} -\n7 be2 1 srv2 ${s2_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s2_port} -\n8 be3 1 srv3 ${s3_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s3_port} -\n9 be4 1 srv4 ${s4_addr} 2 0 1 1 [[:digit:]]+ 6 [03] 1 [67] 0 0 0 - ${s4_port} -"
201}
202
203syslog S1 -wait
204syslog S2 -wait
205syslog S3 -wait
206syslog S4 -wait
207