File 0001-Choose-random-value-for-HA-routes-vr_id.patch of Package openstack-neutron

Index: neutron-9.4.2.dev21/neutron/db/l3_hamode_db.py
===================================================================
--- neutron-9.4.2.dev21.orig/neutron/db/l3_hamode_db.py
+++ neutron-9.4.2.dev21/neutron/db/l3_hamode_db.py
@@ -14,6 +14,7 @@
 #
 
 import functools
+import random
 
 import netaddr
 from neutron_lib.api import validators
@@ -206,6 +207,16 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NA
 
         return allocated_vr_ids
 
+    def _get_vr_id(self, context, network_id):
+        allocated_vr_ids = self._get_allocated_vr_id(context,
+                                                     network_id)
+        available_vr_ids = VR_ID_RANGE - allocated_vr_ids
+
+        if not available_vr_ids:
+            return None
+
+        return random.choice(list(available_vr_ids))
+
     @db_api.retry_if_session_inactive()
     def _ensure_vr_id(self, context, router_db, ha_network):
         router_id = router_db.id
@@ -226,16 +237,13 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NA
                              'ha_vr_id': router_db.extra_attributes.ha_vr_id})
                         return
 
-                    allocated_vr_ids = self._get_allocated_vr_id(context,
-                                                                 network_id)
-                    available_vr_ids = VR_ID_RANGE - allocated_vr_ids
-
-                    if not available_vr_ids:
+                    vr_id = self._get_vr_id(context, network_id)
+                    if vr_id is None:
                         raise l3_ha.NoVRIDAvailable(router_id=router_id)
 
                     allocation = L3HARouterVRIdAllocation()
                     allocation.network_id = network_id
-                    allocation.vr_id = available_vr_ids.pop()
+                    allocation.vr_id = vr_id
 
                     context.session.add(allocation)
                     router_db.extra_attributes.ha_vr_id = allocation.vr_id
openSUSE Build Service is sponsored by