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 commit07b015d789
) (cherry picked from commitb019821abd
)
This commit is contained in:
parent
84562fc892
commit
45f5635606
|
@ -236,10 +236,10 @@ class NovaSegmentNotifier(object):
|
||||||
total += int(netaddr.IPAddress(pool['end']) -
|
total += int(netaddr.IPAddress(pool['end']) -
|
||||||
netaddr.IPAddress(pool['start'])) + 1
|
netaddr.IPAddress(pool['start'])) + 1
|
||||||
if total:
|
if total:
|
||||||
if subnet['gateway_ip']:
|
if subnet.get('gateway_ip'):
|
||||||
total += 1
|
total += 1
|
||||||
reserved += 1
|
reserved += 1
|
||||||
if subnet['enable_dhcp']:
|
if subnet.get('enable_dhcp'):
|
||||||
reserved += 1
|
reserved += 1
|
||||||
return total, reserved
|
return total, reserved
|
||||||
|
|
||||||
|
|
|
@ -1545,10 +1545,10 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||||
total += int(netaddr.IPAddress(pool['end']) -
|
total += int(netaddr.IPAddress(pool['end']) -
|
||||||
netaddr.IPAddress(pool['start'])) + 1
|
netaddr.IPAddress(pool['start'])) + 1
|
||||||
if total:
|
if total:
|
||||||
if subnet['gateway_ip']:
|
if subnet.get('gateway_ip'):
|
||||||
total += 1
|
total += 1
|
||||||
reserved += 1
|
reserved += 1
|
||||||
if subnet['enable_dhcp']:
|
if subnet.get('enable_dhcp'):
|
||||||
reserved += 1
|
reserved += 1
|
||||||
return total, reserved
|
return total, reserved
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue