Fix updating session persistence of a pool in DB

In case when update data for a pool contains session persistence
it is required to update session persistence table first and
then remove 'session_persistence' key from the update dict.
Otherwise, update will fail and a pool will get stuck in
PENDING_UPDATE status.

This change reuses update_pool_on_listener method of
db.repositories.Repositories class in UpdatePoolInDB task instead
of PoolRepository update method.

This regression was discovered using a scenario test:
https://review.openstack.org/#/c/207945/

Change-Id: I53d6b7962c0baa466db7e053157cdd302edae473
Closes-Bug: #1505125
This commit is contained in:
Elena Ezhova 2016-01-13 19:20:46 +03:00
parent f941cbbfff
commit caecc4f998
2 changed files with 17 additions and 12 deletions

View File

@ -892,8 +892,9 @@ class UpdatePoolInDB(BaseDatabaseTask):
"""
LOG.debug("Update DB for pool id: %s ", pool.id)
self.pool_repo.update(db_apis.get_session(), pool.id,
**update_dict)
sp_dict = update_dict.pop('session_persistence', None)
self.repos.update_pool_on_listener(db_apis.get_session(), pool.id,
update_dict, sp_dict)
def revert(self, pool, *args, **kwargs):
"""Mark the pool ERROR since the update couldn't happen
@ -904,8 +905,8 @@ class UpdatePoolInDB(BaseDatabaseTask):
LOG.warn(_LW("Reverting update pool in DB "
"for pool id %s"), pool.id)
# TODO(johnsom) fix this to set the upper ojects to ERROR
self.pool_repo.update(db_apis.get_session(), pool.id,
enabled=0)
self.repos.update_pool_on_listener(db_apis.get_session(),
pool.id, {'enabled': 0}, None)
class GetUpdatedFailoverAmpNetworkDetailsAsList(BaseDatabaseTask):

View File

@ -910,9 +910,10 @@ class TestDatabaseTasks(base.TestCase):
MEMBER_ID,
enabled=0)
@mock.patch('octavia.db.repositories.PoolRepository.update')
@mock.patch(
'octavia.db.repositories.Repositories.update_pool_on_listener')
def test_update_pool_in_db(self,
mock_pool_repo_update,
mock_repos_pool_update,
mock_generate_uuid,
mock_LOG,
mock_get_session,
@ -921,25 +922,28 @@ class TestDatabaseTasks(base.TestCase):
mock_amphora_repo_update,
mock_amphora_repo_delete):
sp_dict = {'type': 'SOURCE_IP', 'cookie_name': None}
update_dict = {'name': 'test', 'description': 'test2',
'session_persistence': sp_dict}
update_pool = database_tasks.UpdatePoolInDB()
update_pool.execute(self.pool_mock,
{'name': 'test', 'description': 'test2'})
update_dict)
repo.PoolRepository.update.assert_called_once_with(
repo.Repositories.update_pool_on_listener.assert_called_once_with(
'TEST',
POOL_ID,
name='test', description='test2')
update_dict, sp_dict)
# Test the revert
mock_pool_repo_update.reset_mock()
mock_repos_pool_update.reset_mock()
update_pool.revert(self.pool_mock)
# TODO(johnsom) fix this to set the upper ojects to ERROR
repo.PoolRepository.update.assert_called_once_with(
repo.Repositories.update_pool_on_listener.assert_called_once_with(
'TEST',
POOL_ID,
enabled=0)
{'enabled': 0}, None)
def test_mark_amphora_role_indb(self,
mock_generate_uuid,