Amaury Denoyelle | e558043 | 2021-04-15 14:41:20 +0200 | [diff] [blame] | 1 | varnishtest "Delete server via cli" |
| 2 | |
| 3 | feature ignore_unknown_macro |
| 4 | |
| 5 | #REQUIRE_VERSION=2.4 |
| 6 | |
| 7 | # static server |
| 8 | server s1 -repeat 3 { |
| 9 | rxreq |
| 10 | txresp \ |
| 11 | -body "resp from s1" |
| 12 | } -start |
| 13 | |
| 14 | # use as a dynamic server, added then deleted via CLI |
| 15 | server s2 -repeat 3 { |
| 16 | rxreq |
| 17 | txresp \ |
| 18 | -body "resp from s2" |
| 19 | } -start |
| 20 | |
| 21 | haproxy h1 -conf { |
| 22 | defaults |
| 23 | mode http |
| 24 | ${no-htx} option http-use-htx |
| 25 | timeout connect 1s |
| 26 | timeout client 1s |
| 27 | timeout server 1s |
| 28 | |
| 29 | frontend fe |
| 30 | bind "fd@${feS}" |
| 31 | default_backend test |
| 32 | |
| 33 | backend test |
| 34 | server s1 ${s1_addr}:${s1_port} |
| 35 | } -start |
| 36 | |
| 37 | # add a new dynamic server to be able to delete it then |
| 38 | haproxy h1 -cli { |
| 39 | # add a dynamic server and enable it |
| 40 | send "experimental-mode on; add server test/s2 ${s2_addr}:${s2_port}" |
| 41 | expect ~ "New server registered." |
| 42 | |
| 43 | send "enable server test/s2" |
| 44 | expect ~ ".*" |
| 45 | } |
| 46 | |
| 47 | haproxy h1 -cli { |
| 48 | # experimental mode disabled |
| 49 | send "del server test/s1" |
| 50 | expect ~ "This command is restricted to experimental mode only." |
| 51 | |
| 52 | # non existent backend |
| 53 | send "experimental-mode on; del server foo/s1" |
| 54 | expect ~ "No such backend." |
| 55 | |
| 56 | # non existent server |
| 57 | send "experimental-mode on; del server test/other" |
| 58 | expect ~ "No such server." |
| 59 | |
| 60 | # static server |
| 61 | send "experimental-mode on; del server test/s1" |
| 62 | expect ~ "Only servers added at runtime via <add server> CLI cmd can be deleted." |
| 63 | } |
| 64 | |
| 65 | # first check that both servers are active |
| 66 | client c1 -connect ${h1_feS_sock} { |
| 67 | txreq |
| 68 | rxresp |
| 69 | expect resp.body == "resp from s1" |
| 70 | |
| 71 | txreq |
| 72 | rxresp |
| 73 | expect resp.body == "resp from s2" |
| 74 | } -run |
| 75 | |
| 76 | # delete the dynamic server |
| 77 | haproxy h1 -cli { |
| 78 | # server not in maintenance mode |
| 79 | send "experimental-mode on; del server test/s2" |
| 80 | expect ~ "Only servers in maintenance mode can be deleted." |
| 81 | |
| 82 | send "disable server test/s2" |
| 83 | expect ~ ".*" |
| 84 | |
| 85 | # valid command |
| 86 | send "experimental-mode on; del server test/s2" |
| 87 | expect ~ "Server deleted." |
| 88 | } |
| 89 | |
| 90 | # now check that only the first server is used |
| 91 | client c2 -connect ${h1_feS_sock} { |
| 92 | txreq |
| 93 | rxresp |
| 94 | expect resp.body == "resp from s1" |
| 95 | |
| 96 | txreq |
| 97 | rxresp |
| 98 | expect resp.body == "resp from s1" |
| 99 | } -run |
| 100 | |