From a4bba37b843c9b76c38f5c85000f352925d4c648 Mon Sep 17 00:00:00 2001 From: Vadim Ponomarev Date: Fri, 6 Sep 2024 10:22:02 +0200 Subject: [PATCH] Fix error RequestURITooLong in full sync. (#278) * Fix error RequestURITooLong in full sync. * Fix pylint --- .../network/drivers/neutron/neutron_client.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/octavia_f5/network/drivers/neutron/neutron_client.py b/octavia_f5/network/drivers/neutron/neutron_client.py index 1bcf64f6..8de5ffe8 100644 --- a/octavia_f5/network/drivers/neutron/neutron_client.py +++ b/octavia_f5/network/drivers/neutron/neutron_client.py @@ -348,6 +348,10 @@ def _get_f5_hostnames(self, host: str) -> [str]: raise Exception(f"Hostname not found for host {host}") + def _get_subnets_chunks(self, subnets: list, max_size: int = 100): + for i in range(0, len(subnets), max_size): + yield subnets[i:i + max_size] + @tenacity.retry( retry=tenacity.retry_if_exception_type( (neutron_client_exceptions.Conflict, @@ -396,14 +400,17 @@ def ensure_selfips(self, load_balancers: [octavia_models.LoadBalancer], else: hosts_id = [agent] - all_subnets = set(lb.vip.subnet_id for lb in load_balancers) + all_subnets = list(set(lb.vip.subnet_id for lb in load_balancers)) needed_subnets = set(lb.vip.subnet_id for lb in load_balancers if lb.provisioning_status != lib_consts.PENDING_DELETE) - filter = {'device_owner': [constants.DEVICE_OWNER_SELFIP, - constants.DEVICE_OWNER_LEGACY], - 'binding:host_id': hosts_id, - 'fixed_ips': [f'subnet_id={subnet}' for subnet in all_subnets]} - selfips = self.neutron_client.list_ports(**filter).get('ports', []) + subnets_in_chunks = list(self._get_subnets_chunks(all_subnets)) + selfips = [] + for chunk in subnets_in_chunks: + filter = {'device_owner': [constants.DEVICE_OWNER_SELFIP, + constants.DEVICE_OWNER_LEGACY], + 'binding:host_id': hosts_id, + 'fixed_ips': [f'subnet_id={subnet}' for subnet in chunk]} + selfips += self.neutron_client.list_ports(**filter).get('ports', []) # For every subnet and f5host, we expect a selfip f5hosts = {host: set() for host in self._get_f5_hostnames(hosts_id[0])}