Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 799a1da

Browse files
committed
remove appsession which is deprecated in Haproxy 1.6
1 parent 55edf98 commit 799a1da

11 files changed

Lines changed: 36 additions & 66 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ Settings here can overwrite the settings in HAProxy, which are only applied to t
242242

243243
|Environment Variable|Description|
244244
|:-----:|:----------|
245-
|APPSESSION|sticky session option, possible value `JSESSIONID len 52 timeout 3h`. See:[HAProxy:appsession](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-appsession)|
246245
|BALANCE|load balancing algorithm to use. Possible values include: `roundrobin`, `static-rr`, `source`, `leastconn`. See:[HAProxy:balance](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-balance)|
247246
|COOKIE|sticky session option. Possible value `SRV insert indirect nocache`. See:[HAProxy:cookie](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-cookie)|
248247
|DEFAULT_SSL_CERT|similar to SSL_CERT, but stores the pem file at `/certs/cert0.pem` as the default ssl certs. If multiple `DEFAULT_SSL_CERT` are specified in linked services and HAProxy, the behavior is undefined|
@@ -367,10 +366,9 @@ Copy the output and set it as the value of `SSL_CERT` or `DEFAULT_SSL_CERT`.
367366
There are three method to setup affinity and sticky session:
368367

369368
1. set `BALANCE=source` in your application service. When setting `source` method of balance, HAProxy will hash the client IP address and make sure that the same IP always goes to the same server.
370-
2. set `APPSESSION=<value>`. use application session to determine which server a client should connect to. Possible value of `<value>` could be `JSESSIONID len 52 timeout 3h`
371369
2. set `COOKIE=<value>`. use application cookie to determine which server a client should connect to. Possible value of `<value>` could be `SRV insert indirect nocache`
372370

373-
Check [HAProxy:appsession](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-appsession) and [HAProxy:cookie](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-cookie) for more information.
371+
Check [HAProxy:cookie](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-cookie) for more information.
374372

375373

376374
## TCP load balancing

haproxy/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import logging
12
import os
23
import re
3-
import logging
44

55
logger = logging.getLogger("haproxy")
66

7+
78
class RunningMode():
89
LegacyMode, ComposeMode, SwarmMode, CloudMode = range(4)
910

@@ -36,7 +37,7 @@ def parse_extra_frontend_settings(envvars):
3637
try:
3738
with open(v) as file:
3839
for line in file:
39-
settings.append(line.strip())
40+
settings.append(line.strip())
4041
except Exception as e:
4142
logger.info("Error reading %s at '%s', error %s" % (k, v, e))
4243

@@ -67,7 +68,7 @@ def parse_additional_backend_settings(envvars):
6768
for line in file:
6869
settings.append(line.strip())
6970
except Exception as e:
70-
logger.info("Error reading %s at '%s', error %s" % (k, v, e))
71+
logger.info("Error reading %s at '%s', error %s" % (k, v, e))
7172

7273
if len(settings) > 0:
7374
if server in settings_dict:

haproxy/haproxycfg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import copy
2-
import logging
32
import time
43
from collections import OrderedDict
54

@@ -262,9 +261,10 @@ def _config_global_section():
262261
for line in file:
263262
statements.append(line.strip())
264263
except Exception as e:
265-
logger.info("Error reading EXTRA_GLOBAL_SETTINGS_FILE at '%s', error %s" % (EXTRA_GLOBAL_SETTINGS_FILE, e))
264+
logger.info(
265+
"Error reading EXTRA_GLOBAL_SETTINGS_FILE at '%s', error %s" % (EXTRA_GLOBAL_SETTINGS_FILE, e))
266266
cfg["global"] = statements
267-
267+
268268
return cfg
269269

270270
@staticmethod
@@ -299,7 +299,8 @@ def _config_defaults_section():
299299
for line in file:
300300
statements.append(line.strip())
301301
except Exception as e:
302-
logger.info("Error reading EXTRA_DEFAULT_SETTINGS_FILE at '%s', error %s" % (EXTRA_DEFAULT_SETTINGS_FILE, e))
302+
logger.info(
303+
"Error reading EXTRA_DEFAULT_SETTINGS_FILE at '%s', error %s" % (EXTRA_DEFAULT_SETTINGS_FILE, e))
303304
cfg["defaults"] = statements
304305
return cfg
305306

haproxy/helper/backend_helper.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ def get_sticky_setting(details, service_alias):
100100
setting = []
101101
is_sticky = False
102102

103-
appsession = get_service_attribute(details, "appsession", service_alias)
104-
if appsession:
105-
setting.append("appsession %s" % appsession)
106-
is_sticky = True
107-
108103
cookie = get_service_attribute(details, "cookie", service_alias)
109104
if cookie:
110105
setting.append("cookie %s" % cookie)

haproxy/helper/swarm_mode_link_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_task_links(tasks, services, haproxy_service_id, haproxy_nets):
4545
task_slot = "%d" % task.get("Slot", 0)
4646
task_service_id = task.get("ServiceID", "")
4747
task_service_name = services_id_name.get(task_service_id, "")
48-
task_labels = services_id_labels.get(task_service_id,{})
48+
task_labels = services_id_labels.get(task_service_id, {})
4949

5050
if task_labels.get(LABEL_SWARM_MODE_DEACTIVATE, "").lower() == "true":
5151
continue

haproxy/parser/base_parser.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ def parse_virtual_host(value):
133133
def parse_force_ssl(value):
134134
return value
135135

136-
@staticmethod
137-
def parse_appsession(value):
138-
return value
139-
140136
@staticmethod
141137
def parse_balance(value):
142138
return value

tests/unit/helper/test_backend_helper.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,19 @@ def test_get_balance_setting(self):
115115
self.assertEqual([], get_balance_setting(details, 'web-d'))
116116

117117
def test_sticky_setting(self):
118-
details = {'web-a': {'appsession': 'appsession_a'},
119-
'web-b': {'cookie': 'cookie_b'},
120-
'web-c': {'appsession': 'appsession_c', 'cookie': 'cookie_c'},
121-
'web-d': {'attrD': 'valueD'},
122-
'web-e': {'appsession': '', 'cookie': ''}}
118+
details = {'web-a': {'cookie': 'cookie_b'},
119+
'web-b': {'attrB': 'valueB'},
120+
'web-c': {'cookie': ''}}
123121

124122
setting, is_sticky = get_sticky_setting(details, 'web-a')
125-
self.assertEqual(['appsession appsession_a'], setting)
126-
self.assertTrue(is_sticky)
127-
128-
setting, is_sticky = get_sticky_setting(details, 'web-b')
129123
self.assertEqual(['cookie cookie_b'], setting)
130124
self.assertTrue(is_sticky)
131125

132-
setting, is_sticky = get_sticky_setting(details, 'web-c')
133-
self.assertEqual(['appsession appsession_c', 'cookie cookie_c'], setting)
134-
self.assertTrue(is_sticky)
135-
136-
setting, is_sticky = get_sticky_setting(details, 'web-d')
137-
self.assertEqual([], setting)
138-
self.assertFalse(is_sticky)
139-
140-
setting, is_sticky = get_sticky_setting(details, 'web-e')
126+
setting, is_sticky = get_sticky_setting(details, 'web-b')
141127
self.assertEqual([], setting)
142128
self.assertFalse(is_sticky)
143129

144-
setting, is_sticky = get_sticky_setting(details, 'web-f')
130+
setting, is_sticky = get_sticky_setting(details, 'web-c')
145131
self.assertEqual([], setting)
146132
self.assertFalse(is_sticky)
147133

tests/unit/parser/test_base_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def test_parse_vhost(self):
3838
details = {'WORLD': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
3939
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
4040
'health_check': None, 'cookie': None, 'virtual_host': 'a.com', 'force_ssl': None,
41-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
41+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
4242
'option': []},
4343
'HELLO': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
4444
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
4545
'health_check': None, 'cookie': None, 'virtual_host': 'b.com', 'force_ssl': None,
46-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
46+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
4747
'option': []}}
4848
vhosts = [{'path': '', 'host': 'a.com', 'scheme': 'http', 'port': '80', 'service_alias': 'WORLD'},
4949
{'path': '', 'host': 'b.com', 'scheme': 'http', 'port': '80', 'service_alias': 'HELLO'}]
@@ -52,12 +52,12 @@ def test_parse_vhost(self):
5252
'gzip_compression_type': None, 'http_check': None, 'health_check': None, 'cookie': None,
5353
'virtual_host': [{'path': '', 'host': 'a.com', 'scheme': 'http', 'port': '80'}],
5454
'exclude_ports': [], 'force_ssl': None, 'tcp_ports': [], 'balance': None, 'extra_settings': None,
55-
'appsession': None, 'virtual_host_str': 'a.com', 'option': []},
55+
'virtual_host_str': 'a.com', 'option': []},
5656
'HELLO': {'default_ssl_cert': '', 'ssl_cert': '', 'virtual_host_weight': 0, 'hsts_max_age': None,
5757
'gzip_compression_type': None, 'http_check': None, 'health_check': None, 'cookie': None,
5858
'virtual_host': [{'path': '', 'host': 'b.com', 'scheme': 'http', 'port': '80'}],
5959
'exclude_ports': [], 'force_ssl': None, 'tcp_ports': [], 'balance': None, 'extra_settings': None,
60-
'appsession': None, 'virtual_host_str': 'b.com', 'option': []}}
60+
'virtual_host_str': 'b.com', 'option': []}}
6161

6262
specs = Specs()
6363
self.assertEqual([], specs._parse_vhosts({}))

tests/unit/parser/test_legacy_parser.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def setUp(self):
1515
self.details = {'WORLD': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
1616
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
1717
'health_check': None, 'cookie': None, 'virtual_host': 'a.com', 'force_ssl': None,
18-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
18+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
1919
'option': [], "extra_route_settings": None, "failover": None,
2020
'exclude_basic_auth': None},
2121
'HELLO': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
2222
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
2323
'health_check': None, 'cookie': None, 'virtual_host': 'b.com', 'force_ssl': None,
24-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
24+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
2525
'option': [], "extra_route_settings": None, "failover": None,
2626
'exclude_basic_auth': None}}
2727
self.routes = {'WORLD': [{'container_name': 'WORLD_1', 'proto': 'tcp', 'port': '80', 'addr': '10.7.0.3'}],
@@ -71,13 +71,13 @@ def test_parse_details(self):
7171
empty_details = {'WORLD': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
7272
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
7373
'health_check': None, 'cookie': None, 'virtual_host': None, 'force_ssl': None,
74-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
74+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
7575
'option': [], "extra_route_settings": None, "failover": None,
7676
'exclude_basic_auth': None, 'exclude_basic_auth': None},
7777
'HELLO': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
7878
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
7979
'health_check': None, 'cookie': None, 'virtual_host': None, 'force_ssl': None,
80-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
80+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
8181
'option': [], "extra_route_settings": None, "failover": None,
8282
'exclude_basic_auth': None, 'exclude_basic_auth': None}}
8383
self.assertEqual({}, specs._parse_details([], {}))
@@ -105,17 +105,17 @@ def test_parse_routes(self):
105105
details = {'WORLD': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
106106
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
107107
'health_check': None, 'cookie': None, 'virtual_host': 'a.com', 'force_ssl': None,
108-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
108+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
109109
'option': [], "extra_route_settings": None, 'exclude_basic_auth': None},
110110
'HELLO': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
111111
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
112112
'health_check': None, 'cookie': None, 'virtual_host': 'b.com', 'force_ssl': None,
113-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
113+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
114114
'option': [], "extra_route_settings": None, 'exclude_basic_auth': None},
115115
'DUPLICATED': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': None,
116116
'gzip_compression_type': None, 'http_check': None, 'virtual_host_weight': 0,
117117
'health_check': None, 'cookie': None, 'virtual_host': 'b.com', 'force_ssl': None,
118-
'tcp_ports': [], 'balance': None, 'extra_settings': None, 'appsession': None,
118+
'tcp_ports': [], 'balance': None, 'extra_settings': None,
119119
'option': [], "extra_route_settings": None, 'exclude_basic_auth': None}
120120
}
121121

@@ -157,9 +157,6 @@ def test_parse(self):
157157
env.parse("HELLO_2_ENV_FORCE_SSL", "True")
158158
self.assertEqual("True", env.details["HELLO"]["force_ssl"])
159159

160-
env.parse("HELLO_2_ENV_APPSESSION", "session")
161-
self.assertEqual("session", env.details["HELLO"]["appsession"])
162-
163160
env.parse("HELLO_2_ENV_BALANCE", "source")
164161
self.assertEqual("source", env.details["HELLO"]["balance"])
165162

tests/unit/parser/test_new_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def setUp(self):
3434
self.details = {'tmp_world': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': '',
3535
'gzip_compression_type': '', 'http_check': '', 'virtual_host_weight': 0,
3636
'health_check': '', 'cookie': '', 'virtual_host': 'ab.com', 'force_ssl': '',
37-
'tcp_ports': [], 'balance': '', 'extra_settings': '', 'appsession': '',
37+
'tcp_ports': [], 'balance': '', 'extra_settings': '',
3838
'option': [], "extra_route_settings": '', "failover": '',
3939
'exclude_basic_auth': ''},
4040
'tmp_hello': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': '',
4141
'gzip_compression_type': '', 'http_check': '', 'virtual_host_weight': 0,
4242
'health_check': '', 'cookie': '', 'virtual_host': 'a.com', 'force_ssl': '',
43-
'tcp_ports': [], 'balance': '', 'extra_settings': '', 'appsession': '',
43+
'tcp_ports': [], 'balance': '', 'extra_settings': '',
4444
'option': [], "extra_route_settings": '', "failover": '',
4545
'exclude_basic_auth': ''}}
4646
self.routes = {'tmp_hello': [{'addr': 'tmp_hello_1',
@@ -86,13 +86,13 @@ def test_parse_details(self):
8686
empty_details = {'tmp_world': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': '',
8787
'gzip_compression_type': '', 'http_check': '', 'virtual_host_weight': 0,
8888
'health_check': '', 'cookie': '', 'virtual_host': '', 'force_ssl': '',
89-
'tcp_ports': [], 'balance': '', 'extra_settings': '', 'appsession': '',
89+
'tcp_ports': [], 'balance': '', 'extra_settings': '',
9090
'option': [], "extra_route_settings": '', "failover": '',
9191
'exclude_basic_auth': ''},
9292
'tmp_hello': {'default_ssl_cert': '', 'ssl_cert': '', 'exclude_ports': [], 'hsts_max_age': '',
9393
'gzip_compression_type': '', 'http_check': '', 'virtual_host_weight': 0,
9494
'health_check': '', 'cookie': '', 'virtual_host': '', 'force_ssl': '',
95-
'tcp_ports': [], 'balance': '', 'extra_settings': '', 'appsession': '',
95+
'tcp_ports': [], 'balance': '', 'extra_settings': '',
9696
'option': [], "extra_route_settings": '', "failover": '',
9797
'exclude_basic_auth': ''}}
9898

0 commit comments

Comments
 (0)