Merge "EVPN router always redistributes static routes"
This commit is contained in:
commit
0b6747490f
8 files changed
+201
-5
No files matched your search
@@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import model_base
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
@@ -59,6 +60,20 @@ class EVPNL3Instance(model_base.BASEV2):
|
||||
|
||||
revises_on_change = ('router',)
|
||||
|
||||
@classmethod
|
||||
@db_api.CONTEXT_READER
|
||||
def get_all_router_ids(cls, context):
|
||||
"""Get all router IDs that have EVPN instances.
|
||||
|
||||
Returns a list of router_id strings without loading joined
|
||||
relationships (mapping, router). This is more efficient than
|
||||
querying full EVPNL3Instance objects when only router_id is needed.
|
||||
|
||||
:param context: Neutron request context
|
||||
:returns: list of router_id strings
|
||||
"""
|
||||
return [row[0] for row in context.session.query(cls.router_id).all()]
|
||||
|
||||
|
||||
class EVPNNetwork(model_base.BASEV2):
|
||||
"""Links a network to an EVPN L3 instance (router).
|
||||
|
||||
@@ -43,6 +43,7 @@ from neutron.common.ovn import utils
|
||||
from neutron.common import wsgi_utils
|
||||
from neutron.conf.agent import ovs_conf
|
||||
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
|
||||
from neutron.db.models import evpn as evpn_models
|
||||
from neutron.db import ovn_hash_ring_db as hash_ring_db
|
||||
from neutron.db import ovn_revision_numbers_db as revision_numbers_db
|
||||
from neutron.db import segments_db
|
||||
@@ -51,6 +52,8 @@ from neutron.objects import ports as ports_obj
|
||||
from neutron.objects import pvlan as pvlan_obj
|
||||
from neutron.objects import router as router_obj
|
||||
from neutron.objects import securitygroup as sg_obj
|
||||
from neutron.services.bgp import constants as bgp_const
|
||||
from neutron.services.evpn import constants as evpn_const
|
||||
from neutron.services.pvlan.drivers.ovn import driver as pvlan_ovn_driver
|
||||
|
||||
|
||||
@@ -1598,6 +1601,52 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
|
||||
|
||||
raise periodics.NeverAgain()
|
||||
|
||||
# TODO(ichen): Remove this method in the I+4=M (2029.1) cycle (2nd next
|
||||
# SLURP release)
|
||||
@has_lock_periodic(
|
||||
periodic_run_limit=ovn_const.MAINTENANCE_TASK_RETRY_LIMIT,
|
||||
spacing=ovn_const.MAINTENANCE_ONE_RUN_TASK_SPACING,
|
||||
run_immediately=True)
|
||||
@log_maintenance_task(
|
||||
start_message='Provisioning static route redistribution on existing '
|
||||
'EVPN routers.')
|
||||
def provision_evpn_static_route_redistribution(self):
|
||||
"""Set dynamic-routing-redistribute=static on existing EVPN routers.
|
||||
|
||||
This maintenance method provisions the static route redistribution
|
||||
option on EVPN logical routers that were created before this feature
|
||||
was added. The option enables static routes to be advertised through
|
||||
EVPN, which is required for some EVPN deployments.
|
||||
|
||||
This method queries all routers with EVPN instances, checks if they
|
||||
have the redistribute option set in OVN, and provisions it if missing.
|
||||
"""
|
||||
|
||||
context = n_context.get_admin_context()
|
||||
|
||||
# Query all router IDs that have EVPN instances (optimized to avoid
|
||||
# loading joined VNIVLANMapping and Router relationships)
|
||||
router_ids = evpn_models.EVPNL3Instance.get_all_router_ids(context)
|
||||
|
||||
if not router_ids:
|
||||
LOG.debug('No EVPN routers found, skipping maintenance task')
|
||||
raise periodics.NeverAgain()
|
||||
|
||||
# Build all db_set commands for a single transaction
|
||||
options = {bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE:
|
||||
evpn_const.EVPN_LR_REDISTRIBUTE_OPTION}
|
||||
|
||||
with self._nb_idl.transaction(check_error=True) as txn:
|
||||
for router_id in router_ids:
|
||||
lr_name = utils.ovn_name(router_id)
|
||||
txn.add(self._nb_idl.db_set(
|
||||
'Logical_Router', lr_name, ('options', options)))
|
||||
|
||||
LOG.info('Provisioned static route redistribution for %d EVPN '
|
||||
'routers', len(router_ids))
|
||||
|
||||
raise periodics.NeverAgain()
|
||||
|
||||
|
||||
class HashRingHealthCheckPeriodics:
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ BGP_BRIDGE_NIC_TYPES = ('', 'system')
|
||||
|
||||
BGP_LRP_TO_CHASSIS = 'neutron-bgp-lrp-to-chassis-router'
|
||||
|
||||
DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST = 'connected-as-host'
|
||||
DYNAMIC_ROUTE_TYPE_STATIC = 'static'
|
||||
|
||||
|
||||
class Enum(enum.Enum):
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ class CreateEVPNRouterCommand(command.BaseCommand):
|
||||
ovn_utils.setkeys(lrouter, 'options', {
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING: 'true',
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_VRF_ID: str(self.vni),
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE:
|
||||
evpn_const.EVPN_LR_REDISTRIBUTE_OPTION,
|
||||
ovn_const.LR_OPTIONS_DR_VRF_NAME:
|
||||
evpn_agent_utils.evpn_vrf_name(self.router_id),
|
||||
})
|
||||
@@ -168,7 +170,7 @@ class AdvertiseHostCommand(command.BaseCommand):
|
||||
|
||||
ovn_utils.setkeys(lrp, 'options', {
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE:
|
||||
'connected-as-host',
|
||||
bgp_const.DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.services.bgp import constants as bgp_const
|
||||
|
||||
EVPN_LRP_VNI_EXT_ID_KEY = 'vni'
|
||||
EVPN_LRP_VLAN_EXT_ID_KEY = 'vlan'
|
||||
EVPN_LS_NAME_PREFIX = 'evpn-ls-'
|
||||
EVPN_LRP_NAME_PATTERN = 'evpn-lrp-%(lrp_uuid)s-to-%(evpn_ls_name)s'
|
||||
EVPN_LSP_NAME_PATTERN = 'evpn-lsp-%(evpn_ls_name)s-to-%(lrp_uuid)s'
|
||||
EVPN_HCG_NAME_PREFIX = 'evpn-hcg-'
|
||||
EVPN_LR_REDISTRIBUTE_OPTION = bgp_const.DYNAMIC_ROUTE_TYPE_STATIC
|
||||
+120
@@ -32,10 +32,13 @@ from neutron_lib.utils import net as net_utils
|
||||
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.common.ovn import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as ovn_config
|
||||
from neutron.db import evpn_db
|
||||
from neutron.db import ovn_revision_numbers_db as db_rev
|
||||
from neutron.objects import ports as ports_obj
|
||||
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import maintenance
|
||||
from neutron.services.bgp import constants as bgp_const
|
||||
from neutron.services.portforwarding import constants as pf_consts
|
||||
from neutron.tests.functional import base
|
||||
from neutron.tests.functional.services.logapi.drivers.ovn \
|
||||
@@ -1739,6 +1742,123 @@ class TestMaintenance(_TestMaintenanceHelper):
|
||||
localnet_coexist.external_ids)
|
||||
|
||||
|
||||
class TestEVPNMaintenance(_TestMaintenanceHelper):
|
||||
"""Functional tests for EVPN maintenance tasks."""
|
||||
|
||||
def _create_evpn_router(self, vni, redistribute=''):
|
||||
"""Create an EVPN router with database entries.
|
||||
|
||||
Creates:
|
||||
- Actual Neutron router (via API)
|
||||
- EVPNL3Instance database entry (via EVPNDbHelper)
|
||||
- VNI/VLAN allocations and mapping (via EVPNDbHelper)
|
||||
- Sets redistribute option on OVN logical router
|
||||
"""
|
||||
# Create actual Neutron router (satisfies FK constraint)
|
||||
router_name = common_utils.get_rand_device_name(prefix='evpn-test-')
|
||||
router = self._create_router(router_name)
|
||||
router_id = router['id']
|
||||
lr_name = utils.ovn_name(router_id)
|
||||
|
||||
# Use EVPNDbHelper to create EVPN instance (production code path)
|
||||
evpn_helper = evpn_db.EVPNDbHelper()
|
||||
evpn_helper.allocate_vni_for_router(self.context, router_id, vni)
|
||||
|
||||
# Set the redistribute option
|
||||
self.nb_api.db_set(
|
||||
'Logical_Router', lr_name,
|
||||
('options', {
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE: redistribute
|
||||
})
|
||||
).execute(check_error=True)
|
||||
|
||||
return router_id, lr_name
|
||||
|
||||
def test_provision_evpn_static_route_redistribution_empty(self):
|
||||
"""Test adding 'static' when redistribute option is empty."""
|
||||
router_id, lr_name = self._create_evpn_router(
|
||||
vni=6000, redistribute='')
|
||||
|
||||
# Verify initial state
|
||||
lr = self.nb_api.lr_get(lr_name).execute(check_error=True)
|
||||
self.assertEqual('', lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
# Run the maintenance task
|
||||
self.assertRaises(
|
||||
periodics.NeverAgain,
|
||||
self.maint.provision_evpn_static_route_redistribution)
|
||||
|
||||
# Verify 'static' was added
|
||||
lr = self.nb_api.lr_get(lr_name).execute(check_error=True)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
def test_provision_evpn_static_route_redistribution_no_routers(self):
|
||||
"""Test when there are no EVPN routers in the system."""
|
||||
# Don't create any EVPN routers
|
||||
|
||||
# Run the maintenance task
|
||||
self.assertRaises(
|
||||
periodics.NeverAgain,
|
||||
self.maint.provision_evpn_static_route_redistribution)
|
||||
|
||||
# Test passes if NeverAgain is raised without errors
|
||||
|
||||
def test_provision_evpn_static_route_redistribution_multiple_routers(self):
|
||||
"""Test updating multiple EVPN routers in one run."""
|
||||
# Create routers with different initial states
|
||||
router1_id, lr1_name = self._create_evpn_router(
|
||||
vni=6004, redistribute='')
|
||||
router2_id, lr2_name = self._create_evpn_router(
|
||||
vni=6005, redistribute='')
|
||||
router3_id, lr3_name = self._create_evpn_router(
|
||||
vni=6006, redistribute='')
|
||||
|
||||
# Run the maintenance task
|
||||
self.assertRaises(
|
||||
periodics.NeverAgain,
|
||||
self.maint.provision_evpn_static_route_redistribution)
|
||||
|
||||
# Verify all routers were updated correctly
|
||||
lr1 = self.nb_api.lr_get(lr1_name).execute(check_error=True)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr1.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
lr2 = self.nb_api.lr_get(lr2_name).execute(check_error=True)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr2.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
lr3 = self.nb_api.lr_get(lr3_name).execute(check_error=True)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr3.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
def test_provision_evpn_static_route_redistribution_idempotent(self):
|
||||
"""Test that setting 'static' when already set doesn't duplicate."""
|
||||
# Create router with 'static' already configured
|
||||
router_id, lr_name = self._create_evpn_router(
|
||||
vni=6007,
|
||||
redistribute=bgp_const.DYNAMIC_ROUTE_TYPE_STATIC)
|
||||
|
||||
# Verify initial state
|
||||
lr = self.nb_api.lr_get(lr_name).execute(check_error=True)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC,
|
||||
lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
# Run the maintenance task
|
||||
self.assertRaises(
|
||||
periodics.NeverAgain,
|
||||
self.maint.provision_evpn_static_route_redistribution)
|
||||
|
||||
# Verify 'static' is still set and not duplicated,
|
||||
# e.g., 'static,static'
|
||||
lr = self.nb_api.lr_get(lr_name).execute(check_error=True)
|
||||
redistribute = lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE)
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, redistribute)
|
||||
|
||||
|
||||
class TestLogMaintenance(_TestMaintenanceHelper,
|
||||
test_log_driver.LogApiTestCaseBase):
|
||||
def test_check_for_logging_conf_change(self):
|
||||
|
||||
+1
-1
@@ -2537,7 +2537,7 @@ class TestOvnNbSyncEVPN(base.TestOVNFunctionalBase):
|
||||
networks=['192.168.99.1/24'],
|
||||
options={
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE:
|
||||
'connected-as-host'}))
|
||||
bgp_const.DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST}))
|
||||
|
||||
self.assertIn(orphan_ls, self._get_ovn_evpn_ls_names())
|
||||
self.assertIn(orphan_hcg, self._get_ovn_evpn_hcg_names())
|
||||
|
||||
@@ -70,6 +70,8 @@ class CreateEVPNRouterCommandTestCase(bgp_base.BaseBgpTestCase):
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING))
|
||||
self.assertEqual(str(self.vni), lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_VRF_ID))
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
self.assertEqual(
|
||||
('vr%s' % self.router_id)[:n_const.DEVICE_NAME_MAX_LEN],
|
||||
lr.options.get(
|
||||
@@ -88,6 +90,8 @@ class CreateEVPNRouterCommandTestCase(bgp_base.BaseBgpTestCase):
|
||||
lr.options.get('existing-key'))
|
||||
self.assertEqual('true', lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING))
|
||||
self.assertEqual(bgp_const.DYNAMIC_ROUTE_TYPE_STATIC, lr.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
def test_creates_dummy_logical_switch(self):
|
||||
self._execute()
|
||||
@@ -329,7 +333,7 @@ class AdvertiseHostCommandTestCase(bgp_base.BaseBgpNbIdlTestCase):
|
||||
|
||||
lrp = self.nb_api.lrp_get(lrp_name).execute(check_error=True)
|
||||
self.assertEqual(
|
||||
'connected-as-host',
|
||||
bgp_const.DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST,
|
||||
lrp.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
@@ -345,7 +349,7 @@ class AdvertiseHostCommandTestCase(bgp_base.BaseBgpNbIdlTestCase):
|
||||
self.assertEqual('existing-value',
|
||||
lrp.options.get('existing-key'))
|
||||
self.assertEqual(
|
||||
'connected-as-host',
|
||||
bgp_const.DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST,
|
||||
lrp.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
|
||||
@@ -360,6 +364,6 @@ class AdvertiseHostCommandTestCase(bgp_base.BaseBgpNbIdlTestCase):
|
||||
|
||||
lrp = self.nb_api.lrp_get(lrp_name).execute(check_error=True)
|
||||
self.assertEqual(
|
||||
'connected-as-host',
|
||||
bgp_const.DYNAMIC_ROUTE_TYPE_CONNECTED_AS_HOST,
|
||||
lrp.options.get(
|
||||
bgp_const.LR_OPTIONS_DYNAMIC_ROUTING_REDISTRIBUTE))
|
||||
Reference in new issue
Block a user