Set distributed flag to NB_Global

The patch introduces a new maintenance routine that always sets
NB_Global.external_ids:fip-distributed value in Northbound OVN DB to the
same value that enable_distributed_floating_ip config option has.

This is useful for projects that do not use RPC and rely on data only in
the OVN database.

Conflicts:
	neutron/common/ovn/constants.py
	neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py
	neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py

Closes-Bug: #2083456
Change-Id: I7f30e6e030292b762dc9fc785c494c0dc215c749
Signed-off-by: Jakub Libosvar <libosvar@redhat.com>
(cherry picked from commit 1300110ccb)
This commit is contained in:
Jakub Libosvar 2024-10-01 16:54:18 -04:00
parent bcf248e6ea
commit 5c00b7975e
3 changed files with 64 additions and 0 deletions

View File

@ -56,6 +56,7 @@ OVN_LIVENESS_CHECK_EXT_ID_KEY = 'neutron:liveness_check_at'
METADATA_LIVENESS_CHECK_EXT_ID_KEY = 'neutron:metadata_liveness_check_at' METADATA_LIVENESS_CHECK_EXT_ID_KEY = 'neutron:metadata_liveness_check_at'
OVN_PORT_BINDING_PROFILE = portbindings.PROFILE OVN_PORT_BINDING_PROFILE = portbindings.PROFILE
OVN_HOST_ID_EXT_ID_KEY = 'neutron:host_id' OVN_HOST_ID_EXT_ID_KEY = 'neutron:host_id'
OVN_FIP_DISTRIBUTED_KEY = 'neutron:fip-distributed'
MIGRATING_ATTR = 'migrating_to' MIGRATING_ATTR = 'migrating_to'
OVN_ROUTER_PORT_OPTION_KEYS = ['router-port', 'nat-addresses', OVN_ROUTER_PORT_OPTION_KEYS = ['router-port', 'nat-addresses',

View File

@ -1300,6 +1300,21 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
raise periodics.NeverAgain() raise periodics.NeverAgain()
@has_lock_periodic(
periodic_run_limit=ovn_const.MAINTENANCE_TASK_RETRY_LIMIT,
spacing=ovn_const.MAINTENANCE_ONE_RUN_TASK_SPACING,
run_immediately=True)
def set_fip_distributed_flag(self):
"""Set the NB_Global.external_ids:fip-distributed flag."""
distributed = ovn_conf.is_ovn_distributed_floating_ip()
LOG.debug(
"Setting fip-distributed flag in NB_Global to %s", distributed)
self._nb_idl.db_set(
'NB_Global', '.', external_ids={
ovn_const.OVN_FIP_DISTRIBUTED_KEY: str(distributed)}).execute(
check_error=True)
raise periodics.NeverAgain()
class HashRingHealthCheckPeriodics(object): class HashRingHealthCheckPeriodics(object):

View File

@ -1270,6 +1270,54 @@ class TestMaintenance(_TestMaintenanceHelper):
lr = self.nb_api.lookup('Logical_Router', utils.ovn_name(router['id'])) lr = self.nb_api.lookup('Logical_Router', utils.ovn_name(router['id']))
self.assertEqual([], lr.ports[0].gateway_chassis) self.assertEqual([], lr.ports[0].gateway_chassis)
def _get_nb_global_external_ids(self):
return self.nb_api.db_get(
'NB_Global', '.', 'external_ids').execute(check_error=True)
def test_set_fip_distributed_flag(self):
ovn_config.cfg.CONF.set_override(
'enable_distributed_floating_ip', True, 'ovn')
nb_global_ext_id = self._get_nb_global_external_ids()
self.assertNotIn(ovn_const.OVN_FIP_DISTRIBUTED_KEY, nb_global_ext_id)
self.assertRaises(
periodics.NeverAgain, self.maint.set_fip_distributed_flag)
nb_global_ext_id = self._get_nb_global_external_ids()
self.assertEqual(
"True", nb_global_ext_id[ovn_const.OVN_FIP_DISTRIBUTED_KEY])
def _test_set_fip_distributed_flag_change(
self, original_value, config_value):
ovn_config.cfg.CONF.set_override(
'enable_distributed_floating_ip', config_value, 'ovn')
self.nb_api.db_set(
'NB_Global', '.', external_ids={
ovn_const.OVN_FIP_DISTRIBUTED_KEY: str(original_value)}
).execute(check_error=True)
nb_global_ext_id = self._get_nb_global_external_ids()
self.assertEqual(
str(original_value),
nb_global_ext_id[ovn_const.OVN_FIP_DISTRIBUTED_KEY])
self.assertRaises(
periodics.NeverAgain, self.maint.set_fip_distributed_flag)
nb_global_ext_id = self._get_nb_global_external_ids()
self.assertEqual(
str(config_value),
nb_global_ext_id[ovn_const.OVN_FIP_DISTRIBUTED_KEY])
def test_set_fip_distributed_flag_changed(self):
self._test_set_fip_distributed_flag_change(
original_value=False,
config_value=True)
def test_set_fip_distributed_flag_unchanged(self):
self._test_set_fip_distributed_flag_change(
original_value=True,
config_value=True)
class TestLogMaintenance(_TestMaintenanceHelper, class TestLogMaintenance(_TestMaintenanceHelper,
test_log_driver.LogApiTestCaseBase): test_log_driver.LogApiTestCaseBase):