diff --git a/neutron/common/ovn/constants.py b/neutron/common/ovn/constants.py index 5c0aa8951ba..78334dd534f 100644 --- a/neutron/common/ovn/constants.py +++ b/neutron/common/ovn/constants.py @@ -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' OVN_PORT_BINDING_PROFILE = portbindings.PROFILE OVN_HOST_ID_EXT_ID_KEY = 'neutron:host_id' +OVN_FIP_DISTRIBUTED_KEY = 'neutron:fip-distributed' MIGRATING_ATTR = 'migrating_to' OVN_ROUTER_PORT_OPTION_KEYS = ['router-port', 'nat-addresses', diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py index c6ab5fbbd33..8a34af8576c 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py @@ -1300,6 +1300,21 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase): 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): diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py index 5c631ee2c0a..36671829207 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py @@ -1270,6 +1270,54 @@ class TestMaintenance(_TestMaintenanceHelper): lr = self.nb_api.lookup('Logical_Router', utils.ovn_name(router['id'])) 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, test_log_driver.LogApiTestCaseBase):