Skip to content

Commit e2bc072

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix hm operating status to ONLINE in single lb call"
2 parents 5e15981 + e20ceeb commit e2bc072

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

octavia/controller/worker/v2/flows/listener_flows.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def get_create_all_listeners_flow(self):
6060
requires=constants.LOADBALANCER_ID))
6161
create_all_listeners_flow.add(network_tasks.UpdateVIP(
6262
requires=constants.LISTENERS))
63+
create_all_listeners_flow.add(
64+
database_tasks.MarkHealthMonitorsOnlineInDB(
65+
requires=constants.LOADBALANCER))
6366
return create_all_listeners_flow
6467

6568
def get_delete_listener_flow(self):

octavia/controller/worker/v2/tasks/database_tasks.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,39 @@ def revert(self, health_mon, *args, **kwargs):
19231923
health_mon[constants.HEALTHMONITOR_ID])
19241924

19251925

1926+
class MarkHealthMonitorsOnlineInDB(BaseDatabaseTask):
1927+
"""Mark all enabled health monitors Online
1928+
1929+
:param loadbalancer: Dictionary of a Load Balancer that has associated
1930+
health monitors
1931+
:returns: None
1932+
"""
1933+
1934+
def execute(self, loadbalancer: dict):
1935+
db_lb = self.loadbalancer_repo.get(
1936+
db_apis.get_session(),
1937+
id=loadbalancer[constants.LOADBALANCER_ID])
1938+
1939+
# Update the healthmonitors of either attached listeners or l7policies
1940+
hms_to_update = []
1941+
1942+
for listener in db_lb.listeners:
1943+
if listener.default_pool and listener.default_pool.health_monitor:
1944+
hm = listener.default_pool.health_monitor
1945+
if hm.enabled:
1946+
hms_to_update.append(hm.id)
1947+
for l7policy in listener.l7policies:
1948+
if l7policy.redirect_pool and (
1949+
l7policy.redirect_pool.health_monitor):
1950+
hm = l7policy.redirect_pool.health_monitor
1951+
if hm.enabled:
1952+
hms_to_update.append(hm.id)
1953+
1954+
for hm_id in hms_to_update:
1955+
self.health_mon_repo.update(db_apis.get_session(), hm_id,
1956+
operating_status=constants.ONLINE)
1957+
1958+
19261959
class MarkL7PolicyActiveInDB(BaseDatabaseTask):
19271960
"""Mark the l7policy ACTIVE in the DB.
19281961

octavia/tests/unit/controller/worker/v2/tasks/test_database_tasks.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,53 @@ def test_mark_health_mon_pending_update_in_db(
21452145
id=HM_ID,
21462146
provisioning_status=constants.ERROR)
21472147

2148+
@mock.patch('octavia.db.repositories.LoadBalancerRepository.get')
2149+
@mock.patch('octavia.db.repositories.HealthMonitorRepository.update')
2150+
def test_mark_health_monitors_online_in_db(self,
2151+
mock_health_mon_repo_update,
2152+
mock_loadbalancer_repo_get,
2153+
mock_generate_uuid,
2154+
mock_LOG,
2155+
mock_get_session,
2156+
mock_loadbalancer_repo_update,
2157+
mock_listener_repo_update,
2158+
mock_amphora_repo_update,
2159+
mock_amphora_repo_delete):
2160+
# Creating a mock hm for a default pool
2161+
mock_lb = mock.MagicMock()
2162+
mock_listener = mock.MagicMock()
2163+
mock_default_pool = mock_listener.default_pool
2164+
mock_hm_def_pool = mock_default_pool.health_monitor
2165+
mock_hm_def_pool.id = uuidutils.generate_uuid()
2166+
mock_lb.listeners = [mock_listener]
2167+
2168+
# Creating a mock hm for a redirect pool of an l7policy
2169+
mock_l7policy = mock.MagicMock()
2170+
mock_redirect_pool = mock_l7policy.redirect_pool
2171+
mock_hm_l7_policy = mock_redirect_pool.health_monitor
2172+
mock_hm_l7_policy.id = uuidutils.generate_uuid()
2173+
mock_listener.l7policies = [mock_l7policy]
2174+
2175+
# Creating a mock hm for a non default pool - we check its health
2176+
# monitor won't be updated
2177+
mock_pool = mock.MagicMock()
2178+
mock_hm_non_def_pool = mock_pool.health_monitor
2179+
mock_hm_non_def_pool.id = uuidutils.generate_uuid()
2180+
mock_lb.pools = [mock_pool]
2181+
2182+
mock_loadbalancer_repo_get.return_value = mock_lb
2183+
mark_health_mon_online = (database_tasks.
2184+
MarkHealthMonitorsOnlineInDB())
2185+
mark_health_mon_online.execute(mock_lb)
2186+
2187+
mock_session = 'TEST'
2188+
for mock_id in [mock_hm_def_pool.id, mock_hm_l7_policy.id]:
2189+
mock_health_mon_repo_update.assert_called_with(
2190+
mock_session,
2191+
mock_id,
2192+
operating_status=constants.ONLINE)
2193+
self.assertEqual(2, mock_health_mon_repo_update.call_count)
2194+
21482195
@mock.patch('octavia.db.repositories.L7PolicyRepository.update')
21492196
@mock.patch('octavia.db.repositories.L7PolicyRepository.get')
21502197
def test_mark_l7policy_active_in_db(self,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug that didn't set all the active load balancer Health Monitors
5+
ONLINE in populated LB single-create calls.

0 commit comments

Comments
 (0)