From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit introduces two fixes for handling situations when a Device
gets deleted. First is a small workaround for double removal of a
deleted device from the tracking dictionary. The second is an Exception
handling for calling an update on a Device object referring to a device
that is already marked as deleted. This can sometimes happen when
netlink messages get reordered so it's important to handle the
exception.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Slave/InterfaceManager.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py
index 721434a..3801bdb 100644
--- a/lnst/Slave/InterfaceManager.py
+++ b/lnst/Slave/InterfaceManager.py
@@ -21,7 +21,7 @@ from lnst.Common.NetUtils import normalize_hwaddr
from lnst.Common.NetUtils import scan_netdevs
from lnst.Common.ExecCmd import exec_cmd
from lnst.Common.ConnectionHandler import recv_data
-from lnst.Common.DeviceError import DeviceNotFound, DeviceConfigError
+from lnst.Common.DeviceError import DeviceNotFound, DeviceConfigError, DeviceDeleted
from lnst.Common.InterfaceManagerError import InterfaceManagerError
from lnst.Slave.DevlinkManager import DevlinkManager
from pyroute2 import IPRSocket
@@ -123,6 +123,12 @@ class InterfaceManager(object):
for addr_msg in dev['ip_addrs']:
self._devices[dev['index']]._update_netlink(addr_msg)
for i in devices_to_remove:
+ if i not in self._devices:
+ #TODO
+ #this is a workaround fix for when the device to remove was
+ #already removed indirectly by the previous update loop
+ #the fix works for now but should be refactored at some point
+ continue
dev_name = self._devices[i].name
logging.debug("Deleting Device with ifindex %d, name %s because "\
"it doesn't exist anymore." % (i, dev_name))
@@ -153,7 +159,10 @@ class InterfaceManager(object):
def _handle_netlink_msg(self, msg):
if msg['header']['type'] in [RTM_NEWLINK, RTM_NEWADDR,
RTM_DELADDR]:
if msg['index'] in self._devices:
- self._devices[msg['index']]._update_netlink(msg)
+ try:
+ self._devices[msg['index']]._update_netlink(msg)
+ except DeviceDeleted:
+ return
elif msg['header']['type'] == RTM_NEWLINK:
dev = self._device_classes["Device"](self)
dev._init_netlink(msg)
--
2.17.0