Fix weighted round-robin about UDP listener

'lb_algo rr' in keepalived won't work correctly with weight
for UDP listeners, it should be 'lb_algo wrr'.

'wrr' is superset of 'rr' algorithm, as round-robin is
a specical instance of the weighted round-robin scheduling,
in which all the weights are equal. [1]

Algorithm in HAProxy is set to 'roundrobin', which also support
weights, but in keepalived must be set to 'wrr' to work with
the weighted round-robin scheduling, as it is different to 'rr'.

[1] https://www.keepalived.org/doc/scheduling_algorithms.html

Story 2008462
Task 41491

Conflicts:
	octavia/tests/unit/common/jinja/lvs/test_jinja_cfg.py
	octavia/tests/unit/common/sample_configs/sample_configs_combined.py

NOTE(Xing Zhang): The first file does not exist in stable/victoria
due to unit test structure was fixed, file renamed from test_lvs_jinja_cfg.py,
(patch I6d84047b3481a2bf6bf9bd17d482fb504dbc752b) was introduced in stable/wallaby.
The second file has conflict due to the SCTP is supported by the amphora provider
in the Wallaby release. (patch I30997ae6cc6b8ec724f0e9dcfdfe49356b320ff4)

This backport removes SCTP in commit message and releasenote due to SCTP
was introduced in the Wallaby release.

Change-Id: Ic63929d8864e5285baf70dd85e6362988bf2863f
(cherry picked from commit 5352a10f62)
(cherry picked from commit d9603b3d21)
This commit is contained in:
Xing Zhang 2021-03-02 12:55:35 +08:00
parent 8b210bb52a
commit c7640b90ad
No known key found for this signature in database
GPG Key ID: 43F80E57B910E3B0
7 changed files with 21 additions and 15 deletions

View File

@ -28,7 +28,7 @@ PROTOCOL_MAP = {
} }
BALANCE_MAP = { BALANCE_MAP = {
constants.LB_ALGORITHM_ROUND_ROBIN: 'rr', constants.LB_ALGORITHM_ROUND_ROBIN: 'wrr',
constants.LB_ALGORITHM_LEAST_CONNECTIONS: 'lc', constants.LB_ALGORITHM_LEAST_CONNECTIONS: 'lc',
constants.LB_ALGORITHM_SOURCE_IP: 'sh' constants.LB_ALGORITHM_SOURCE_IP: 'sh'
} }

View File

@ -42,7 +42,7 @@ class KeepalivedLvsTestCase(base.TestCase):
"# Configuration for Listener %(listener_id)s\n\n" "# Configuration for Listener %(listener_id)s\n\n"
"net_namespace haproxy-amphora\n\n" "net_namespace haproxy-amphora\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol udp\n" " protocol udp\n"
" delay_loop 30\n" " delay_loop 30\n"

View File

@ -56,7 +56,7 @@ CFG_FILE_TEMPLATE_v4 = (
"# Configuration for Listener %(listener_id)s\n\n" "# Configuration for Listener %(listener_id)s\n\n"
"net_namespace %(ns_name)s\n\n" "net_namespace %(ns_name)s\n\n"
"virtual_server 10.0.0.37 7777 {\n" "virtual_server 10.0.0.37 7777 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol udp\n\n\n" " protocol udp\n\n\n"
" # Configuration for Pool %(pool_id)s\n" " # Configuration for Pool %(pool_id)s\n"
@ -97,7 +97,7 @@ CFG_FILE_TEMPLATE_v6 = (
"# Configuration for Listener %(listener_id)s\n\n" "# Configuration for Listener %(listener_id)s\n\n"
"net_namespace %(ns_name)s\n\n" "net_namespace %(ns_name)s\n\n"
"virtual_server fd79:35e2:9963:0:f816:3eff:fe6d:7a2a 7777 {\n" "virtual_server fd79:35e2:9963:0:f816:3eff:fe6d:7a2a 7777 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol udp\n\n\n" " protocol udp\n\n\n"
" # Configuration for Pool %(pool_id)s\n" " # Configuration for Pool %(pool_id)s\n"

View File

@ -40,7 +40,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" persistence_timeout 33\n" " persistence_timeout 33\n"
@ -86,7 +86,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" delay_loop 30\n" " delay_loop 30\n"
@ -129,7 +129,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" delay_loop 30\n" " delay_loop 30\n"
@ -172,7 +172,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" delay_loop 30\n" " delay_loop 30\n"
@ -227,7 +227,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n\n\n" " protocol UDP\n\n\n"
" # Configuration for Pool sample_pool_id_0\n" " # Configuration for Pool sample_pool_id_0\n"
@ -245,7 +245,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n\n\n" " protocol UDP\n\n\n"
" # Pool sample_pool_id_1 is disabled\n" " # Pool sample_pool_id_1 is disabled\n"
@ -356,7 +356,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" delay_loop 30\n" " delay_loop 30\n"
@ -417,7 +417,7 @@ class TestLvsCfg(base.TestCase):
"# Configuration for Listener sample_listener_id_1\n\n" "# Configuration for Listener sample_listener_id_1\n\n"
"net_namespace amphora-haproxy\n\n" "net_namespace amphora-haproxy\n\n"
"virtual_server 10.0.0.2 80 {\n" "virtual_server 10.0.0.2 80 {\n"
" lb_algo rr\n" " lb_algo wrr\n"
" lb_kind NAT\n" " lb_kind NAT\n"
" protocol UDP\n" " protocol UDP\n"
" delay_loop 30\n" " delay_loop 30\n"

View File

@ -470,7 +470,7 @@ RET_UDP_POOL = {
'id': 'sample_pool_id_1', 'id': 'sample_pool_id_1',
'enabled': True, 'enabled': True,
'health_monitor': UDP_HEALTH_MONITOR_NO_SCRIPT, 'health_monitor': UDP_HEALTH_MONITOR_NO_SCRIPT,
'lb_algorithm': 'rr', 'lb_algorithm': 'wrr',
'members': [UDP_MEMBER_1, UDP_MEMBER_2], 'members': [UDP_MEMBER_1, UDP_MEMBER_2],
'protocol': 'udp', 'protocol': 'udp',
'session_persistence': UDP_SOURCE_IP_BODY 'session_persistence': UDP_SOURCE_IP_BODY
@ -482,7 +482,7 @@ RET_UDP_LISTENER = {
'id': 'sample_pool_id_1', 'id': 'sample_pool_id_1',
'enabled': True, 'enabled': True,
'health_monitor': RET_UDP_HEALTH_MONITOR, 'health_monitor': RET_UDP_HEALTH_MONITOR,
'lb_algorithm': 'rr', 'lb_algorithm': 'wrr',
'members': [UDP_MEMBER_1, UDP_MEMBER_2], 'members': [UDP_MEMBER_1, UDP_MEMBER_2],
'protocol': 'udp', 'protocol': 'udp',
'session_persistence': UDP_SOURCE_IP_BODY 'session_persistence': UDP_SOURCE_IP_BODY

View File

@ -467,7 +467,7 @@ RET_UDP_POOL = {
'id': 'sample_pool_id_1', 'id': 'sample_pool_id_1',
'enabled': True, 'enabled': True,
'health_monitor': UDP_HEALTH_MONITOR_NO_SCRIPT, 'health_monitor': UDP_HEALTH_MONITOR_NO_SCRIPT,
'lb_algorithm': 'rr', 'lb_algorithm': 'wrr',
'members': [UDP_MEMBER_1, UDP_MEMBER_2], 'members': [UDP_MEMBER_1, UDP_MEMBER_2],
'protocol': 'udp', 'protocol': 'udp',
'session_persistence': UDP_SOURCE_IP_BODY 'session_persistence': UDP_SOURCE_IP_BODY

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fix weighted round-robin for UDP listeners with keepalived and lvs.
The algorithm must be specified as 'wrr' in order for weighted
round-robin to work correctly, but was being set to 'rr'.