Fix HM flows to set Pool back to active

This became a lot more complicated than originally anticipated... When
we made the decision to use the pool_id as the hm_id, someone should
have smacked us.

Depends-On: I8dd385e3c993942473e67d04367cdf74495dbeef
Change-Id: I8c9f3bfe6766eac93642b656efd8876279d3d378
Closes-Bug: #1692171
This commit is contained in:
Adam Harwell 2017-05-19 21:04:22 -07:00
parent 29219e4345
commit 2debcaa4c7
13 changed files with 158 additions and 162 deletions

View File

@ -32,7 +32,6 @@ import six
from octavia.api.handlers import abstract_handler
from octavia.common import constants
from octavia.common import data_models
cfg.CONF.import_group('oslo_messaging', 'octavia.common.config')
@ -59,11 +58,7 @@ class BaseProducer(abstract_handler.BaseObjectHandler):
:param model:
"""
model_id = getattr(model, 'id', None)
p_class = self.payload_class
if isinstance(model, data_models.HealthMonitor):
model_id = model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_id".format(p_class): model_id}
kw = {"{0}_id".format(self.payload_class): model_id}
method_name = "create_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
@ -74,13 +69,9 @@ class BaseProducer(abstract_handler.BaseObjectHandler):
:param data_model:
"""
model_id = getattr(data_model, 'id', None)
p_class = self.payload_class
if isinstance(data_model, data_models.HealthMonitor):
model_id = data_model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_updates".format(self.payload_class):
updated_model.to_dict(render_unsets=False),
"{0}_id".format(p_class): model_id}
"{0}_id".format(self.payload_class): model_id}
method_name = "update_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
@ -90,11 +81,7 @@ class BaseProducer(abstract_handler.BaseObjectHandler):
:param data_model:
"""
model_id = getattr(data_model, 'id', None)
p_class = self.payload_class
if isinstance(data_model, data_models.HealthMonitor):
model_id = data_model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_id".format(p_class): model_id}
kw = {"{0}_id".format(self.payload_class): model_id}
method_name = "delete_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
@ -192,7 +179,7 @@ class ProducerHandler(abstract_handler.BaseHandler):
"""Base class for all QueueProducers.
used to send messages via the Class variables load_balancer, listener,
health_monitor, and member.
health_monitor, member, l7policy and l7rule.
"""
load_balancer = LoadBalancerProducer()

View File

@ -77,17 +77,19 @@ class Endpoint(object):
LOG.info('Deleting pool \'%s\'...', pool_id)
self.worker.delete_pool(pool_id)
def create_health_monitor(self, context, pool_id):
LOG.info('Creating health monitor on pool \'%s\'...', pool_id)
self.worker.create_health_monitor(pool_id)
def create_health_monitor(self, context, health_monitor_id):
LOG.info('Creating health monitor \'%s\'...', health_monitor_id)
self.worker.create_health_monitor(health_monitor_id)
def update_health_monitor(self, context, pool_id, health_monitor_updates):
LOG.info('Updating health monitor on pool \'%s\'...', pool_id)
self.worker.update_health_monitor(pool_id, health_monitor_updates)
def update_health_monitor(self, context, health_monitor_id,
health_monitor_updates):
LOG.info('Updating health monitor \'%s\'...', health_monitor_id)
self.worker.update_health_monitor(health_monitor_id,
health_monitor_updates)
def delete_health_monitor(self, context, pool_id):
LOG.info('Deleting health monitor on pool \'%s\'...', pool_id)
self.worker.delete_health_monitor(pool_id)
def delete_health_monitor(self, context, health_monitor_id):
LOG.info('Deleting health monitor \'%s\'...', health_monitor_id)
self.worker.delete_health_monitor(health_monitor_id)
def create_member(self, context, member_id):
LOG.info('Creating member \'%s\'...' % member_id)

View File

@ -108,7 +108,7 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
log=LOG):
delete_amp_tf.run()
def create_health_monitor(self, pool_id):
def create_health_monitor(self, health_monitor_id):
"""Creates a health monitor.
:param pool_id: ID of the pool to create a health monitor on
@ -116,25 +116,24 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
:raises NoSuitablePool: Unable to find the node pool
"""
health_mon = self._health_mon_repo.get(db_apis.get_session(),
pool_id=pool_id)
id=health_monitor_id)
listeners = health_mon.pool.listeners
health_mon.pool.health_monitor = health_mon
load_balancer = health_mon.pool.load_balancer
pool = health_mon.pool
listeners = pool.listeners
pool.health_monitor = health_mon
load_balancer = pool.load_balancer
create_hm_tf = self._taskflow_load(self._health_monitor_flows.
get_create_health_monitor_flow(),
store={constants.HEALTH_MON:
health_mon,
constants.LISTENERS:
listeners,
constants.LOADBALANCER:
load_balancer})
create_hm_tf = self._taskflow_load(
self._health_monitor_flows.get_create_health_monitor_flow(),
store={constants.HEALTH_MON: health_mon,
constants.POOL: pool,
constants.LISTENERS: listeners,
constants.LOADBALANCER: load_balancer})
with tf_logging.DynamicLoggingListener(create_hm_tf,
log=LOG):
create_hm_tf.run()
def delete_health_monitor(self, pool_id):
def delete_health_monitor(self, health_monitor_id):
"""Deletes a health monitor.
:param pool_id: ID of the pool to delete its health monitor
@ -142,21 +141,23 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
:raises HMNotFound: The referenced health monitor was not found
"""
health_mon = self._health_mon_repo.get(db_apis.get_session(),
pool_id=pool_id)
id=health_monitor_id)
listeners = health_mon.pool.listeners
load_balancer = health_mon.pool.load_balancer
pool = health_mon.pool
listeners = pool.listeners
load_balancer = pool.load_balancer
delete_hm_tf = self._taskflow_load(
self._health_monitor_flows.get_delete_health_monitor_flow(),
store={constants.HEALTH_MON: health_mon, constants.POOL_ID:
pool_id, constants.LISTENERS: listeners,
store={constants.HEALTH_MON: health_mon,
constants.POOL: pool,
constants.LISTENERS: listeners,
constants.LOADBALANCER: load_balancer})
with tf_logging.DynamicLoggingListener(delete_hm_tf,
log=LOG):
delete_hm_tf.run()
def update_health_monitor(self, pool_id, health_monitor_updates):
def update_health_monitor(self, health_monitor_id, health_monitor_updates):
"""Updates a health monitor.
:param pool_id: ID of the pool to have it's health monitor updated
@ -165,22 +166,20 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
:raises HMNotFound: The referenced health monitor was not found
"""
health_mon = self._health_mon_repo.get(db_apis.get_session(),
pool_id=pool_id)
id=health_monitor_id)
listeners = health_mon.pool.listeners
health_mon.pool.health_monitor = health_mon
load_balancer = health_mon.pool.load_balancer
pool = health_mon.pool
listeners = pool.listeners
pool.health_monitor = health_mon
load_balancer = pool.load_balancer
update_hm_tf = self._taskflow_load(self._health_monitor_flows.
get_update_health_monitor_flow(),
store={constants.HEALTH_MON:
health_mon,
constants.LISTENERS:
listeners,
constants.LOADBALANCER:
load_balancer,
constants.UPDATE_DICT:
health_monitor_updates})
update_hm_tf = self._taskflow_load(
self._health_monitor_flows.get_update_health_monitor_flow(),
store={constants.HEALTH_MON: health_mon,
constants.POOL: pool,
constants.LISTENERS: listeners,
constants.LOADBALANCER: load_balancer,
constants.UPDATE_DICT: health_monitor_updates})
with tf_logging.DynamicLoggingListener(update_hm_tf,
log=LOG):
update_hm_tf.run()

View File

@ -40,6 +40,8 @@ class HealthMonitorFlows(object):
requires=[constants.LOADBALANCER, constants.LISTENERS]))
create_hm_flow.add(database_tasks.MarkHealthMonitorActiveInDB(
requires=constants.HEALTH_MON))
create_hm_flow.add(database_tasks.MarkPoolActiveInDB(
requires=constants.POOL))
create_hm_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
requires=[constants.LOADBALANCER, constants.LISTENERS]))
@ -63,9 +65,11 @@ class HealthMonitorFlows(object):
delete_hm_flow.add(amphora_driver_tasks.ListenersUpdate(
requires=[constants.LOADBALANCER, constants.LISTENERS]))
delete_hm_flow.add(database_tasks.DeleteHealthMonitorInDB(
requires=constants.POOL_ID))
requires=constants.HEALTH_MON))
delete_hm_flow.add(database_tasks.DecrementHealthMonitorQuota(
requires=constants.HEALTH_MON))
delete_hm_flow.add(database_tasks.MarkPoolActiveInDB(
requires=constants.POOL))
delete_hm_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
requires=[constants.LOADBALANCER, constants.LISTENERS]))
@ -93,6 +97,8 @@ class HealthMonitorFlows(object):
requires=[constants.HEALTH_MON, constants.UPDATE_DICT]))
update_hm_flow.add(database_tasks.MarkHealthMonitorActiveInDB(
requires=constants.HEALTH_MON))
update_hm_flow.add(database_tasks.MarkPoolActiveInDB(
requires=constants.POOL))
update_hm_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
requires=[constants.LOADBALANCER, constants.LISTENERS]))

View File

@ -63,7 +63,7 @@ class TaskUtils(object):
"""
try:
self.health_mon_repo.update(db_apis.get_session(),
pool_id=health_mon_id,
id=health_mon_id,
provisioning_status=constants.ERROR)
except Exception as e:
LOG.error("Failed to update health monitor %(health)s "

View File

@ -152,32 +152,32 @@ class DeleteHealthMonitorInDB(BaseDatabaseTask):
Since sqlalchemy will likely retry by itself always revert if it fails
"""
def execute(self, pool_id):
def execute(self, health_mon):
"""Delete the health monitor in DB
:param pool_id: The id of pool which health monitor should be deleted
:param health_mon: The health monitor which should be deleted
:returns: None
"""
LOG.debug("DB delete health monitor for pool id: %s ", pool_id)
LOG.debug("DB delete health monitor: %s ", health_mon.id)
try:
self.health_mon_repo.delete(db_apis.get_session(), pool_id=pool_id)
self.health_mon_repo.delete(db_apis.get_session(),
id=health_mon.id)
except exc.NoResultFound:
# ignore if the HealthMonitor was not found
pass
def revert(self, pool_id, *args, **kwargs):
def revert(self, health_mon, *args, **kwargs):
"""Mark the health monitor ERROR since the mark active couldn't happen
:param pool_id: Id of a pool which health monitor couldn't be deleted
:param health_mon: The health monitor which couldn't be deleted
:returns: None
"""
LOG.warning("Reverting mark health monitor delete in DB "
"for health monitor on pool with id %s", pool_id)
# TODO(johnsom) fix this
# self.health_mon_repo.update(db_apis.get_session(), health_mon.id,
# provisioning_status=constants.ERROR)
"for health monitor with id %s", health_mon.id)
self.health_mon_repo.update(db_apis.get_session(), id=health_mon.id,
provisioning_status=constants.ERROR)
class DeleteHealthMonitorInDBByPool(DeleteHealthMonitorInDB):
@ -192,7 +192,8 @@ class DeleteHealthMonitorInDBByPool(DeleteHealthMonitorInDB):
:param pool: A pool which health monitor should be deleted.
:returns: None
"""
super(DeleteHealthMonitorInDBByPool, self).execute(pool.id)
super(DeleteHealthMonitorInDBByPool, self).execute(
pool.health_monitor)
def revert(self, pool, *args, **kwargs):
"""Mark the health monitor ERROR since the mark active couldn't happen
@ -201,7 +202,7 @@ class DeleteHealthMonitorInDBByPool(DeleteHealthMonitorInDB):
:returns: None
"""
super(DeleteHealthMonitorInDBByPool, self).revert(
pool.id, *args, **kwargs)
pool.health_monitor, *args, **kwargs)
class DeleteMemberInDB(BaseDatabaseTask):
@ -1276,8 +1277,8 @@ class UpdateHealthMonInDB(BaseDatabaseTask):
:returns: None
"""
LOG.debug("Update DB for health monitor id: %s ", health_mon.pool_id)
self.health_mon_repo.update(db_apis.get_session(), health_mon.pool_id,
LOG.debug("Update DB for health monitor id: %s ", health_mon.id)
self.health_mon_repo.update(db_apis.get_session(), health_mon.id,
**update_dict)
def revert(self, health_mon, *args, **kwargs):
@ -1288,16 +1289,16 @@ class UpdateHealthMonInDB(BaseDatabaseTask):
"""
LOG.warning("Reverting update health monitor in DB "
"for health monitor id %s", health_mon.pool_id)
"for health monitor id %s", health_mon.id)
# TODO(johnsom) fix this to set the upper ojects to ERROR
try:
self.health_mon_repo.update(db_apis.get_session(),
health_mon.pool_id,
health_mon.id,
enabled=0)
except Exception as e:
LOG.error("Failed to update health monitor %(hm)s "
"enabled to 0 due to: %(except)s",
{'hm': health_mon.pool_id, 'except': e})
{'hm': health_mon.id, 'except': e})
class UpdateListenerInDB(BaseDatabaseTask):
@ -1625,12 +1626,12 @@ class MarkHealthMonitorActiveInDB(BaseDatabaseTask):
"""
LOG.debug("Mark ACTIVE in DB for health monitor id: %s",
health_mon.pool_id)
health_mon.id)
op_status = (constants.ONLINE if health_mon.enabled
else constants.OFFLINE)
self.health_mon_repo.update(db_apis.get_session(),
health_mon.pool_id,
health_mon.id,
provisioning_status=constants.ACTIVE,
operating_status=op_status)
@ -1642,8 +1643,8 @@ class MarkHealthMonitorActiveInDB(BaseDatabaseTask):
"""
LOG.warning("Reverting mark health montor ACTIVE in DB "
"for health monitor id %s", health_mon.pool_id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.pool_id)
"for health monitor id %s", health_mon.id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
class MarkHealthMonitorPendingCreateInDB(BaseDatabaseTask):
@ -1660,9 +1661,9 @@ class MarkHealthMonitorPendingCreateInDB(BaseDatabaseTask):
"""
LOG.debug("Mark PENDING CREATE in DB for health monitor id: %s",
health_mon.pool_id)
health_mon.id)
self.health_mon_repo.update(db_apis.get_session(),
health_mon.pool_id,
health_mon.id,
provisioning_status=(constants.
PENDING_CREATE))
@ -1674,8 +1675,8 @@ class MarkHealthMonitorPendingCreateInDB(BaseDatabaseTask):
"""
LOG.warning("Reverting mark health monitor pending create in DB "
"for health monitor id %s", health_mon.pool_id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.pool_id)
"for health monitor id %s", health_mon.id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
class MarkHealthMonitorPendingDeleteInDB(BaseDatabaseTask):
@ -1692,9 +1693,9 @@ class MarkHealthMonitorPendingDeleteInDB(BaseDatabaseTask):
"""
LOG.debug("Mark PENDING DELETE in DB for health monitor id: %s",
health_mon.pool_id)
health_mon.id)
self.health_mon_repo.update(db_apis.get_session(),
health_mon.pool_id,
health_mon.id,
provisioning_status=(constants.
PENDING_DELETE))
@ -1706,8 +1707,8 @@ class MarkHealthMonitorPendingDeleteInDB(BaseDatabaseTask):
"""
LOG.warning("Reverting mark health monitor pending delete in DB "
"for health monitor id %s", health_mon.pool_id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.pool_id)
"for health monitor id %s", health_mon.id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
@ -1724,9 +1725,9 @@ class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
"""
LOG.debug("Mark PENDING UPDATE in DB for health monitor id: %s",
health_mon.pool_id)
health_mon.id)
self.health_mon_repo.update(db_apis.get_session(),
health_mon.pool_id,
health_mon.id,
provisioning_status=(constants.
PENDING_UPDATE))
@ -1738,8 +1739,8 @@ class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
"""
LOG.warning("Reverting mark health monitor pending update in DB "
"for health monitor id %s", health_mon.pool_id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.pool_id)
"for health monitor id %s", health_mon.id)
self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
class MarkL7PolicyActiveInDB(BaseDatabaseTask):

View File

@ -703,19 +703,6 @@ class VipRepository(BaseRepository):
class HealthMonitorRepository(BaseRepository):
model_class = models.HealthMonitor
def create(self, session, **model_kwargs):
with session.begin(subtransactions=True):
model_kwargs['id'] = model_kwargs['pool_id']
model = self.model_class(**model_kwargs)
session.add(model)
return model.to_data_model()
def update(self, session, pool_id, **model_kwargs):
"""Updates a health monitor entity in the database by pool_id."""
with session.begin(subtransactions=True):
session.query(self.model_class).filter_by(
pool_id=pool_id).update(model_kwargs)
class SessionPersistenceRepository(BaseRepository):
model_class = models.SessionPersistence

View File

@ -2463,26 +2463,27 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)
def create_health_monitor(self, pool_id):
def create_health_monitor(self, hm_id, pool_id):
health_monitor = self.hm_repo.create(
self.session, type=constants.HEALTH_MONITOR_HTTP,
self.session, type=constants.HEALTH_MONITOR_HTTP, id=hm_id,
pool_id=pool_id, delay=1, timeout=1, fall_threshold=1,
rise_threshold=1, http_method="POST",
url_path="http://localhost:80/index.php",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE,
expected_codes="200", enabled=True)
self.assertEqual(hm_id, health_monitor.id)
return health_monitor
def test_get(self):
hm = self.create_health_monitor(self.pool.id)
new_hm = self.hm_repo.get(self.session, pool_id=hm.pool_id)
hm = self.create_health_monitor(self.FAKE_UUID_3, self.pool.id)
new_hm = self.hm_repo.get(self.session, id=hm.id)
self.assertIsInstance(new_hm, models.HealthMonitor)
self.assertEqual(hm, new_hm)
def test_create(self):
hm = self.create_health_monitor(self.pool.id)
new_hm = self.hm_repo.get(self.session, pool_id=hm.pool_id)
hm = self.create_health_monitor(self.FAKE_UUID_3, self.pool.id)
new_hm = self.hm_repo.get(self.session, id=hm.id)
self.assertEqual(constants.HEALTH_MONITOR_HTTP, new_hm.type)
self.assertEqual(self.pool.id, new_hm.pool_id)
self.assertEqual(1, new_hm.delay)
@ -2496,15 +2497,16 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
def test_update(self):
delay_change = 2
hm = self.create_health_monitor(self.pool.id)
self.hm_repo.update(self.session, hm.pool.id, delay=delay_change)
new_hm = self.hm_repo.get(self.session, pool_id=hm.pool_id)
hm = self.create_health_monitor(self.FAKE_UUID_3, self.pool.id)
self.hm_repo.update(
self.session, hm.id, delay=delay_change)
new_hm = self.hm_repo.get(self.session, id=hm.id)
self.assertEqual(delay_change, new_hm.delay)
def test_delete(self):
hm = self.create_health_monitor(self.pool.id)
self.hm_repo.delete(self.session, pool_id=hm.pool_id)
self.assertIsNone(self.hm_repo.get(self.session, pool_id=hm.pool_id))
hm = self.create_health_monitor(self.FAKE_UUID_3, self.pool.id)
self.hm_repo.delete(self.session, id=hm.id)
self.assertIsNone(self.hm_repo.get(self.session, id=hm.id))
new_pool = self.pool_repo.get(self.session, id=self.pool.id)
self.assertIsNotNone(new_pool)
self.assertIsNone(new_pool.health_monitor)

View File

@ -153,10 +153,10 @@ class TestProducer(base.TestCase):
def test_update_healthmonitor(self):
p = producer.HealthMonitorProducer()
hm = data_models.HealthMonitor(pool_id=10)
hm = data_models.HealthMonitor(id=20, pool_id=10)
hm_updates = health_monitor.HealthMonitorPUT(enabled=False)
p.update(hm, hm_updates)
kw = {'pool_id': hm.pool_id,
kw = {'health_monitor_id': hm.id,
'health_monitor_updates': hm_updates.to_dict(
render_unsets=False)}
self.mck_client.cast.assert_called_once_with(

View File

@ -37,7 +37,7 @@ class TestHealthMonitorFlows(base.TestCase):
self.assertIn(constants.LISTENERS, health_mon_flow.requires)
self.assertIn(constants.LOADBALANCER, health_mon_flow.requires)
self.assertEqual(3, len(health_mon_flow.requires))
self.assertEqual(4, len(health_mon_flow.requires))
self.assertEqual(0, len(health_mon_flow.provides))
def test_get_delete_health_monitor_flow(self):
@ -48,8 +48,9 @@ class TestHealthMonitorFlows(base.TestCase):
self.assertIsInstance(health_mon_flow, flow.Flow)
self.assertIn(constants.HEALTH_MON, health_mon_flow.requires)
self.assertIn(constants.POOL_ID, health_mon_flow.requires)
self.assertIn(constants.LISTENERS, health_mon_flow.requires)
self.assertIn(constants.LOADBALANCER, health_mon_flow.requires)
self.assertIn(constants.POOL, health_mon_flow.requires)
self.assertEqual(4, len(health_mon_flow.requires))
self.assertEqual(0, len(health_mon_flow.provides))
@ -66,5 +67,5 @@ class TestHealthMonitorFlows(base.TestCase):
self.assertIn(constants.HEALTH_MON, health_mon_flow.requires)
self.assertIn(constants.UPDATE_DICT, health_mon_flow.requires)
self.assertEqual(4, len(health_mon_flow.requires))
self.assertEqual(5, len(health_mon_flow.requires))
self.assertEqual(0, len(health_mon_flow.provides))

View File

@ -35,6 +35,7 @@ SERVER_GROUP_ID = uuidutils.generate_uuid()
LB_NET_IP = '192.0.2.2'
LISTENER_ID = uuidutils.generate_uuid()
POOL_ID = uuidutils.generate_uuid()
HM_ID = uuidutils.generate_uuid()
MEMBER_ID = uuidutils.generate_uuid()
PORT_ID = uuidutils.generate_uuid()
SUBNET_ID = uuidutils.generate_uuid()
@ -129,6 +130,7 @@ class TestDatabaseTasks(base.TestCase):
def setUp(self):
self.health_mon_mock = mock.MagicMock()
self.health_mon_mock.id = HM_ID
self.health_mon_mock.pool_id = POOL_ID
self.listener_mock = mock.MagicMock()
@ -142,6 +144,7 @@ class TestDatabaseTasks(base.TestCase):
self.pool_mock = mock.MagicMock()
self.pool_mock.id = POOL_ID
self.pool_mock.health_monitor = self.health_mon_mock
self.l7policy_mock = mock.MagicMock()
self.l7policy_mock.id = L7POLICY_ID
@ -213,9 +216,11 @@ class TestDatabaseTasks(base.TestCase):
'TEST',
id=LISTENER_ID)
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
@mock.patch('octavia.db.repositories.HealthMonitorRepository.delete')
def test_delete_health_monitor_in_db(self,
mock_health_mon_repo_delete,
mock_health_mon_repo_update,
mock_generate_uuid,
mock_LOG,
mock_get_session,
@ -225,29 +230,31 @@ class TestDatabaseTasks(base.TestCase):
mock_amphora_repo_delete):
delete_health_mon = database_tasks.DeleteHealthMonitorInDB()
delete_health_mon.execute(POOL_ID)
delete_health_mon.execute(self.health_mon_mock)
repo.HealthMonitorRepository.delete.assert_called_once_with(
'TEST',
pool_id=POOL_ID)
'TEST', id=HM_ID)
# Test the revert
mock_health_mon_repo_delete.reset_mock()
delete_health_mon.revert(POOL_ID)
delete_health_mon.revert(self.health_mon_mock)
repo.HealthMonitorRepository.update.assert_called_once_with(
'TEST', id=HM_ID, provisioning_status=constants.ERROR)
# Test Not Found Exception
mock_health_mon_repo_delete.reset_mock()
mock_health_mon_repo_delete.side_effect = [exc.NoResultFound()]
delete_health_mon.execute(POOL_ID)
delete_health_mon.execute(self.health_mon_mock)
repo.HealthMonitorRepository.delete.assert_called_once_with(
'TEST',
pool_id=POOL_ID)
'TEST', id=HM_ID)
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
@mock.patch('octavia.db.repositories.HealthMonitorRepository.delete')
def test_delete_health_monitor_in_db_by_pool(self,
mock_health_mon_repo_delete,
mock_health_mon_repo_update,
mock_generate_uuid,
mock_LOG,
mock_get_session,
@ -261,13 +268,15 @@ class TestDatabaseTasks(base.TestCase):
repo.HealthMonitorRepository.delete.assert_called_once_with(
'TEST',
pool_id=POOL_ID)
id=HM_ID)
# Test the revert
mock_health_mon_repo_delete.reset_mock()
delete_health_mon.revert(self.pool_mock)
repo.HealthMonitorRepository.update.assert_called_once_with(
'TEST', id=HM_ID, provisioning_status=constants.ERROR)
# TODO(johnsom) fix once provisioning status added
# repo.HealthMonitorRepository.update.assert_called_once_with(
# 'TEST',
@ -1357,7 +1366,7 @@ class TestDatabaseTasks(base.TestCase):
repo.HealthMonitorRepository.update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
delay=1, timeout=2)
# Test the revert
@ -1367,7 +1376,7 @@ class TestDatabaseTasks(base.TestCase):
# TODO(johnsom) fix this to set the upper ojects to ERROR
repo.HealthMonitorRepository.update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
enabled=0)
# Test the revert with exception
@ -1378,7 +1387,7 @@ class TestDatabaseTasks(base.TestCase):
# TODO(johnsom) fix this to set the upper ojects to ERROR
repo.HealthMonitorRepository.update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
enabled=0)
@mock.patch('octavia.db.repositories.LoadBalancerRepository.update')
@ -1846,7 +1855,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
@ -1856,7 +1865,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
# Test the revert with exception
@ -1866,7 +1875,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
@ -1887,7 +1896,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
provisioning_status=constants.PENDING_CREATE)
# Test the revert
@ -1896,7 +1905,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
# Test the revert with exception
@ -1906,7 +1915,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
@ -1927,7 +1936,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
provisioning_status=constants.PENDING_DELETE)
# Test the revert
@ -1936,7 +1945,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
# Test the revert with exception
@ -1946,7 +1955,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
@ -1967,7 +1976,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
POOL_ID,
HM_ID,
provisioning_status=constants.PENDING_UPDATE)
# Test the revert
@ -1976,7 +1985,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
# Test the revert with exception
@ -1986,7 +1995,7 @@ class TestDatabaseTasks(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
'TEST',
pool_id=POOL_ID,
id=HM_ID,
provisioning_status=constants.ERROR)
@mock.patch('octavia.db.repositories.L7PolicyRepository.update')

View File

@ -86,16 +86,12 @@ class TestControllerWorker(base.TestCase):
self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
_health_mon_mock.pool.load_balancer.amphorae = _amphora_mock
_health_mon_mock.pool.listeners = [_listener_mock]
_health_mon_mock.pool.load_balancer = _load_balancer_mock
_health_mon_mock.pool.load_balancer.vip = _vip_mock
_listener_mock.load_balancer = _load_balancer_mock
_listener_mock.load_balancer.amphorae = _amphora_mock
_listener_mock.load_balancer.vip = _vip_mock
_pool_mock.listeners = [_listener_mock]
_pool_mock.load_balancer = _load_balancer_mock
_pool_mock.load_balancer.vip = _vip_mock
_health_mon_mock.pool = _pool_mock
_load_balancer_mock.amphorae = _amphora_mock
_load_balancer_mock.vip = _vip_mock
_listener_mock.load_balancer = _load_balancer_mock
_member_mock.pool = _pool_mock
_l7policy_mock.listener = _listener_mock
_l7rule_mock.l7policy = _l7policy_mock
@ -103,6 +99,7 @@ class TestControllerWorker(base.TestCase):
fetch_mock = mock.MagicMock(return_value=AMP_ID)
_flow_mock.storage.fetch = fetch_mock
_pool_mock.id = POOL_ID
_health_mon_mock.pool_id = POOL_ID
_health_mon_mock.id = HM_ID
@ -204,7 +201,9 @@ class TestControllerWorker(base.TestCase):
constants.LISTENERS:
[_listener_mock],
constants.LOADBALANCER:
_load_balancer_mock}))
_load_balancer_mock,
constants.POOL:
_pool_mock}))
_flow_mock.run.assert_called_once_with()
@ -235,11 +234,12 @@ class TestControllerWorker(base.TestCase):
assert_called_once_with(_flow_mock,
store={constants.HEALTH_MON:
_health_mon_mock,
constants.POOL_ID: HM_ID,
constants.LISTENERS:
[_listener_mock],
constants.LOADBALANCER:
_load_balancer_mock}))
_load_balancer_mock,
constants.POOL:
_pool_mock}))
_flow_mock.run.assert_called_once_with()
@ -271,6 +271,8 @@ class TestControllerWorker(base.TestCase):
assert_called_once_with(_flow_mock,
store={constants.HEALTH_MON:
_health_mon_mock,
constants.POOL:
_pool_mock,
constants.LISTENERS:
[_listener_mock],
constants.LOADBALANCER:

View File

@ -72,7 +72,7 @@ class TestTaskUtils(base.TestCase):
mock_health_mon_repo_update.assert_called_once_with(
TEST_SESSION,
pool_id=self.HEALTH_MON_ID,
id=self.HEALTH_MON_ID,
provisioning_status=constants.ERROR)
# Exception path