Skip to content

Commit a43b2cd

Browse files
gorangalinecmjuraga
authored andcommitted
MAJOR: add support for tcp-check commands
1 parent b7c566c commit a43b2cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6465
-262
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Check out code into the Go module directory
1212
uses: actions/checkout@v2
1313
- name: Downloading required packages
14-
run: sudo apt-get install bats
14+
run: sudo apt-get install bats
1515
- name: Set up Go 1.16
1616
uses: actions/setup-go@v1
1717
with:

configure_data_plane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
390390
api.TCPResponseRuleGetTCPResponseRulesHandler = &handlers.GetTCPResponseRulesHandlerImpl{Client: client}
391391
api.TCPResponseRuleReplaceTCPResponseRuleHandler = &handlers.ReplaceTCPResponseRuleHandlerImpl{Client: client, ReloadAgent: ra}
392392

393+
// setup tcp check handlers
394+
api.TCPCheckCreateTCPCheckHandler = &handlers.CreateTCPCheckHandlerImpl{Client: client, ReloadAgent: ra}
395+
api.TCPCheckDeleteTCPCheckHandler = &handlers.DeleteTCPCheckHandlerImpl{Client: client, ReloadAgent: ra}
396+
api.TCPCheckGetTCPCheckHandler = &handlers.GetTCPCheckHandlerImpl{Client: client}
397+
api.TCPCheckGetTCPChecksHandler = &handlers.GetTCPChecksHandlerImpl{Client: client}
398+
api.TCPCheckReplaceTCPCheckHandler = &handlers.ReplaceTCPCheckHandlerImpl{Client: client, ReloadAgent: ra}
399+
393400
// setup backend switching rule handlers
394401
api.BackendSwitchingRuleCreateBackendSwitchingRuleHandler = &handlers.CreateBackendSwitchingRuleHandlerImpl{Client: client, ReloadAgent: ra}
395402
api.BackendSwitchingRuleDeleteBackendSwitchingRuleHandler = &handlers.DeleteBackendSwitchingRuleHandlerImpl{Client: client, ReloadAgent: ra}

e2e/tests/tcp_checks/add.bats

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/haproxy_config_setup'
20+
load '../../libs/resource_client'
21+
load '../../libs/version'
22+
load '../../libs/haproxy_version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "tcp_checks: Add a new connect TCP check to a backend" {
27+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/connect.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
28+
assert_equal "$SC" 201
29+
}
30+
31+
@test "tcp_checks: Add a new send TCP check to a backend" {
32+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/send.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
33+
assert_equal "$SC" 201
34+
}
35+
36+
@test "tcp_checks: Add a new expect TCP check to a backend" {
37+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/expect.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
38+
assert_equal "$SC" 201
39+
}
40+
41+
@test "tcp_checks: Add a new send-binary TCP check to a backend" {
42+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/send_binary.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
43+
assert_equal "$SC" 201
44+
}
45+
46+
@test "tcp_checks: Add a new comment TCP check to a backend" {
47+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/comment.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
48+
if haproxy_version_ge "2.2"
49+
then
50+
assert_equal "$SC" 201
51+
else
52+
assert_equal "$SC" 400
53+
fi
54+
}
55+
56+
@test "tcp_checks: Add a new send-lf TCP check to a backend" {
57+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/send_lf.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
58+
if haproxy_version_ge "2.2"
59+
then
60+
assert_equal "$SC" 201
61+
else
62+
assert_equal "$SC" 400
63+
fi
64+
}
65+
66+
@test "tcp_checks: Add a new send-binary-lf TCP check to a backend" {
67+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/send_binary_lf.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
68+
if haproxy_version_ge "2.2"
69+
then
70+
assert_equal "$SC" 201
71+
else
72+
assert_equal "$SC" 400
73+
fi
74+
}
75+
76+
# @test "tcp_checks: Add a new set-var and uset-var TCP check to a backend" {
77+
# resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/set_var.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
78+
# if haproxy_version_ge "2.2"
79+
# then
80+
# assert_equal "$SC" 201
81+
# else
82+
# assert_equal "$SC" 400
83+
# fi
84+
# resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/unset_var.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
85+
# if haproxy_version_ge "2.2"
86+
# then
87+
# assert_equal "$SC" 201
88+
# else
89+
# assert_equal "$SC" 400
90+
# fi
91+
# }
92+
93+
@test "tcp_checks: Add an empty TCP check to a backend" {
94+
resource_post "$_TCP_CHECKS_CERTS_BASE_PATH" "data/empty.json" "parent_type=backend&parent_name=test_backend_add&force_reload=true"
95+
if haproxy_version_ge "2.2"
96+
then
97+
assert_equal "$SC" 422
98+
else
99+
assert_equal "$SC" 422
100+
fi
101+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"action": "comment",
3+
"log_message": "log_message",
4+
"index": 0
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"action": "connect",
3+
"index": 0
4+
}

e2e/tests/tcp_checks/data/empty.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

e2e/tests/tcp_checks/data/expect.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"action": "expect",
3+
"match": "string",
4+
"pattern": "role:master",
5+
"index": 0
6+
}

e2e/tests/tcp_checks/data/haproxy.cfg

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
backend test_backend_add
11+
mode tcp
12+
option tcp-check
13+
14+
backend test_backend_replace
15+
mode tcp
16+
option tcp-check
17+
tcp-check connect
18+
tcp-check send PING\r\n
19+
tcp-check expect string +PONG
20+
tcp-check send-binary 50494e470d0a
21+
22+
backend test_backend_get
23+
mode tcp
24+
option tcp-check
25+
tcp-check connect
26+
tcp-check send PING\r\n
27+
tcp-check expect string +PONG
28+
tcp-check send-binary 50494e470d0a
29+
30+
backend test_backend_delete
31+
mode tcp
32+
option tcp-check
33+
tcp-check connect
34+
tcp-check send PING\r\n
35+
tcp-check expect string +PONG
36+
tcp-check send-binary 50494e470d0a

e2e/tests/tcp_checks/data/put.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"action": "comment",
3+
"log_message": "test-comment-replace",
4+
"index": 0
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"action": "connect",
3+
"log_message": "replace",
4+
"index": 0
5+
}

0 commit comments

Comments
 (0)