Browse Source

Merge "Fix race conditions between API and worker DB calls"

changes/56/794956/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
f0d6624083
2 changed files with 29 additions and 7 deletions
  1. +27
    -6
      octavia/controller/worker/v2/controller_worker.py
  2. +2
    -1
      octavia/tests/unit/controller/worker/v2/test_controller_worker.py

+ 27
- 6
octavia/controller/worker/v2/controller_worker.py View File

@ -426,8 +426,15 @@ class ControllerWorker(object):
:returns: None
:raises NoSuitablePool: Unable to find the node pool
"""
pool = self._pool_repo.get(db_apis.get_session(),
id=member[constants.POOL_ID])
db_member = self._member_repo.get(db_apis.get_session(),
id=member[constants.MEMBER_ID])
if not db_member:
LOG.warning('Failed to fetch %s %s from DB. Retrying for up to '
'60 seconds.', 'l7member',
member[constants.MEMBER_ID])
raise db_exceptions.NoResultFound
pool = db_member.pool
load_balancer = pool.load_balancer
provider_lb = provider_utils.db_loadbalancer_to_provider_loadbalancer(
load_balancer).to_dict()
@ -693,8 +700,15 @@ class ControllerWorker(object):
:returns: None
:raises NoResultFound: Unable to find the object
"""
db_listener = self._listener_repo.get(
db_apis.get_session(), id=l7policy[constants.LISTENER_ID])
db_l7policy = self._l7policy_repo.get(
db_apis.get_session(), id=l7policy[constants.L7POLICY_ID])
if not db_l7policy:
LOG.warning('Failed to fetch %s %s from DB. Retrying for up to '
'60 seconds.', 'l7policy',
l7policy[constants.L7POLICY_ID])
raise db_exceptions.NoResultFound
db_listener = db_l7policy.listener
listeners_dicts = (
provider_utils.db_listeners_to_provider_dicts_list_of_dicts(
@ -767,8 +781,15 @@ class ControllerWorker(object):
:returns: None
:raises NoResultFound: Unable to find the object
"""
db_l7policy = self._l7policy_repo.get(db_apis.get_session(),
id=l7rule[constants.L7POLICY_ID])
db_l7rule = self._l7rule_repo.get(db_apis.get_session(),
id=l7rule[constants.L7RULE_ID])
if not db_l7rule:
LOG.warning('Failed to fetch %s %s from DB. Retrying for up to '
'60 seconds.', 'l7rule',
l7rule[constants.L7RULE_ID])
raise db_exceptions.NoResultFound
db_l7policy = db_l7rule.l7policy
load_balancer = db_l7policy.listener.load_balancer


+ 2
- 1
octavia/tests/unit/controller/worker/v2/test_controller_worker.py View File

@ -983,6 +983,7 @@ class TestControllerWorker(base.TestCase):
constants.L7POLICY_ID: L7POLICY_ID,
constants.LISTENER_ID: LISTENER_ID
}
mock_l7policy_repo_get.side_effect = [None, _l7policy_mock]
cw.create_l7policy(l7policy_mock)
(cw.services_controller.run_poster.
@ -1071,7 +1072,7 @@ class TestControllerWorker(base.TestCase):
mock_amp_repo_get):
_flow_mock.reset_mock()
mock_l7policy_repo_get.return_value = _l7policy_mock
mock_l7rule_repo_get.side_effect = [None, _l7rule_mock]
cw = controller_worker.ControllerWorker()


Loading…
Cancel
Save