Skip to content

Commit 2c99b56

Browse files
hdurand0710mjuraga
authored andcommitted
BUG/MEDIUM: change track-sc<0|1|2> to track-sc
1 parent 150525f commit 2c99b56

21 files changed

+770
-10
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
## tune.stick-counters is a haproxy >= 2.8 global parameter
28+
@test "http_request_rules: Add a new HTTP Request Rule track-sc to backend" {
29+
if haproxy_version_ge "2.8"
30+
then
31+
# Using new track-sc with track_sc_stick_counter
32+
resource_post "$_REQ_RULES_BASE_PATH" "data/post-track-sc.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
33+
assert_equal "$SC" 201
34+
35+
resource_get "$_REQ_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_sticksc"
36+
assert_equal "$SC" 200
37+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
38+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
39+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
40+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
41+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
42+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 5
43+
fi
44+
}
45+
46+
@test "http_request_rules: Add a new HTTP Request Rule track-sc-x to backend" {
47+
# Using old track-sc(0|1|2)
48+
if haproxy_version_ge "2.8"
49+
then
50+
resource_post "$_REQ_RULES_BASE_PATH" "data/post-track-sc-x.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
51+
assert_equal "$SC" 201
52+
53+
resource_get "$_REQ_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_sticksc"
54+
assert_equal "$SC" 200
55+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
56+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
57+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
58+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
59+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
60+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 0
61+
fi
62+
}
63+
64+
@test "http_request_rules: Fail - Add a new HTTP Request Rule track-sc to backend - when track_sc_stick_counter is missing" {
65+
# Using new track-sc with track_sc_stick_counter
66+
# Fail due to missing track_sc_stick_counter
67+
if haproxy_version_ge "2.8"
68+
then
69+
resource_post "$_REQ_RULES_BASE_PATH" "data/post-track-sc-fail.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
70+
assert_equal "$SC" 400
71+
fi
72+
}

e2e/tests/http_request_rules/data/haproxy_2.8.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ global
66
pidfile /var/run/haproxy.pid
77
stats socket /var/lib/haproxy/stats level admin
88
log 127.0.0.1 local2
9+
tune.stick-counters 6
910

1011
defaults
1112
mode http
@@ -34,9 +35,21 @@ frontend test_frontend
3435
http-request del-header X-Del-Frontend if { src 10.1.0.0/16 }
3536
http-request sc-add-gpc(0,1) 1 if FALSE
3637

38+
frontend test_sticksc
39+
bind *:1248
40+
default_backend test_sticksc
41+
http-request track-sc0 src table test_sticksc if TRUE
42+
http-request track-sc5 src table test_sticksc if TRUE
43+
3744
backend test_backend
3845
mode http
3946
balance roundrobin
4047
option forwardfor
4148
http-request add-header X-Add-Backend CustomValue unless { src 192.168.0.0/16 }
4249
http-request del-header X-Del-Backend if { src 10.1.0.0/16 }
50+
51+
backend test_sticksc
52+
http-request track-sc0 src table test_sticksc if TRUE
53+
http-request track-sc5 src table test_sticksc if TRUE
54+
stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
55+
server app1 127.0.0.1:4444 check
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc",
6+
"track_sc_table": "test_sticksc",
7+
"track_sc_key": "src"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc0",
6+
"track-sc0-table": "test_sticksc",
7+
"track-sc0-key": "src"
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc",
6+
"track_sc_table": "test_sticksc",
7+
"track_sc_key": "src",
8+
"track_sc_stick_counter": 5
9+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
@test "http_request_rules: Return one track-sc HTTP Request Rule from frontend" {
28+
if haproxy_version_ge "2.8"
29+
then
30+
resource_get "$_REQ_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_sticksc"
31+
assert_equal "$SC" 200
32+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
33+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
34+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
35+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
36+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
37+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 0
38+
39+
resource_get "$_REQ_RULES_BASE_PATH/1" "parent_type=frontend&parent_name=test_sticksc"
40+
assert_equal "$SC" 200
41+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
42+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
43+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
44+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
45+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
46+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 5
47+
fi
48+
}
49+
50+
@test "http_request_rules: Return one track-sc HTTP Request Rule from backend" {
51+
if haproxy_version_ge "2.8"
52+
then
53+
resource_get "$_REQ_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_sticksc"
54+
assert_equal "$SC" 200
55+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
56+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
57+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
58+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
59+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
60+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 0
61+
62+
resource_get "$_REQ_RULES_BASE_PATH/1" "parent_type=backend&parent_name=test_sticksc"
63+
assert_equal "$SC" 200
64+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
65+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
66+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
67+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
68+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
69+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 5
70+
fi
71+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
## tune.stick-counters is a haproxy >= 2.8 global parameter
28+
@test "http_response_rules: Add a new HTTP Response Rule track-sc to backend" {
29+
if haproxy_version_ge "2.8"
30+
then
31+
# Using new track-sc with track_sc_stick_counter
32+
resource_post "$_RES_RULES_BASE_PATH" "data/post-track-sc.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
33+
assert_equal "$SC" 201
34+
35+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_sticksc"
36+
assert_equal "$SC" 200
37+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
38+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
39+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
40+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
41+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
42+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 5
43+
fi
44+
}
45+
46+
@test "http_response_rules: Add a new HTTP Response Rule track-sc-x to backend" {
47+
if haproxy_version_ge "2.8"
48+
then
49+
# Using old track-sc(0|1|2)
50+
resource_post "$_RES_RULES_BASE_PATH" "data/post-track-sc-x.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
51+
assert_equal "$SC" 201
52+
53+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_sticksc"
54+
assert_equal "$SC" 200
55+
assert_equal "$(get_json_path "$BODY" ".data.type")" "track-sc"
56+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
57+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "TRUE"
58+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_key")" "src"
59+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_table")" "test_sticksc"
60+
assert_equal "$(get_json_path "$BODY" ".data.track_sc_stick_counter")" 0
61+
fi
62+
}
63+
64+
@test "http_response_rules: Fail - Add a new HTTP Response Rule track-sc to backend - when track_sc_stick_counter is missing" {
65+
if haproxy_version_ge "2.8"
66+
then
67+
# Using new track-sc with track_sc_stick_counter
68+
# Fail due to missing track_sc_stick_counter
69+
resource_post "$_RES_RULES_BASE_PATH" "data/post-track-sc-fail.json" "parent_type=backend&parent_name=test_sticksc&force_reload=true"
70+
assert_equal "$SC" 400
71+
fi
72+
}

e2e/tests/http_response_rules/data/haproxy_2.8.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ global
66
pidfile /var/run/haproxy.pid
77
stats socket /var/lib/haproxy/stats level admin
88
log 127.0.0.1 local2
9+
tune.stick-counters 6
910

1011
defaults
1112
mode http
@@ -34,9 +35,21 @@ frontend test_frontend
3435
http-response del-header X-Del-Frontend if { src 10.1.0.0/16 }
3536
http-response sc-add-gpc(0,1) 1 if FALSE
3637

38+
frontend test_sticksc
39+
bind *:1248
40+
default_backend test_sticksc
41+
http-response track-sc0 src table test_sticksc if TRUE
42+
http-response track-sc5 src table test_sticksc if TRUE
43+
3744
backend test_backend
3845
mode http
3946
balance roundrobin
4047
option forwardfor
4148
http-response add-header X-Add-Backend CustomValue unless { src 192.168.0.0/16 }
4249
http-response del-header X-Del-Backend if { src 10.1.0.0/16 }
50+
51+
backend test_sticksc
52+
http-response track-sc0 src table test_sticksc if TRUE
53+
http-response track-sc5 src table test_sticksc if TRUE
54+
stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
55+
server app1 127.0.0.1:4444 check
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc",
6+
"track_sc_table": "test_sticksc",
7+
"track_sc_key": "src"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc0",
6+
"track-sc0-table": "test_sticksc",
7+
"track-sc0-key": "src"
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "TRUE",
4+
"index": 0,
5+
"type": "track-sc",
6+
"track_sc_table": "test_sticksc",
7+
"track_sc_key": "src",
8+
"track_sc_stick_counter": 5
9+
}

0 commit comments

Comments
 (0)