Skip to content

Commit

Permalink
Fix error RequestURITooLong in full sync. (#278)
Browse files Browse the repository at this point in the history
* Fix error RequestURITooLong in full sync.

* Fix pylint
  • Loading branch information
velp authored Sep 6, 2024
1 parent 77f3d97 commit a4bba37
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions octavia_f5/network/drivers/neutron/neutron_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])}
Expand Down

0 comments on commit a4bba37

Please sign in to comment.