Browse Source

Fixed support of session_persistence for lbaas/octavia

This patch will fix broken support of session_persistence and
only add cookie_name when type is APP_COOKIE.

Change-Id: I32ad7840208bcc20091abcc1df68a7a707a7c4ac
changes/51/779551/12 11.0.0
Satish Patel 4 months ago
parent
commit
e111000aab
4 changed files with 61 additions and 9 deletions
  1. +1
    -0
      senlin/drivers/os/lbaas.py
  2. +7
    -1
      senlin/drivers/os/octavia_v2.py
  3. +8
    -4
      senlin/tests/unit/drivers/test_lbaas.py
  4. +45
    -4
      senlin/tests/unit/drivers/test_octavia_v2.py

+ 1
- 0
senlin/drivers/os/lbaas.py View File

@ -159,6 +159,7 @@ class LoadBalancerDriver(base.DriverBase):
try:
pool = self.oc().pool_create(pool['lb_method'], listener.id,
pool['protocol'],
pool['session_persistence'],
pool['admin_state_up'])
except exception.InternalError as ex:
msg = 'Failed in creating lb pool: %s.' % str(ex)


+ 7
- 1
senlin/drivers/os/octavia_v2.py View File

@ -98,12 +98,18 @@ class OctaviaClient(base.DriverBase):
@sdk.translate_exception
def pool_create(self, lb_algorithm, listener_id, protocol,
admin_state_up=True, name=None, description=None):
session_persistence, admin_state_up=True,
name=None, description=None):
# Remove cookie_name when type not equal to APP_COOKIE
if session_persistence['type'] != 'APP_COOKIE':
session_persistence.pop('cookie_name', None)
kwargs = {
'lb_algorithm': lb_algorithm,
'listener_id': listener_id,
'protocol': protocol,
'session_persistence': session_persistence,
'admin_state_up': admin_state_up,
}


+ 8
- 4
senlin/tests/unit/drivers/test_lbaas.py View File

@ -50,7 +50,11 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.pool = {
'lb_method': 'ROUND_ROBIN',
'protocol': 'HTTP',
'admin_state_up': True
'session_persistence': {
'type': 'SOURCE_IP',
'cookie_name': 'whatever',
},
'admin_state_up': True,
}
self.hm = {
"type": "HTTP",
@ -168,7 +172,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.assertEqual('LISTENER_ID', res['listener'])
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'])
self.assertEqual('POOL_ID', res['pool'])
self.oc.healthmonitor_create.assert_called_once_with(
self.hm['type'], self.hm['delay'], self.hm['timeout'],
@ -227,7 +231,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.assertEqual('LISTENER_ID', res['listener'])
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'])
self.assertEqual('POOL_ID', res['pool'])
self.oc.healthmonitor_create.assert_called_once_with(
self.hm['type'], self.hm['delay'], self.hm['timeout'],
@ -357,7 +361,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.vip['connection_limit'], self.vip['admin_state_up'])
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'])
self.lb_driver._wait_for_lb_ready.assert_called_with('LB_ID')
self.lb_driver.lb_delete.assert_called_once_with(
loadbalancer='LB_ID', listener='LISTENER_ID', pool='POOL_ID')


+ 45
- 4
senlin/tests/unit/drivers/test_octavia_v2.py View File

@ -129,6 +129,12 @@ class TestOctaviaV2Driver(base.SenlinTestCase):
lb_algorithm = 'ROUND_ROBIN'
listener_id = 'ID1'
protocol = 'HTTP'
session_persistence = {
'type': 'SOURCE_IP',
'cookie_name': 'whatever',
}
session_persistence_expected = session_persistence.copy()
session_persistence_expected.pop('cookie_name', None)
pool_obj = mock.Mock()
# All input parameters are provided
@ -140,20 +146,55 @@ class TestOctaviaV2Driver(base.SenlinTestCase):
self.conn.load_balancer.create_pool.return_value = pool_obj
self.assertEqual(pool_obj, self.oc.pool_create(
lb_algorithm, listener_id, protocol, **kwargs))
lb_algorithm, listener_id, protocol, session_persistence,
**kwargs))
self.conn.load_balancer.create_pool.assert_called_once_with(
lb_algorithm=lb_algorithm, listener_id=listener_id,
protocol=protocol, **kwargs)
protocol=protocol,
session_persistence=session_persistence_expected,
**kwargs)
# Use default input parameters
kwargs = {
'admin_state_up': True
}
self.assertEqual(pool_obj, self.oc.pool_create(
lb_algorithm, listener_id, protocol))
lb_algorithm, listener_id, protocol, session_persistence))
self.conn.load_balancer.create_pool.assert_called_with(
lb_algorithm=lb_algorithm, listener_id=listener_id,
protocol=protocol, **kwargs)
protocol=protocol,
session_persistence=session_persistence_expected,
**kwargs)
def test_pool_create_cookie_removed(self):
lb_algorithm = 'ROUND_ROBIN'
listener_id = 'ID1'
protocol = 'HTTP'
pool_obj = mock.Mock()
# All input parameters are provided
kwargs = {
'admin_state_up': True,
'name': 'test-pool',
'description': 'This is a pool',
}
self.conn.load_balancer.create_pool.return_value = pool_obj
# Check type is APP_COOKIE
session_persistence_app_cookie = {
'type': 'APP_COOKIE',
'cookie_name': 'whatever',
}
self.assertEqual(pool_obj, self.oc.pool_create(
lb_algorithm, listener_id, protocol,
session_persistence_app_cookie, **kwargs))
# cookie_name is not removed
self.conn.load_balancer.create_pool.assert_called_once_with(
lb_algorithm=lb_algorithm, listener_id=listener_id,
protocol=protocol,
session_persistence=session_persistence_app_cookie,
**kwargs)
def test_pool_delete(self):
pool_id = 'ID1'


Loading…
Cancel
Save