Browse Source

Use dict .get() to avoid a KeyError in the segment plugin

On subnet delete, the supplied subnet in the post hook
could contain a subnet without certain items, leading to
a KeyError in the segment plugin.  Fix a number of these
occurences so this cannot happen.

Also fixed similar code in the segment tests.

Conflicts:
    neutron/services/segments/plugin.py

Change-Id: I645610febde446b78ed6edd868e699673648a4de
Closes-bug: #1868724
(cherry picked from commit 07b015d789)
(cherry picked from commit b019821abd)
changes/49/749949/1
Brian Haley 6 months ago
committed by Slawek Kaplonski
parent
commit
45f5635606
2 changed files with 4 additions and 4 deletions
  1. +2
    -2
      neutron/services/segments/plugin.py
  2. +2
    -2
      neutron/tests/unit/extensions/test_segment.py

+ 2
- 2
neutron/services/segments/plugin.py View File

@@ -236,10 +236,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



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

@@ -1545,10 +1545,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