Merge "Handle feature compatibility of HAProxy server-state-file option" into stable/train
This commit is contained in:
commit
e52a2ebabd
|
@ -740,6 +740,7 @@ AMP_NETNS_SVC_PREFIX = 'amphora-netns'
|
|||
|
||||
# Amphora Feature Compatibility
|
||||
HTTP_REUSE = 'has_http_reuse'
|
||||
SERVER_STATE_FILE = 'has_server_state_file'
|
||||
|
||||
# TODO(johnsom) convert this to octavia_lib constant flavor
|
||||
# once octavia is transitioned to use octavia_lib
|
||||
|
|
|
@ -99,6 +99,7 @@ class JinjaTemplater(object):
|
|||
# Is it newer than haproxy 1.5?
|
||||
if not (int(haproxy_versions[0]) < 2 and int(haproxy_versions[1]) < 6):
|
||||
feature_compatibility[constants.HTTP_REUSE] = True
|
||||
feature_compatibility[constants.SERVER_STATE_FILE] = True
|
||||
|
||||
return self.render_loadbalancer_obj(
|
||||
host_amphora, listeners, tls_certs=tls_certs,
|
||||
|
@ -161,7 +162,8 @@ class JinjaTemplater(object):
|
|||
listeners[0].load_balancer.id)
|
||||
state_file_path = '%s/%s/servers-state' % (
|
||||
self.base_amp_path,
|
||||
listeners[0].load_balancer.id)
|
||||
listeners[0].load_balancer.id) if feature_compatibility.get(
|
||||
constants.SERVER_STATE_FILE) else ''
|
||||
return self._get_template().render(
|
||||
{'loadbalancer': loadbalancer,
|
||||
'stats_sock': socket_path,
|
||||
|
|
|
@ -20,7 +20,9 @@ global
|
|||
log {{ log_http | default('/run/rsyslog/octavia/log', true)}} local{{ user_log_facility }}
|
||||
log {{ log_server | default('/run/rsyslog/octavia/log', true)}} local{{ administrative_log_facility }} notice
|
||||
stats socket {{ sock_path }} mode 0666 level user
|
||||
{% if state_file %}
|
||||
server-state-file {{ state_file }}
|
||||
{% endif %}
|
||||
{% if loadbalancer.global_connection_limit is defined %}
|
||||
maxconn {{ loadbalancer.global_connection_limit }}
|
||||
{% endif %}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
{% for listener in loadbalancer.listeners if listener.enabled %}
|
||||
{{- frontend_macro(constants, listener, loadbalancer.vip_address) }}
|
||||
{% for pool in listener.pools if pool.enabled %}
|
||||
{{- backend_macro(constants, listener, pool, loadbalancer) }}
|
||||
{{- backend_macro(constants, listener, pool, loadbalancer, state_file) }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
|
@ -234,7 +234,7 @@ frontend {{ listener.id }}
|
|||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro backend_macro(constants, listener, pool, loadbalancer) %}
|
||||
{% macro backend_macro(constants, listener, pool, loadbalancer, state_file) %}
|
||||
backend {{ pool.id }}:{{ listener.id }}
|
||||
{% if pool.protocol.lower() == constants.PROTOCOL_PROXY.lower() %}
|
||||
mode {{ listener.protocol_mode }}
|
||||
|
@ -276,7 +276,9 @@ backend {{ pool.id }}:{{ listener.id }}
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% if pool.health_monitor and pool.health_monitor.enabled %}
|
||||
{% if state_file %}
|
||||
load-server-state-from-file global
|
||||
{% endif %}
|
||||
timeout check {{ pool.health_monitor.timeout }}s
|
||||
{% if (pool.health_monitor.type ==
|
||||
constants.HEALTH_MONITOR_HTTP or pool.health_monitor.type ==
|
||||
|
|
|
@ -32,8 +32,6 @@ class HAProxyCompatTestCase(base.TestCase):
|
|||
" log /run/rsyslog/octavia/log local1 notice\n"
|
||||
" stats socket /var/lib/octavia/sample_loadbalancer_id_1.sock"
|
||||
" mode 0666 level user\n"
|
||||
" server-state-file /var/lib/octavia/sample_loadbalancer_id_1"
|
||||
"/servers-state\n"
|
||||
" maxconn {maxconn}\n\n"
|
||||
"defaults\n"
|
||||
" log global\n"
|
||||
|
|
|
@ -61,7 +61,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -113,7 +112,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -148,7 +146,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -175,7 +172,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -212,7 +208,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -248,7 +243,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -277,7 +271,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -318,7 +311,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode tcp\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -355,7 +347,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode tcp\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option ssl-hello-chk\n"
|
||||
" fullconn {maxconn}\n"
|
||||
|
@ -423,7 +414,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option external-check\n"
|
||||
" external-check command /var/lib/octavia/ping-wrapper.sh\n"
|
||||
|
@ -484,7 +474,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.1\\r\\nHost:\\ "
|
||||
"testlab.com\n"
|
||||
|
@ -562,7 +551,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" balance roundrobin\n"
|
||||
" stick-table type ip size 10k\n"
|
||||
" stick on src\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -590,7 +578,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" stick-table type string len 64 size 10k\n"
|
||||
" stick store-response res.cook(JSESSIONID)\n"
|
||||
" stick match req.cook(JSESSIONID)\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -714,7 +701,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -731,7 +717,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /healthmon.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -753,7 +738,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -782,7 +766,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -813,7 +796,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" fullconn {maxconn}\n"
|
||||
" option allbackups\n"
|
||||
|
@ -840,7 +822,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -876,7 +857,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -1106,7 +1086,7 @@ class TestHaproxyCfg(base.TestCase):
|
|||
defaults=defaults, logging="\n"),
|
||||
rendered_obj)
|
||||
|
||||
def test_http_reuse(self):
|
||||
def test_haproxy_cfg_1_8_vs_1_5(self):
|
||||
j_cfg = jinja_cfg.JinjaTemplater(
|
||||
base_amp_path='/var/lib/octavia',
|
||||
base_crt_dir='/var/lib/octavia/certs')
|
||||
|
@ -1114,7 +1094,12 @@ class TestHaproxyCfg(base.TestCase):
|
|||
sample_amphora = sample_configs_combined.sample_amphora_tuple()
|
||||
sample_proxy_listener = sample_configs_combined.sample_listener_tuple(
|
||||
be_proto='PROXY')
|
||||
# With http-reuse
|
||||
# With http-reuse and server-state-file
|
||||
go = (
|
||||
" server-state-file /var/lib/octavia/sample_loadbalancer_id_1/"
|
||||
"servers-state\n"
|
||||
" maxconn {maxconn}\n\n").format(
|
||||
maxconn=constants.HAPROXY_DEFAULT_MAXCONN)
|
||||
be = ("backend {pool_id}:{listener_id}\n"
|
||||
" mode http\n"
|
||||
" http-reuse safe\n"
|
||||
|
@ -1141,15 +1126,15 @@ class TestHaproxyCfg(base.TestCase):
|
|||
tls_certs=None,
|
||||
haproxy_versions=("1", "8", "1"))
|
||||
self.assertEqual(
|
||||
sample_configs_combined.sample_base_expected_config(backend=be),
|
||||
sample_configs_combined.sample_base_expected_config(
|
||||
global_opts=go, backend=be),
|
||||
rendered_obj)
|
||||
|
||||
# Without http-reuse
|
||||
# Without http-reuse and server-state-file
|
||||
be = ("backend {pool_id}:{listener_id}\n"
|
||||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" fullconn {maxconn}\n"
|
||||
" option allbackups\n"
|
||||
|
@ -1220,7 +1205,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -1236,7 +1220,6 @@ class TestHaproxyCfg(base.TestCase):
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /healthmon.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
|
|
@ -1086,7 +1086,6 @@ def sample_base_expected_config(frontend=None, logging=None, backend=None,
|
|||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" cookie SRV insert indirect nocache\n"
|
||||
" load-server-state-from-file global\n"
|
||||
" timeout check 31s\n"
|
||||
" option httpchk GET /index.html HTTP/1.0\\r\\n\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
|
@ -1120,7 +1119,5 @@ def sample_base_expected_config(frontend=None, logging=None, backend=None,
|
|||
" log /run/rsyslog/octavia/log local0\n"
|
||||
" log /run/rsyslog/octavia/log local1 notice\n"
|
||||
" stats socket /var/lib/octavia/sample_loadbalancer_id_1.sock"
|
||||
" mode 0666 level user\n"
|
||||
" server-state-file /var/lib/octavia/sample_loadbalancer_id_1"
|
||||
"/servers-state\n" +
|
||||
" mode 0666 level user\n" +
|
||||
global_opts + defaults + peers + frontend + logging + backend)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed backwards compatibility issue with the feature that preserves HAProxy
|
||||
server states between reloads.
|
||||
HAProxy version 1.5 or below do not support this feature, so Octavia
|
||||
will not to activate it on amphorae with those versions.
|
Loading…
Reference in New Issue