Merge "Add APP_COOKIE session persistence type"
This commit is contained in:
@@ -76,6 +76,14 @@ backend {{ pool.id }}
|
||||
stick-table type ip size {{ pool.stick_size }}
|
||||
{% endif %}
|
||||
stick on src
|
||||
{% elif pool.session_persistence.type == constants.SESSION_PERSISTENCE_APP_COOKIE %}
|
||||
{% if listener.topology == constants.TOPOLOGY_ACTIVE_STANDBY %}
|
||||
stick-table type string len 64 size {{ pool.stick_size }} peers {{ "%s_peers"|format(listener.id.replace("-", ""))|trim() }}
|
||||
{% else %}
|
||||
stick-table type string len 64 size {{ pool.stick_size }}
|
||||
{% endif %}
|
||||
stick store-response res.cook({{ pool.session_persistence.cookie_name }})
|
||||
stick match req.cook({{ pool.session_persistence.cookie_name }})
|
||||
{% elif pool.session_persistence.type == constants.SESSION_PERSISTENCE_HTTP_COOKIE %}
|
||||
cookie SRV insert indirect nocache
|
||||
{% endif %}
|
||||
|
@@ -21,8 +21,10 @@ SUPPORTED_LB_ALGORITHMS = (LB_ALGORITHM_LEAST_CONNECTIONS,
|
||||
|
||||
SESSION_PERSISTENCE_SOURCE_IP = 'SOURCE_IP'
|
||||
SESSION_PERSISTENCE_HTTP_COOKIE = 'HTTP_COOKIE'
|
||||
SESSION_PERSISTENCE_APP_COOKIE = 'APP_COOKIE'
|
||||
SUPPORTED_SP_TYPES = (SESSION_PERSISTENCE_SOURCE_IP,
|
||||
SESSION_PERSISTENCE_HTTP_COOKIE)
|
||||
SESSION_PERSISTENCE_HTTP_COOKIE,
|
||||
SESSION_PERSISTENCE_APP_COOKIE)
|
||||
|
||||
HEALTH_MONITOR_PING = 'PING'
|
||||
HEALTH_MONITOR_TCP = 'TCP'
|
||||
|
@@ -238,6 +238,29 @@ class TestHaproxyCfg(base.TestCase):
|
||||
sample_configs.sample_base_expected_config(backend=be),
|
||||
rendered_obj)
|
||||
|
||||
def test_render_template_appcookie_persistence(self):
|
||||
be = ("backend sample_pool_id_1\n"
|
||||
" mode http\n"
|
||||
" balance roundrobin\n"
|
||||
" stick-table type string len 64 size 10k\n"
|
||||
" stick store-response res.cook(JSESSIONID)\n"
|
||||
" stick match req.cook(JSESSIONID)\n"
|
||||
" timeout check 31\n"
|
||||
" option httpchk GET /index.html\n"
|
||||
" http-check expect rstatus 418\n"
|
||||
" option forwardfor\n"
|
||||
" server sample_member_id_1 10.0.0.99:82 "
|
||||
"weight 13 check inter 30s fall 3 rise 2\n"
|
||||
" server sample_member_id_2 10.0.0.98:82 "
|
||||
"weight 13 check inter 30s fall 3 rise 2\n\n")
|
||||
rendered_obj = self.jinja_cfg.render_loadbalancer_obj(
|
||||
sample_configs.sample_listener_tuple(
|
||||
persistence_type='APP_COOKIE',
|
||||
persistence_cookie='JSESSIONID'))
|
||||
self.assertEqual(
|
||||
sample_configs.sample_base_expected_config(backend=be),
|
||||
rendered_obj)
|
||||
|
||||
def test_transform_session_persistence(self):
|
||||
in_persistence = sample_configs.sample_session_persistence_tuple()
|
||||
ret = self.jinja_cfg._transform_session_persistence(in_persistence)
|
||||
|
@@ -27,7 +27,7 @@ def sample_amphora_tuple():
|
||||
|
||||
RET_PERSISTENCE = {
|
||||
'type': 'HTTP_COOKIE',
|
||||
'cookie_name': 'HTTP_COOKIE'}
|
||||
'cookie_name': None}
|
||||
|
||||
RET_MONITOR = {
|
||||
'id': 'sample_monitor_id_1',
|
||||
@@ -187,8 +187,8 @@ def sample_vip_tuple():
|
||||
|
||||
|
||||
def sample_listener_tuple(proto=None, monitor=True, persistence=True,
|
||||
persistence_type=None, tls=False, sni=False,
|
||||
peer_port=None, topology=None):
|
||||
persistence_type=None, persistence_cookie=None,
|
||||
tls=False, sni=False, peer_port=None, topology=None):
|
||||
proto = 'HTTP' if proto is None else proto
|
||||
topology = 'SINGLE' if topology is None else topology
|
||||
port = '443' if proto is 'HTTPS' or proto is 'TERMINATED_HTTPS' else '80'
|
||||
@@ -208,7 +208,8 @@ def sample_listener_tuple(proto=None, monitor=True, persistence=True,
|
||||
peer_port=peer_port,
|
||||
default_pool=sample_pool_tuple(
|
||||
proto=proto, monitor=monitor, persistence=persistence,
|
||||
persistence_type=persistence_type),
|
||||
persistence_type=persistence_type,
|
||||
persistence_cookie=persistence_cookie),
|
||||
connection_limit=98,
|
||||
tls_certificate_id='cont_id_1' if tls else '',
|
||||
sni_container_ids=['cont_id_2', 'cont_id_3'] if sni else [],
|
||||
@@ -256,14 +257,15 @@ def sample_tls_container_tuple(id='cont_id_1', certificate=None,
|
||||
|
||||
|
||||
def sample_pool_tuple(proto=None, monitor=True, persistence=True,
|
||||
persistence_type=None):
|
||||
persistence_type=None, persistence_cookie=None):
|
||||
proto = 'HTTP' if proto is None else proto
|
||||
in_pool = collections.namedtuple(
|
||||
'pool', 'id, protocol, lb_algorithm, members, health_monitor,'
|
||||
'session_persistence, enabled, operating_status')
|
||||
mon = sample_health_monitor_tuple(proto=proto) if monitor is True else None
|
||||
persis = sample_session_persistence_tuple(
|
||||
persistence_type=persistence_type) if persistence is True else None
|
||||
persistence_type=persistence_type,
|
||||
persistence_cookie=persistence_cookie) if persistence is True else None
|
||||
return in_pool(
|
||||
id='sample_pool_id_1',
|
||||
protocol=proto,
|
||||
@@ -291,12 +293,13 @@ def sample_member_tuple(id, ip, enabled=True, operating_status='ACTIVE'):
|
||||
operating_status=operating_status)
|
||||
|
||||
|
||||
def sample_session_persistence_tuple(persistence_type=None):
|
||||
def sample_session_persistence_tuple(persistence_type=None,
|
||||
persistence_cookie=None):
|
||||
spersistence = collections.namedtuple('SessionPersistence',
|
||||
'type, cookie_name')
|
||||
pt = 'HTTP_COOKIE' if persistence_type is None else persistence_type
|
||||
return spersistence(type=pt,
|
||||
cookie_name=pt)
|
||||
cookie_name=persistence_cookie)
|
||||
|
||||
|
||||
def sample_health_monitor_tuple(proto='HTTP'):
|
||||
|
Reference in New Issue
Block a user