Resetting session persisnence for a VIP.

This change allows to reset session persistence, if it
was configured for a VIP. It's possible by passing None
value for session persistence through the REST API.

Change-Id: I8690850d0589065502a8eb774d51fe40851624f8
Fixes: bug #1109101
This commit is contained in:
Roman Prykhodchenko 2013-01-29 20:33:17 +02:00
parent 4ab676fc4f
commit 35cb218adb
4 changed files with 33 additions and 8 deletions

View File

@ -338,6 +338,10 @@ def convert_none_to_empty_list(value):
return [] if value is None else value
def convert_none_to_empty_dict(value):
return {} if value is None else value
def convert_to_list(data):
if data is None:
return []

View File

@ -260,7 +260,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase):
with context.session.begin(subtransactions=True):
pool_db.update({'vip_id': vip_id})
def _update_vip_session_persistence_info(self, context, vip_id, info):
def _update_vip_session_persistence(self, context, vip_id, info):
vip = self._get_resource(context, Vip, vip_id)
with context.session.begin(subtransactions=True):
@ -279,10 +279,10 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase):
vip.session_persistence = sesspersist_db
context.session.add(vip)
def _delete_sessionpersistence(self, context, id):
def _delete_session_persistence(self, context, vip_id):
with context.session.begin(subtransactions=True):
sess_qry = context.session.query(SessionPersistence)
sess_qry.filter_by(vip_id=id).delete()
sess_qry.filter_by(vip_id=vip_id).delete()
def create_vip(self, context, vip):
v = vip['vip']
@ -325,12 +325,12 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase):
def update_vip(self, context, id, vip):
v = vip['vip']
sesspersist_info = v.pop('session_persistence', None)
sess_persist = v.pop('session_persistence', None)
with context.session.begin(subtransactions=True):
if sesspersist_info:
self._update_vip_session_persistence_info(context,
id,
sesspersist_info)
if sess_persist:
self._update_vip_session_persistence(context, id, sess_persist)
else:
self._delete_session_persistence(context, id)
vip_db = self._get_resource(context, Vip, id)
old_pool_id = vip_db['pool_id']

View File

@ -88,6 +88,7 @@ RESOURCE_ATTRIBUTE_MAP = {
'validate': {'type:uuid': None},
'is_visible': True},
'session_persistence': {'allow_post': True, 'allow_put': True,
'convert_to': attr.convert_none_to_empty_dict,
'default': {},
'validate': {'type:dict': None},
'is_visible': True},

View File

@ -438,6 +438,26 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
for k, v in keys:
self.assertEqual(vip['vip'][k], v)
def test_reset_session_persistence(self):
name = 'vip4'
session_persistence = {'type': "HTTP_COOKIE",
'cookie_name': "cookie_name"}
update_info = {'vip': {'session_persistence': None}}
with self.vip(name=name, session_persistence=session_persistence) as v:
# Ensure that vip has been created properly
self.assertEqual(v['vip']['session_persistence'],
session_persistence)
# Try resetting session_persistence
req = self.new_update_request('vips', update_info, v['vip']['id'])
res = self.deserialize('json', req.get_response(self.ext_api))
# If session persistence has been removed, it won't be present in
# the response.
self.assertNotIn('session_persistence', res['vip'])
def test_update_vip(self):
name = 'new_vip'
keys = [('name', name),