Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 1 | # This script is to test the proper behavior with dynamic servers insertion and |
| 2 | # deletion, in particular with the load-balancing of requests. |
| 3 | # |
| 4 | varnishtest "Delete server via cli" |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | #REQUIRE_VERSION=2.4 |
| 9 | |
| 10 | # static server |
| 11 | server 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 |
| 18 | server s2 -repeat 3 { |
| 19 | rxreq |
| 20 | txresp \ |
| 21 | -body "resp from s2" |
| 22 | } -start |
| 23 | |
| 24 | haproxy h1 -conf { |
| 25 | defaults |
| 26 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 27 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 28 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 29 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 30 | |
| 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 |
| 40 | haproxy h1 -cli { |
| 41 | # add a dynamic server and enable it |
Amaury Denoyelle | 76e8b70 | 2022-03-09 15:07:31 +0100 | [diff] [blame] | 42 | send "add server test/s2 ${s2_addr}:${s2_port}" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 43 | expect ~ "New server registered." |
| 44 | |
| 45 | send "enable server test/s2" |
| 46 | expect ~ ".*" |
| 47 | } |
| 48 | |
| 49 | haproxy h1 -cli { |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 50 | # non existent backend |
Amaury Denoyelle | 76e8b70 | 2022-03-09 15:07:31 +0100 | [diff] [blame] | 51 | send "del server foo/s1" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 52 | expect ~ "No such backend." |
| 53 | |
| 54 | # non existent server |
Amaury Denoyelle | 76e8b70 | 2022-03-09 15:07:31 +0100 | [diff] [blame] | 55 | send "del server test/other" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 56 | expect ~ "No such server." |
| 57 | } |
| 58 | |
| 59 | # first check that both servers are active |
| 60 | client 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 |
| 71 | haproxy h1 -cli { |
| 72 | # server not in maintenance mode |
Amaury Denoyelle | 76e8b70 | 2022-03-09 15:07:31 +0100 | [diff] [blame] | 73 | send "del server test/s2" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 74 | expect ~ "Only servers in maintenance mode can be deleted." |
| 75 | |
| 76 | send "disable server test/s2" |
| 77 | expect ~ ".*" |
| 78 | |
| 79 | # valid command |
Amaury Denoyelle | 76e8b70 | 2022-03-09 15:07:31 +0100 | [diff] [blame] | 80 | send "del server test/s2" |
Amaury Denoyelle | 14c3c5c | 2021-08-23 14:10:51 +0200 | [diff] [blame] | 81 | expect ~ "Server deleted." |
| 82 | } |
| 83 | |
| 84 | # now check that only the first server is used |
| 85 | client 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 | |