From 1f1824397dd4e2cfd2327b2d9fec7f57453b45d2 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Mon, 26 Jun 2023 16:50:49 +0000 Subject: [PATCH] [OVN] Populate the "router.distributed" flag in ML2/OVN In ML2/OVN there is a static common configuration parameter to define if the routers (more in particular the floating IPs) can be distributed or centralized: [ovn] enable_distributed_floating_ip This patch writes this value on each new router created. It also implements a maintenance method to populate this flag when the Neutron API is restarted and the value changed. Closes-Bug: #2022058 Change-Id: Ib109b09fde4db8738c1d0b3e394c201492d210c6 --- doc/source/ovn/faq/index.rst | 7 ++++--- neutron/objects/router.py | 6 ++++++ .../ovn/mech_driver/ovsdb/maintenance.py | 19 +++++++++++++++++++ neutron/services/ovn_l3/plugin.py | 5 +++++ neutron/tests/unit/objects/test_router.py | 10 ++++++++++ ...ter-distributed-flag-48a8e72c1b258e40.yaml | 12 ++++++++++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/ovn-router-distributed-flag-48a8e72c1b258e40.yaml diff --git a/doc/source/ovn/faq/index.rst b/doc/source/ovn/faq/index.rst index 2f1ec337adc..8c8849d56d2 100644 --- a/doc/source/ovn/faq/index.rst +++ b/doc/source/ovn/faq/index.rst @@ -24,9 +24,10 @@ Frequently Asked Questions | | VRRP traffic. | tunnel endpoints to detect | | | | connectivity issues to nodes. | +---------------+---------------------------+--------------------------------+ -| DVR | exposes the "distributed" | no "distributed" flag is shown | -| API | flag on routers only | or available on routers via | -| | modifiable by admin. | API. | +| DVR | exposes the "distributed" | exposes the "distributed" flag | +| API | flag on routers only | based on the configuration | +| | modifiable by admin. | option | +| | | enable_distributed_floating_ip | +---------------+---------------------------+--------------------------------+ | DVR | uses namespaces, veths, | Uses OpenFlow rules on the | | dataplane | ip routing, ip rules and | compute nodes. | diff --git a/neutron/objects/router.py b/neutron/objects/router.py index 66307e641b1..49f308b2db6 100644 --- a/neutron/objects/router.py +++ b/neutron/objects/router.py @@ -136,6 +136,12 @@ class RouterExtraAttributes(base.NeutronDbObject): return list(query) + @classmethod + @db_api.CONTEXT_WRITER + def update_distributed_flag(cls, context, distributed): + query = context.session.query(cls.db_model) + query.update({'distributed': distributed}) + def obj_make_compatible(self, primitive, target_version): _target_version = versionutils.convert_version_to_tuple(target_version) if _target_version < (1, 1): 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 b639af08713..3149fd7a7d2 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py @@ -1095,6 +1095,25 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase): raise periodics.NeverAgain() + @has_lock_periodic(spacing=86400, run_immediately=True) + def update_router_distributed_flag(self): + """Set "enable_distributed_floating_ip" on the router.distributed flag. + + This method is needed to sync the static configuration parameter + "enable_distributed_floating_ip", loaded when the Neutron API starts, + and the router.distributed flag. + + NOTE: remove this method when the RFE that allows to define the + distributed flag per FIP is implemented. At this point, the + router.distributed flag will be useless. + RFE: https://bugs.launchpad.net/neutron/+bug/1978039 + """ + distributed = ovn_conf.is_ovn_distributed_floating_ip() + router_obj.RouterExtraAttributes.update_distributed_flag( + n_context.get_admin_context(), distributed) + + raise periodics.NeverAgain() + class HashRingHealthCheckPeriodics(object): diff --git a/neutron/services/ovn_l3/plugin.py b/neutron/services/ovn_l3/plugin.py index 50689847313..99c15b431c9 100644 --- a/neutron/services/ovn_l3/plugin.py +++ b/neutron/services/ovn_l3/plugin.py @@ -35,6 +35,7 @@ from neutron._i18n import _ from neutron.common.ovn import constants as ovn_const from neutron.common.ovn import extensions from neutron.common.ovn import utils +from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf from neutron.db.availability_zone import router as router_az_db from neutron.db import dns_db from neutron.db import extraroute_db @@ -174,6 +175,10 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase, context.session.flush() router_id = payload.resource_id router_db = payload.metadata['router_db'] + # NOTE(ralonsoh): the "distributed" flag is a static configuration + # parameter that needs to be defined only during the router creation. + extra_attr = router_db['extra_attributes'] + extra_attr.distributed = ovn_conf.is_ovn_distributed_floating_ip() db_rev.create_initial_revision( context, router_id, ovn_const.TYPE_ROUTERS, diff --git a/neutron/tests/unit/objects/test_router.py b/neutron/tests/unit/objects/test_router.py index 6deedfa00f8..b46b4e37997 100644 --- a/neutron/tests/unit/objects/test_router.py +++ b/neutron/tests/unit/objects/test_router.py @@ -61,6 +61,16 @@ class RouterExtraAttrsDbObjTestCase(obj_test_base.BaseDbObjectTestCase, self.update_obj_fields( {'router_id': lambda: self._create_test_router_id()}) + def test_update_distributed_flag(self): + for obj in self.objs: + obj.distributed = False + obj.create() + router.RouterExtraAttributes.update_distributed_flag(self.context, + True) + r_e_a_list = router.RouterExtraAttributes.get_objects(self.context) + for obj in r_e_a_list: + self.assertTrue(obj.distributed) + class RouterIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase): diff --git a/releasenotes/notes/ovn-router-distributed-flag-48a8e72c1b258e40.yaml b/releasenotes/notes/ovn-router-distributed-flag-48a8e72c1b258e40.yaml new file mode 100644 index 00000000000..d6744ea60d1 --- /dev/null +++ b/releasenotes/notes/ovn-router-distributed-flag-48a8e72c1b258e40.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + OVN routers now expose the "distributed" flag depending on the + configuration option ``enable_distributed_floating_ip``. Because this is a + common configuration option, all routers will expose the same value. This + value can flap if the Neutron API is restarted and the configuration option + changes. + NOTE: Once the RFE that allows us to define the distributed flag per + floating IP address is implemented in ML2/OVN, this flag will be useless + (no Launchpad bug has been created yet for this RFE, that is only a + proposed idea during several PTGs).