blob: 8c29305e7457e8bfe76a89c18fe9431da6cc5c5b [file] [log] [blame]
Amaury Denoyelle65273ab2021-03-12 10:45:12 +01001varnishtest "Add server via cli"
2
3feature ignore_unknown_macro
4
5#REQUIRE_VERSION=2.4
6
7server s1 {
8 rxreq
9 txresp
10} -start
11
12haproxy h1 -conf {
13 defaults
14 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010015 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
16 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
17 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010018
19 frontend fe
20 bind "fd@${feS}"
21 default_backend test
22
23 backend test
24 balance random
25
26 backend other
27 balance static-rr
Amaury Denoyelle30467232021-03-12 18:03:27 +010028
29 backend other2
30 balance random
31 mode tcp
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010032} -start
33
34client c1 -connect ${h1_feS_sock} {
35 txreq
36 rxresp
37 expect resp.status == 503
38} -run
39
40haproxy h1 -cli {
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010041 # non existent backend
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010042 send "add server foo/s1 ${s1_addr}:${s1_port}"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010043 expect ~ "No such backend."
44
45 # missing address
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010046 send "add server test/s1"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010047 expect ~ "'server' expects <name> and <addr>\\[:<port>\\] as arguments."
48
49 # invalid load-balancing algo
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010050 send "add server other/s1 ${s1_addr}:${s1_port}"
Amaury Denoyelle996190a2021-04-29 15:35:46 +020051 expect ~ "Backend must use a dynamic load balancing to support dynamic servers."
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010052
Amaury Denoyelle30467232021-03-12 18:03:27 +010053 # invalid mux proto
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010054 send "add server other2/s1 ${s1_addr}:${s1_port} proto h2"
Amaury Denoyelle30467232021-03-12 18:03:27 +010055 expect ~ "MUX protocol is not usable for server."
56
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010057 # valid command
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010058 send "add server test/s1 ${s1_addr}:${s1_port}"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010059 expect ~ "New server registered."
60
61 # duplicate server
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010062 send "add server test/s1 ${s1_addr}:${s1_port}"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010063 expect ~ "Already exists a server with the same name in backend."
Amaury Denoyelle30467232021-03-12 18:03:27 +010064
65 # valid command
66 # specify the proto, it should be accepted for this backend
Amaury Denoyelle76e8b702022-03-09 15:07:31 +010067 send "add server test/s2 ${s1_addr}:${s1_port} proto h2"
Amaury Denoyelle30467232021-03-12 18:03:27 +010068 expect ~ "New server registered."
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010069}
70
71# dynamic servers are created on MAINT mode and should not be available at first
72client c2 -connect ${h1_feS_sock} {
73 txreq
74 rxresp
75 expect resp.status == 503
76} -run
77
78haproxy h1 -cli {
Amaury Denoyelle318c0082021-03-22 11:43:03 +010079 send "enable server test/s1"
Amaury Denoyelle79e6d2a2021-03-22 11:44:12 +010080 expect ~ ".*"
Amaury Denoyelle65273ab2021-03-12 10:45:12 +010081}
82
83client c3 -connect ${h1_feS_sock} {
84 txreq
85 rxresp
86 expect resp.status == 200
87} -run