Fix the delete pool flow
Updated tasks in delete flow Added more constants to keep flows consistent Updated model methods to define a deletion step Updated unit tests Change-Id: Icf22c36cbdf0e3f95b56876c776524958090bdf2 Closes-Bug: 1458242
This commit is contained in:
parent
ed7d67d47c
commit
00640a9c6f
@ -91,6 +91,9 @@ COMPUTE_OBJ = 'compute_obj'
|
||||
AMPS_DATA = 'amps_data'
|
||||
NICS = 'nics'
|
||||
VIP = 'vip'
|
||||
POOL = 'pool'
|
||||
POOL_ID = 'pool_id'
|
||||
OBJECT = 'object'
|
||||
|
||||
CREATE_AMPHORA_FLOW = 'octavia-create-amphora-flow'
|
||||
CREATE_AMPHORA_FOR_LB_FLOW = 'octavia-create-amp-for-lb-flow'
|
||||
|
@ -107,6 +107,10 @@ class Pool(BaseDataModel):
|
||||
self.session_persistence = session_persistence
|
||||
self.listener = listener
|
||||
|
||||
def delete(self):
|
||||
self.listener.default_pool = None
|
||||
self.listener.default_pool_id = None
|
||||
|
||||
|
||||
class Member(BaseDataModel):
|
||||
|
||||
|
@ -417,16 +417,15 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
|
||||
pool = self._pool_repo.get(db_apis.get_session(),
|
||||
id=pool_id)
|
||||
|
||||
load_balancer = pool.listener.load_balancer
|
||||
listener = pool.listener
|
||||
listener.default_pool = pool
|
||||
vip = listener.load_balancer.vip
|
||||
vip = load_balancer.vip
|
||||
|
||||
delete_pool_tf = self._taskflow_load(self._pool_flows.
|
||||
get_delete_pool_flow(),
|
||||
store={'pool': pool,
|
||||
'pool_id': pool_id,
|
||||
'listener': listener,
|
||||
'vip': vip})
|
||||
delete_pool_tf = self._taskflow_load(
|
||||
self._pool_flows.get_delete_pool_flow(),
|
||||
store={constants.POOL: pool, constants.LISTENER: listener,
|
||||
constants.LOADBALANCER: load_balancer,
|
||||
constants.VIP: vip})
|
||||
with tf_logging.DynamicLoggingListener(delete_pool_tf,
|
||||
log=LOG):
|
||||
delete_pool_tf.run()
|
||||
|
@ -42,13 +42,14 @@ class PoolFlows(object):
|
||||
:returns: The flow for deleting a pool
|
||||
"""
|
||||
delete_pool_flow = linear_flow.Flow(constants.DELETE_POOL_FLOW)
|
||||
delete_pool_flow.add(model_tasks.
|
||||
DeleteModelObject(rebind={'object': 'pool'}))
|
||||
delete_pool_flow.add(model_tasks.DeleteModelObject(
|
||||
rebind={constants.OBJECT: constants.POOL}))
|
||||
delete_pool_flow.add(amphora_driver_tasks.ListenerUpdate(
|
||||
requires=['listener', 'vip']))
|
||||
delete_pool_flow.add(database_tasks.DeletePoolInDB(requires='pool_id'))
|
||||
requires=[constants.LISTENER, constants.VIP]))
|
||||
delete_pool_flow.add(database_tasks.DeletePoolInDB(
|
||||
requires=constants.POOL))
|
||||
delete_pool_flow.add(database_tasks.MarkLBAndListenerActiveInDB(
|
||||
requires=['loadbalancer', 'listener']))
|
||||
requires=[constants.LOADBALANCER, constants.LISTENER]))
|
||||
|
||||
return delete_pool_flow
|
||||
|
||||
|
@ -159,16 +159,16 @@ class DeletePoolInDB(BaseDatabaseTask):
|
||||
Since sqlalchemy will likely retry by itself always revert if it fails
|
||||
"""
|
||||
|
||||
def execute(self, pool_id):
|
||||
def execute(self, pool):
|
||||
"""Delete the pool in DB
|
||||
|
||||
:param pool_id: The pool ID to be deleted
|
||||
:param pool: The pool to be deleted
|
||||
:returns: None
|
||||
"""
|
||||
|
||||
LOG.debug("Delete in DB for pool id: %s " %
|
||||
pool_id)
|
||||
self.pool_repo.delete(db_apis.get_session(), pool_id)
|
||||
pool.id)
|
||||
self.pool_repo.delete(db_apis.get_session(), id=pool.id)
|
||||
|
||||
def revert(self, pool_id, *args, **kwargs):
|
||||
"""Mark the pool ERROR since the delete couldn't happen
|
||||
|
@ -47,11 +47,10 @@ class TestPoolFlows(base.TestCase):
|
||||
|
||||
self.assertIn('listener', pool_flow.requires)
|
||||
self.assertIn('loadbalancer', pool_flow.requires)
|
||||
self.assertIn('pool', pool_flow.requires)
|
||||
self.assertIn('pool_id', pool_flow.requires)
|
||||
self.assertIn('vip', pool_flow.requires)
|
||||
self.assertIn('pool', pool_flow.requires)
|
||||
|
||||
self.assertEqual(len(pool_flow.requires), 5)
|
||||
self.assertEqual(len(pool_flow.requires), 4)
|
||||
self.assertEqual(len(pool_flow.provides), 0)
|
||||
|
||||
def test_get_update_pool_flow(self):
|
||||
|
@ -39,6 +39,8 @@ _amphora_mock.lb_network_ip = LB_NET_IP
|
||||
_loadbalancer_mock = mock.MagicMock()
|
||||
_loadbalancer_mock.id = LB_ID
|
||||
_loadbalancer_mock.amphorae = [_amphora_mock]
|
||||
_pool_mock = mock.MagicMock()
|
||||
_pool_mock.id = POOL_ID
|
||||
_tf_failure_mock = mock.Mock(spec=failure.Failure)
|
||||
|
||||
|
||||
@ -178,11 +180,11 @@ class TestDatabaseTasks(base.TestCase):
|
||||
mock_amphora_repo_delete):
|
||||
|
||||
delete_pool = database_tasks.DeletePoolInDB()
|
||||
delete_pool.execute(POOL_ID)
|
||||
delete_pool.execute(_pool_mock)
|
||||
|
||||
repo.PoolRepository.delete.assert_called_once_with(
|
||||
'TEST',
|
||||
POOL_ID)
|
||||
id=POOL_ID)
|
||||
|
||||
# Test the revert
|
||||
|
||||
|
@ -556,8 +556,8 @@ class TestControllerWorker(base.TestCase):
|
||||
(base_taskflow.BaseTaskFlowEngine._taskflow_load.
|
||||
assert_called_once_with(_flow_mock,
|
||||
store={'pool': _pool_mock,
|
||||
'pool_id': POOL_ID,
|
||||
'listener': _listener_mock,
|
||||
'loadbalancer': _load_balancer_mock,
|
||||
'vip': _vip_mock}))
|
||||
|
||||
_flow_mock.run.assert_called_once()
|
||||
|
Loading…
x
Reference in New Issue
Block a user