Skip to content

Commit 36bb18b

Browse files
Pratik Mohantymjuraga
authored andcommitted
BUG/MINOR: table: Add support for table in peers section
1 parent ec35277 commit 36bb18b

34 files changed

+5073
-30
lines changed

configure_data_plane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
570570
api.PeerEntryGetPeerEntriesHandler = &handlers.GetPeerEntriesHandlerImpl{Client: client}
571571
api.PeerEntryReplacePeerEntryHandler = &handlers.ReplacePeerEntryHandlerImpl{Client: client, ReloadAgent: ra}
572572

573+
// setup tables handlers
574+
api.TableCreateTableHandler = &handlers.CreateTableHandlerImpl{Client: client, ReloadAgent: ra}
575+
api.TableDeleteTableHandler = &handlers.DeleteTableHandlerImpl{Client: client, ReloadAgent: ra}
576+
api.TableGetTableHandler = &handlers.GetTableHandlerImpl{Client: client}
577+
api.TableGetTablesHandler = &handlers.GetTablesHandlerImpl{Client: client}
578+
api.TableReplaceTableHandler = &handlers.ReplaceTableHandlerImpl{Client: client, ReloadAgent: ra}
579+
573580
// setup http-errors sections handlers
574581
api.HTTPErrorsCreateHTTPErrorsSectionHandler = &handlers.CreateHTTPErrorsSectionHandlerImpl{Client: client, ReloadAgent: ra}
575582
api.HTTPErrorsDeleteHTTPErrorsSectionHandler = &handlers.DeleteHTTPErrorsSectionHandlerImpl{Client: client, ReloadAgent: ra}

e2e/tests/table/add.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
24+
load 'utils/_helpers'
25+
26+
@test "table: Add a new table to peers" {
27+
resource_post "$_REQ_RULES_BASE_PATH" "data/post.json" "peer_section=mycluster&force_reload=true"
28+
assert_equal "$SC" 201
29+
}

e2e/tests/table/data/haproxy.cfg

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
defaults
11+
mode http
12+
maxconn 3000
13+
log global
14+
option httplog
15+
option redispatch
16+
option dontlognull
17+
option http-server-close
18+
option forwardfor except 127.0.0.0/8
19+
timeout http-request 10s
20+
timeout check 10s
21+
timeout connect 10s
22+
timeout client 1m
23+
timeout queue 1m
24+
timeout server 1m
25+
timeout http-keep-alive 10s
26+
retries 3
27+
28+
peers mycluster
29+
enabled
30+
table t1 type string len 1000 size 200k expire 5m nopurge store gpc0,conn_rate(30s)

e2e/tests/table/data/post.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "t2",
3+
"type": "ip",
4+
"size": "2k",
5+
"store": "gpc0,gpc1,conn_rate(30s)"
6+
}

e2e/tests/table/data/put.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "t1",
3+
"type": "ip",
4+
"size": "2m",
5+
"store": "gpc0,gpc1,conn_rate(30s)"
6+
}

e2e/tests/table/delete.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
24+
load 'utils/_helpers'
25+
26+
@test "table: Delete a table from peers" {
27+
#
28+
# Deleting first
29+
#
30+
resource_delete "$_REQ_RULES_BASE_PATH/t1" "peer_section=mycluster&force_reload=true"
31+
assert_equal "$SC" 204
32+
#
33+
# Not found
34+
#
35+
resource_delete "$_REQ_RULES_BASE_PATH/t1" "peer_section=mycluster&force_reload=true"
36+
assert_equal "$SC" 404
37+
}

e2e/tests/table/get.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
24+
load 'utils/_helpers'
25+
26+
@test "table: Return one table from peers" {
27+
resource_get "$_REQ_RULES_BASE_PATH/t1" "peer_section=mycluster"
28+
assert_equal "$SC" 200
29+
assert_equal "$(get_json_path "$BODY" ".data.name")" "t1"
30+
assert_equal "$(get_json_path "$BODY" ".data.type")" "string"
31+
assert_equal "$(get_json_path "$BODY" ".data.type_len")" "1000"
32+
assert_equal "$(get_json_path "$BODY" ".data.size")" "200k"
33+
assert_equal "$(get_json_path "$BODY" ".data.expire")" "5m"
34+
assert_equal "$(get_json_path "$BODY" ".data.no_purge")" "true"
35+
assert_equal "$(get_json_path "$BODY" ".data.store")" "gpc0,conn_rate(30s)"
36+
}
37+

e2e/tests/table/list.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
24+
load 'utils/_helpers'
25+
26+
@test "table: Return an array of all tables from peers" {
27+
resource_get "$_REQ_RULES_BASE_PATH" "peer_section=mycluster"
28+
assert_equal "$SC" 200
29+
assert_equal "$(get_json_path "$BODY" ".data[0].name")" "t1"
30+
assert_equal "$(get_json_path "$BODY" ".data[0].type")" "string"
31+
assert_equal "$(get_json_path "$BODY" ".data[0].type_len")" "1000"
32+
assert_equal "$(get_json_path "$BODY" ".data[0].size")" "200k"
33+
assert_equal "$(get_json_path "$BODY" ".data[0].expire")" "5m"
34+
assert_equal "$(get_json_path "$BODY" ".data[0].no_purge")" "true"
35+
assert_equal "$(get_json_path "$BODY" ".data[0].store")" "gpc0,conn_rate(30s)"
36+
}
37+

e2e/tests/table/replace.bats

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
24+
load 'utils/_helpers'
25+
26+
@test "table: Replace table values in peers" {
27+
resource_put "$_REQ_RULES_BASE_PATH/t1" "data/put.json" "peer_section=mycluster&force_reload=true"
28+
assert_equal "$SC" 200
29+
resource_get "$_REQ_RULES_BASE_PATH/t1" "peer_section=mycluster"
30+
assert_equal "$SC" 200
31+
assert_equal "$(get_json_path "$BODY" ".data.name")" "t1"
32+
assert_equal "$(get_json_path "$BODY" ".data.type")" "ip"
33+
assert_equal "$(get_json_path "$BODY" ".data.size")" "2m"
34+
assert_equal "$(get_json_path "$BODY" ".data.store")" "gpc0,gpc1,conn_rate(30s)"
35+
}

e2e/tests/table/utils/_helpers.bash

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
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+
_REQ_RULES_BASE_PATH="/services/haproxy/configuration/tables"

0 commit comments

Comments
 (0)