Browse Source

Merge "Use dict .get() to avoid a KeyError in the segment plugin" into stable/rocky

changes/00/750400/1
Zuul 3 weeks ago
committed by Gerrit Code Review
parent
commit
2bcbd947b3
2 changed files with 15 additions and 12 deletions
  1. +13
    -10
      neutron/services/segments/plugin.py
  2. +2
    -2
      neutron/tests/unit/extensions/test_segment.py

+ 13
- 10
neutron/services/segments/plugin.py View File

@@ -260,10 +260,10 @@ class NovaSegmentNotifier(object):
total += int(netaddr.IPAddress(pool['end']) -
netaddr.IPAddress(pool['start'])) + 1
if total:
if subnet['gateway_ip']:
if subnet.get('gateway_ip'):
total += 1
reserved += 1
if subnet['enable_dhcp']:
if subnet.get('enable_dhcp'):
reserved += 1
return total, reserved

@@ -560,7 +560,7 @@ class SegmentHostRoutes(object):
context=context,
ip_version=netaddr.IPNetwork(subnet['cidr']).version,
network_id=subnet['network_id'],
segment_id=subnet['segment_id'],
segment_id=segment_id,
host_routes=copy.deepcopy(host_routes),
gateway_ip=gateway_ip)
if (not host_routes or
@@ -572,11 +572,14 @@ class SegmentHostRoutes(object):
def host_routes_before_update(self, resource, event, trigger, **kwargs):
context = kwargs['context']
subnet, original_subnet = kwargs['request'], kwargs['original_subnet']
segment_id = subnet.get('segment_id', original_subnet['segment_id'])
gateway_ip = subnet.get('gateway_ip', original_subnet['gateway_ip'])
host_routes = subnet.get('host_routes', original_subnet['host_routes'])
if (segment_id and (host_routes != original_subnet['host_routes'] or
gateway_ip != original_subnet['gateway_ip'])):
orig_segment_id = original_subnet.get('segment_id')
segment_id = subnet.get('segment_id', orig_segment_id)
orig_gateway_ip = original_subnet.get('gateway_ip')
gateway_ip = subnet.get('gateway_ip', orig_gateway_ip)
orig_host_routes = original_subnet.get('host_routes')
host_routes = subnet.get('host_routes', orig_host_routes)
if (segment_id and (host_routes != orig_host_routes or
gateway_ip != orig_gateway_ip)):
calc_host_routes = self._calculate_routed_network_host_routes(
context=context,
ip_version=netaddr.IPNetwork(original_subnet['cidr']).version,
@@ -584,8 +587,8 @@ class SegmentHostRoutes(object):
segment_id=segment_id,
host_routes=copy.deepcopy(host_routes),
gateway_ip=gateway_ip,
old_gateway_ip=original_subnet['gateway_ip'] if (
gateway_ip != original_subnet['gateway_ip']) else None)
old_gateway_ip=orig_gateway_ip if (
gateway_ip != orig_gateway_ip) else None)
if self._host_routes_need_update(host_routes, calc_host_routes):
subnet['host_routes'] = calc_host_routes



+ 2
- 2
neutron/tests/unit/extensions/test_segment.py View File

@@ -1701,10 +1701,10 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
total += int(netaddr.IPAddress(pool['end']) -
netaddr.IPAddress(pool['start'])) + 1
if total:
if subnet['gateway_ip']:
if subnet.get('gateway_ip'):
total += 1
reserved += 1
if subnet['enable_dhcp']:
if subnet.get('enable_dhcp'):
reserved += 1
return total, reserved



Loading…
Cancel
Save