VOL-601 check for KEY before dereference
Change-Id: I6da1d6f36015acdb2743da77b01091a1d6e224c0
diff --git a/common/utils/nethelpers.py b/common/utils/nethelpers.py
index a4610a2..b17aced 100644
--- a/common/utils/nethelpers.py
+++ b/common/utils/nethelpers.py
@@ -48,11 +48,13 @@
return _get_my_primary_local_ipv4(ifname)
# My IP should belong to the specified subnet
for iface in ni.interfaces():
- m_ip = ni.ifaddresses(iface)[AF_INET][0]['addr']
- _ip = netaddr.IPAddress(m_ip).value
- m_network = netaddr.IPNetwork(inter_core_subnet)
- if _ip >= m_network.first and _ip <= m_network.last:
- return m_ip
+ addresses = ni.ifaddresses(iface)
+ if AF_INET in addresses:
+ m_ip = addresses[AF_INET][0]['addr']
+ _ip = netaddr.IPAddress(m_ip).value
+ m_network = netaddr.IPNetwork(inter_core_subnet)
+ if _ip >= m_network.first and _ip <= m_network.last:
+ return m_ip
return None
@@ -61,11 +63,13 @@
return _get_my_primary_interface()
# My interface should have an IP that belongs to the specified subnet
for iface in ni.interfaces():
- m_ip = ni.ifaddresses(iface)[AF_INET][0]['addr']
- m_ip = netaddr.IPAddress(m_ip).value
- m_network = netaddr.IPNetwork(pon_subnet)
- if m_ip >= m_network.first and m_ip <= m_network.last:
- return iface
+ addresses = ni.ifaddresses(iface)
+ if AF_INET in addresses:
+ m_ip = addresses[AF_INET][0]['addr']
+ m_ip = netaddr.IPAddress(m_ip).value
+ m_network = netaddr.IPNetwork(pon_subnet)
+ if m_ip >= m_network.first and m_ip <= m_network.last:
+ return iface
return None