Skip to content

Commit 07b4c4b

Browse files
ricolinfernandoroyosanchez
authored andcommitted
Add LB sync logic
This patch adds the logic to sync a Load Balancer (LB) entity from the Octavia database, correcting any discrepancies in fields or creating it if it does not exist in the OVN Northbound (NB) database. Future patches will incrementally add support for syncing the remaining entities. Related-Bug: #2045415 Co-authored-by: Fernando Royo <[email protected]> Co-authored-by: Rico Lin <[email protected]> Change-Id: I2916a382bd264b76df794ee94cdfe3035c75453a
1 parent 3549fa9 commit 07b4c4b

File tree

4 files changed

+903
-68
lines changed

4 files changed

+903
-68
lines changed

ovn_octavia_provider/driver.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from octavia_lib.api.drivers import provider_base as driver_base
2121
from octavia_lib.common import constants
2222
from oslo_log import log as logging
23+
from ovsdbapp.backend.ovs_idl import idlutils
2324

2425
from ovn_octavia_provider.common import clients
2526
from ovn_octavia_provider.common import config as ovn_conf
@@ -89,7 +90,7 @@ def _check_for_allowed_cidrs(self, allowed_cidrs):
8990
user_fault_string=msg,
9091
operator_fault_string=msg)
9192

92-
def loadbalancer_create(self, loadbalancer):
93+
def _get_loadbalancer_request_info(self, loadbalancer):
9394
admin_state_up = loadbalancer.admin_state_up
9495
if isinstance(admin_state_up, o_datamodels.UnsetType):
9596
admin_state_up = True
@@ -102,9 +103,12 @@ def loadbalancer_create(self, loadbalancer):
102103
o_datamodels.UnsetType):
103104
request_info[constants.ADDITIONAL_VIPS] = \
104105
loadbalancer.additional_vips
106+
return request_info
105107

108+
def loadbalancer_create(self, loadbalancer):
106109
request = {'type': ovn_const.REQ_TYPE_LB_CREATE,
107-
'info': request_info}
110+
'info': self._get_loadbalancer_request_info(
111+
loadbalancer)}
108112
self._ovn_helper.add_request(request)
109113

110114
if not isinstance(loadbalancer.listeners, o_datamodels.UnsetType):
@@ -587,10 +591,38 @@ def health_monitor_delete(self, healthmonitor):
587591
'info': request_info}
588592
self._ovn_helper.add_request(request)
589593

594+
def _ensure_loadbalancer(self, loadbalancer):
595+
try:
596+
ovn_lbs = self._ovn_helper._find_ovn_lbs_with_retry(
597+
loadbalancer.loadbalancer_id)
598+
except idlutils.RowNotFound:
599+
LOG.debug(f"OVN loadbalancer {loadbalancer.loadbalancer_id} "
600+
"not found. Start create process.")
601+
# TODO(froyo): By now just syncing LB only
602+
status = self._ovn_helper.lb_create(
603+
self._get_loadbalancer_request_info(loadbalancer))
604+
self._ovn_helper._update_status_to_octavia(status)
605+
else:
606+
# Load Balancer found, check LB and listener/pool/member/hms
607+
# related
608+
for ovn_lb in ovn_lbs:
609+
LOG.debug(
610+
f"Sync - Loadbalancer {loadbalancer.loadbalancer_id} "
611+
"found checking other entities related")
612+
self._ovn_helper.lb_sync(
613+
self._get_loadbalancer_request_info(loadbalancer), ovn_lb)
614+
status = self._ovn_helper._get_current_operating_statuses(
615+
ovn_lb)
616+
self._ovn_helper._update_status_to_octavia(status)
617+
590618
def do_sync(self, **lb_filters):
591619
LOG.info(f"Starting sync OVN DB with Loadbalancer filter {lb_filters}")
592620
octavia_client = clients.get_octavia_client()
593621
# We can add project_id to lb_filters for lbs to limit the scope.
594622
lbs = self._ovn_helper.get_octavia_lbs(octavia_client, **lb_filters)
595623
for lb in lbs:
596-
LOG.info(f"Starting sync OVN DB with Loadbalancer {lb.id}")
624+
LOG.info(f"Starting sync OVN DB with Loadbalancer {lb.name}")
625+
provider_lb = (
626+
self._ovn_helper._octavia_driver_lib.get_loadbalancer(lb.id)
627+
)
628+
self._ensure_loadbalancer(provider_lb)

0 commit comments

Comments
 (0)