Rodolfo Alonso Hernandez 6eaa6d83d7 Randomize segmentation ID assignation
If plugin "network_segment_range" is not enabled and a new segment
is required, if no segmentation ID is provided in the request, the
segmentation ID assigned is randomly retrieved from the non
allocated segmentation IDs.

The goal is to improve the concurrent network (and segment) creation.
If several segments are created in parallel, this random query
will return a different segmentation ID to each one, avoiding the
database retry request.

Closes-Bug: #1920923

Change-Id: Id3f71611a00e69c4f22340ca4d05d95e4373cf69
2021-03-24 13:56:09 +00:00

35 lines
1.2 KiB
Python

# Copyright (c) 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class SegmentAllocationDbObjTestCase(object):
def test_get_random_unallocated_segment(self):
self.assertIsNone(
self._test_class.get_random_unallocated_segment(self.context))
obj = self.objs[0]
obj.allocated = True
obj.create()
self.assertIsNone(
self._test_class.get_random_unallocated_segment(self.context))
obj = self.objs[1]
obj.allocated = False
obj.create()
allocations = self._test_class.get_random_unallocated_segment(
self.context)
self.assertEqual(obj.segmentation_id, allocations.segmentation_id)