blob: e66764164ca3eda9f9e8cb114b1422541fb08630 [file] [log] [blame]
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +02001# This script is to test the proper behavior with dynamic servers insertion and
2# deletion, in particular with the load-balancing of requests.
3#
4varnishtest "Delete server via cli"
5
6feature ignore_unknown_macro
7
8#REQUIRE_VERSION=2.4
9
10# static server
11server s1 -repeat 3 {
12 rxreq
13 txresp \
14 -body "resp from s1"
15} -start
16
17# use as a dynamic server, added then deleted via CLI
18server s2 -repeat 3 {
19 rxreq
20 txresp \
21 -body "resp from s2"
22} -start
23
24haproxy h1 -conf {
25 defaults
26 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010027 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
28 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
29 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020030
31 frontend fe
32 bind "fd@${feS}"
33 default_backend test
34
35 backend test
36 server s1 ${s1_addr}:${s1_port}
37} -start
38
39# add a new dynamic server to be able to delete it then
40haproxy h1 -cli {
41 # add a dynamic server and enable it
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010042 send "add server test/s2 ${s2_addr}:${s2_port}"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020043 expect ~ "New server registered."
44
45 send "enable server test/s2"
46 expect ~ ".*"
47}
48
49haproxy h1 -cli {
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020050 # non existent backend
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010051 send "del server foo/s1"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020052 expect ~ "No such backend."
53
54 # non existent server
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010055 send "del server test/other"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020056 expect ~ "No such server."
57}
58
59# first check that both servers are active
60client c1 -connect ${h1_feS_sock} {
61 txreq
62 rxresp
63 expect resp.body == "resp from s1"
64
65 txreq
66 rxresp
67 expect resp.body == "resp from s2"
68} -run
69
70# delete the dynamic server
71haproxy h1 -cli {
72 # server not in maintenance mode
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010073 send "del server test/s2"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020074 expect ~ "Only servers in maintenance mode can be deleted."
75
76 send "disable server test/s2"
77 expect ~ ".*"
78
79 # valid command
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010080 send "del server test/s2"
Amaury Denoyelle14c3c5c2021-08-23 14:10:51 +020081 expect ~ "Server deleted."
82}
83
84# now check that only the first server is used
85client c2 -connect ${h1_feS_sock} {
86 txreq
87 rxresp
88 expect resp.body == "resp from s1"
89
90 txreq
91 rxresp
92 expect resp.body == "resp from s1"
93} -run
94