From 00998f680cd758b3260c873765f335a6379479ca Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Sat, 23 Jun 2018 04:52:15 +0800 Subject: [PATCH] Reduce IP address collision during port creating Try to give it a large random chance during generate IP address. The DB retry mechanism change moved to neutron-lib: I5ad139bdfb3ae125658b36d05f85f139a1b47bee Closes-Bug: #1777968 Change-Id: I2acc9c720b39271bde2a89da4a66958f7aba5b7d (cherry picked from commit ec5cd0d1b85d56adef836bf1167287993ec35ca6) --- neutron/ipam/drivers/neutrondb_ipam/driver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neutron/ipam/drivers/neutrondb_ipam/driver.py b/neutron/ipam/drivers/neutrondb_ipam/driver.py index 02fdb2ab570..93caa13111b 100644 --- a/neutron/ipam/drivers/neutrondb_ipam/driver.py +++ b/neutron/ipam/drivers/neutrondb_ipam/driver.py @@ -167,10 +167,11 @@ class NeutronDbSubnet(ipam_base.Subnet): window = 1 else: # Compute a value for the selection window - window = min(av_set.size, 10) + window = min(av_set.size, 30) ip_index = random.randint(1, window) candidate_ips = list(itertools.islice(av_set, ip_index)) - allocated_ip = candidate_ips[-1] + allocated_ip = candidate_ips[ + random.randint(0, len(candidate_ips) - 1)] return str(allocated_ip), ip_pool.id raise ipam_exc.IpAddressGenerationFailure(