diff --git a/neutron/services/loadbalancer/drivers/haproxy/cfg.py b/neutron/services/loadbalancer/drivers/haproxy/cfg.py index 94a214bc4a..2944e456a6 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/cfg.py +++ b/neutron/services/loadbalancer/drivers/haproxy/cfg.py @@ -199,7 +199,8 @@ def _get_session_persistence(config): if persistence['type'] == constants.SESSION_PERSISTENCE_SOURCE_IP: opts.append('stick-table type ip size 10k') opts.append('stick on src') - elif persistence['type'] == constants.SESSION_PERSISTENCE_HTTP_COOKIE: + elif (persistence['type'] == constants.SESSION_PERSISTENCE_HTTP_COOKIE and + config.get('members')): opts.append('cookie SRV insert indirect nocache') elif (persistence['type'] == constants.SESSION_PERSISTENCE_APP_COOKIE and persistence.get('cookie_name')): diff --git a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py index 7c937c982e..a35e159360 100644 --- a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py +++ b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py @@ -178,7 +178,15 @@ class TestHaproxyCfg(base.BaseTestCase): self.assertEqual(cfg._get_session_persistence(config), ['stick-table type ip size 10k', 'stick on src']) + config = {'vip': {'session_persistence': {'type': 'HTTP_COOKIE'}}, + 'members': []} + self.assertEqual([], cfg._get_session_persistence(config)) + config = {'vip': {'session_persistence': {'type': 'HTTP_COOKIE'}}} + self.assertEqual([], cfg._get_session_persistence(config)) + + config = {'vip': {'session_persistence': {'type': 'HTTP_COOKIE'}}, + 'members': [{'id': 'member1_id'}]} self.assertEqual(cfg._get_session_persistence(config), ['cookie SRV insert indirect nocache'])