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()