Fix LBaaS Haproxy occurs error if no member is added

If no member is added and session_persistence.type=HTTP_COOKIE,
haproxy agent would not add cookie persistence option to the backend.
Closes-Bug: #1302283

Change-Id: Ifa2564df924c2555225a749a99c705b3f1caab4a
This commit is contained in:
berlin 2014-04-11 08:04:47 +08:00
parent a7da625571
commit 0f2de5a335
2 changed files with 10 additions and 1 deletions

View File

@ -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')):

View File

@ -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'])