Merge "Fix hm operating status to ONLINE in single lb call" into stable/yoga
This commit is contained in:
commit
b81454a2c0
@ -60,6 +60,9 @@ class ListenerFlows(object):
|
||||
requires=constants.LOADBALANCER))
|
||||
create_all_listeners_flow.add(network_tasks.UpdateVIP(
|
||||
requires=constants.LOADBALANCER))
|
||||
create_all_listeners_flow.add(
|
||||
database_tasks.MarkHealthMonitorsOnlineInDB(
|
||||
requires=constants.LOADBALANCER))
|
||||
return create_all_listeners_flow
|
||||
|
||||
def get_delete_listener_flow(self):
|
||||
|
@ -1747,6 +1747,38 @@ class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
|
||||
self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
|
||||
|
||||
|
||||
class MarkHealthMonitorsOnlineInDB(BaseDatabaseTask):
|
||||
"""Mark all enabled health monitors Online
|
||||
|
||||
:param loadbalancer: The Load Balancer that has associated health monitors
|
||||
:returns: None
|
||||
"""
|
||||
|
||||
def execute(self, loadbalancer):
|
||||
db_lb = self.loadbalancer_repo.get(
|
||||
db_apis.get_session(),
|
||||
id=loadbalancer.id)
|
||||
|
||||
# Update the healthmonitors of either attached listeners or l7policies
|
||||
hms_to_update = []
|
||||
|
||||
for listener in db_lb.listeners:
|
||||
if listener.default_pool and listener.default_pool.health_monitor:
|
||||
hm = listener.default_pool.health_monitor
|
||||
if hm.enabled:
|
||||
hms_to_update.append(hm.id)
|
||||
for l7policy in listener.l7policies:
|
||||
if l7policy.redirect_pool and (
|
||||
l7policy.redirect_pool.health_monitor):
|
||||
hm = l7policy.redirect_pool.health_monitor
|
||||
if hm.enabled:
|
||||
hms_to_update.append(hm.id)
|
||||
|
||||
for hm_id in hms_to_update:
|
||||
self.health_mon_repo.update(db_apis.get_session(), hm_id,
|
||||
operating_status=constants.ONLINE)
|
||||
|
||||
|
||||
class MarkL7PolicyActiveInDB(BaseDatabaseTask):
|
||||
"""Mark the l7policy ACTIVE in the DB.
|
||||
|
||||
|
@ -60,6 +60,9 @@ class ListenerFlows(object):
|
||||
requires=constants.LOADBALANCER_ID))
|
||||
create_all_listeners_flow.add(network_tasks.UpdateVIP(
|
||||
requires=constants.LISTENERS))
|
||||
create_all_listeners_flow.add(
|
||||
database_tasks.MarkHealthMonitorsOnlineInDB(
|
||||
requires=constants.LOADBALANCER))
|
||||
return create_all_listeners_flow
|
||||
|
||||
def get_delete_listener_flow(self):
|
||||
|
@ -1895,6 +1895,39 @@ class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
|
||||
health_mon[constants.HEALTHMONITOR_ID])
|
||||
|
||||
|
||||
class MarkHealthMonitorsOnlineInDB(BaseDatabaseTask):
|
||||
"""Mark all enabled health monitors Online
|
||||
|
||||
:param loadbalancer: Dictionary of a Load Balancer that has associated
|
||||
health monitors
|
||||
:returns: None
|
||||
"""
|
||||
|
||||
def execute(self, loadbalancer: dict):
|
||||
db_lb = self.loadbalancer_repo.get(
|
||||
db_apis.get_session(),
|
||||
id=loadbalancer[constants.LOADBALANCER_ID])
|
||||
|
||||
# Update the healthmonitors of either attached listeners or l7policies
|
||||
hms_to_update = []
|
||||
|
||||
for listener in db_lb.listeners:
|
||||
if listener.default_pool and listener.default_pool.health_monitor:
|
||||
hm = listener.default_pool.health_monitor
|
||||
if hm.enabled:
|
||||
hms_to_update.append(hm.id)
|
||||
for l7policy in listener.l7policies:
|
||||
if l7policy.redirect_pool and (
|
||||
l7policy.redirect_pool.health_monitor):
|
||||
hm = l7policy.redirect_pool.health_monitor
|
||||
if hm.enabled:
|
||||
hms_to_update.append(hm.id)
|
||||
|
||||
for hm_id in hms_to_update:
|
||||
self.health_mon_repo.update(db_apis.get_session(), hm_id,
|
||||
operating_status=constants.ONLINE)
|
||||
|
||||
|
||||
class MarkL7PolicyActiveInDB(BaseDatabaseTask):
|
||||
"""Mark the l7policy ACTIVE in the DB.
|
||||
|
||||
|
@ -1976,6 +1976,53 @@ class TestDatabaseTasks(base.TestCase):
|
||||
id=HM_ID,
|
||||
provisioning_status=constants.ERROR)
|
||||
|
||||
@mock.patch('octavia.db.repositories.LoadBalancerRepository.get')
|
||||
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
|
||||
def test_mark_health_monitors_online_in_db(self,
|
||||
mock_health_mon_repo_update,
|
||||
mock_loadbalancer_repo_get,
|
||||
mock_generate_uuid,
|
||||
mock_LOG,
|
||||
mock_get_session,
|
||||
mock_loadbalancer_repo_update,
|
||||
mock_listener_repo_update,
|
||||
mock_amphora_repo_update,
|
||||
mock_amphora_repo_delete):
|
||||
# Creating a mock hm for a default pool
|
||||
mock_lb = mock.MagicMock()
|
||||
mock_listener = mock.MagicMock()
|
||||
mock_default_pool = mock_listener.default_pool
|
||||
mock_hm_def_pool = mock_default_pool.health_monitor
|
||||
mock_hm_def_pool.id = uuidutils.generate_uuid()
|
||||
mock_lb.listeners = [mock_listener]
|
||||
|
||||
# Creating a mock hm for a redirect pool of an l7policy
|
||||
mock_l7policy = mock.MagicMock()
|
||||
mock_redirect_pool = mock_l7policy.redirect_pool
|
||||
mock_hm_l7_policy = mock_redirect_pool.health_monitor
|
||||
mock_hm_l7_policy.id = uuidutils.generate_uuid()
|
||||
mock_listener.l7policies = [mock_l7policy]
|
||||
|
||||
# Creating a mock hm for a non default pool - we check its health
|
||||
# monitor won't be updated
|
||||
mock_pool = mock.MagicMock()
|
||||
mock_hm_non_def_pool = mock_pool.health_monitor
|
||||
mock_hm_non_def_pool.id = uuidutils.generate_uuid()
|
||||
mock_lb.pools = [mock_pool]
|
||||
|
||||
mock_loadbalancer_repo_get.return_value = mock_lb
|
||||
mark_health_mon_online = (database_tasks.
|
||||
MarkHealthMonitorsOnlineInDB())
|
||||
mark_health_mon_online.execute(mock_lb)
|
||||
|
||||
mock_session = 'TEST'
|
||||
for mock_id in [mock_hm_def_pool.id, mock_hm_l7_policy.id]:
|
||||
mock_health_mon_repo_update.assert_called_with(
|
||||
mock_session,
|
||||
mock_id,
|
||||
operating_status=constants.ONLINE)
|
||||
self.assertEqual(2, mock_health_mon_repo_update.call_count)
|
||||
|
||||
@mock.patch('octavia.db.repositories.L7PolicyRepository.update')
|
||||
def test_mark_l7policy_active_in_db(self,
|
||||
mock_l7policy_repo_update,
|
||||
|
@ -2104,6 +2104,53 @@ class TestDatabaseTasks(base.TestCase):
|
||||
id=HM_ID,
|
||||
provisioning_status=constants.ERROR)
|
||||
|
||||
@mock.patch('octavia.db.repositories.LoadBalancerRepository.get')
|
||||
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
|
||||
def test_mark_health_monitors_online_in_db(self,
|
||||
mock_health_mon_repo_update,
|
||||
mock_loadbalancer_repo_get,
|
||||
mock_generate_uuid,
|
||||
mock_LOG,
|
||||
mock_get_session,
|
||||
mock_loadbalancer_repo_update,
|
||||
mock_listener_repo_update,
|
||||
mock_amphora_repo_update,
|
||||
mock_amphora_repo_delete):
|
||||
# Creating a mock hm for a default pool
|
||||
mock_lb = mock.MagicMock()
|
||||
mock_listener = mock.MagicMock()
|
||||
mock_default_pool = mock_listener.default_pool
|
||||
mock_hm_def_pool = mock_default_pool.health_monitor
|
||||
mock_hm_def_pool.id = uuidutils.generate_uuid()
|
||||
mock_lb.listeners = [mock_listener]
|
||||
|
||||
# Creating a mock hm for a redirect pool of an l7policy
|
||||
mock_l7policy = mock.MagicMock()
|
||||
mock_redirect_pool = mock_l7policy.redirect_pool
|
||||
mock_hm_l7_policy = mock_redirect_pool.health_monitor
|
||||
mock_hm_l7_policy.id = uuidutils.generate_uuid()
|
||||
mock_listener.l7policies = [mock_l7policy]
|
||||
|
||||
# Creating a mock hm for a non default pool - we check its health
|
||||
# monitor won't be updated
|
||||
mock_pool = mock.MagicMock()
|
||||
mock_hm_non_def_pool = mock_pool.health_monitor
|
||||
mock_hm_non_def_pool.id = uuidutils.generate_uuid()
|
||||
mock_lb.pools = [mock_pool]
|
||||
|
||||
mock_loadbalancer_repo_get.return_value = mock_lb
|
||||
mark_health_mon_online = (database_tasks.
|
||||
MarkHealthMonitorsOnlineInDB())
|
||||
mark_health_mon_online.execute(mock_lb)
|
||||
|
||||
mock_session = 'TEST'
|
||||
for mock_id in [mock_hm_def_pool.id, mock_hm_l7_policy.id]:
|
||||
mock_health_mon_repo_update.assert_called_with(
|
||||
mock_session,
|
||||
mock_id,
|
||||
operating_status=constants.ONLINE)
|
||||
self.assertEqual(2, mock_health_mon_repo_update.call_count)
|
||||
|
||||
@mock.patch('octavia.db.repositories.L7PolicyRepository.update')
|
||||
@mock.patch('octavia.db.repositories.L7PolicyRepository.get')
|
||||
def test_mark_l7policy_active_in_db(self,
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed a bug that didn't set all the active load balancer Health Monitors
|
||||
ONLINE in populated LB single-create calls.
|
Loading…
Reference in New Issue
Block a user