From b7b7a3147222e4aa397b5bcbdde70eaf1a261bb0 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Mon, 25 Nov 2024 16:19:20 +0000 Subject: [PATCH] Add a detailed debug message in case of segment allocation fail Added an extra detailed message in case of error in the partial segment allocation fail. This message should not be present in production. This message should help in the debugging of the related bug. Related-Bug: #2086602 Change-Id: I49b6e5f3be86c19e0a9e657ee6fe5f61c3b81bb3 --- neutron/objects/plugins/ml2/base.py | 9 +++++++++ neutron/plugins/ml2/drivers/helpers.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/neutron/objects/plugins/ml2/base.py b/neutron/objects/plugins/ml2/base.py index 8046811b63c..12dc3f44eca 100644 --- a/neutron/objects/plugins/ml2/base.py +++ b/neutron/objects/plugins/ml2/base.py @@ -55,6 +55,15 @@ class SegmentAllocation(metaclass=abc.ABCMeta): query = query.order_by(rand_func()) return query.first() + @classmethod + def get_all_unallocated_segments(cls, context, **filters): + with cls.db_context_reader(context): + columns = set(dict(cls.db_model.__table__.columns)) + model_filters = {k: filters[k] + for k in columns & set(filters.keys())} + return context.session.query(cls.db_model).filter_by( + allocated=False, **model_filters).all() + @classmethod def allocate(cls, context, **segment): with cls.db_context_writer(context): diff --git a/neutron/plugins/ml2/drivers/helpers.py b/neutron/plugins/ml2/drivers/helpers.py index 276665f8e1b..e35615e0018 100644 --- a/neutron/plugins/ml2/drivers/helpers.py +++ b/neutron/plugins/ml2/drivers/helpers.py @@ -156,6 +156,22 @@ class SegmentTypeDriver(BaseTypeDriver): raise db_exc.RetryRequest( exceptions.NoNetworkFoundInMaximumAllowedAttempts()) + # NOTE(ralonsoh): this debug message is added to debug LP#2086602. + # Once fixed, it won't be needed. This debug message should not be + # released. + LOG.debug('Partial segment allocation fail:') + LOG.debug(' - Filters: %s', filters) + LOG.debug(' - Non allocated segments:') + for non_allocated_segment in ( + self.segmentation_obj.get_all_unallocated_segments(context, + **filters)): + LOG.debug(' - %s', non_allocated_segment) + if directory.get_plugin(plugin_constants.NETWORK_SEGMENT_RANGE): + LOG.debug(' - Network segment ranges:') + for srange in ns_range.NetworkSegmentRange.get_objects( + context.elevated()): + LOG.debug(' - %s', srange) + @db_api.retry_db_errors def _delete_expired_default_network_segment_ranges(self): ctx = context.get_admin_context()