From: Christos Sfakianakis <csfakian(a)redhat.com>
The intented dictionary that shall contain interface data
depends on "this" instance's data exclusively, with the exception
of 'master', for which another device is possibly referenced. For
the latter case, avoid errors if the referenced device does not
exist any more. For all other keys, return an empty dictionary if
the device is already deleted, otherwise proceed as previously.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Devices/Device.py | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py
index 3037f45..bd47c11 100644
--- a/lnst/Devices/Device.py
+++ b/lnst/Devices/Device.py
@@ -21,7 +21,7 @@ from pyroute2.netlink.rtnl import ifinfmsg
from lnst.Common.Logs import log_exc_traceback
from lnst.Common.NetUtils import normalize_hwaddr
from lnst.Common.ExecCmd import exec_cmd
-from lnst.Common.DeviceError import DeviceError, DeviceDeleted, DeviceDisabled
+from lnst.Common.DeviceError import DeviceError, DeviceDeleted, DeviceDisabled,
DeviceNotFound
from lnst.Common.DeviceError import DeviceConfigError, DeviceConfigValueError
from lnst.Common.IpAddress import ipaddress
from lnst.Common.HWAddress import hwaddress
@@ -206,16 +206,25 @@ class Device(object):
self._ip_addrs.remove(addr)
def _get_if_data(self):
- if_data = {"ifindex": self.ifindex,
- "hwaddr": self.hwaddr,
- "name": self.name,
- "ip_addrs": self.ips,
- "link_header_type": self.link_header_type,
- "state": self.state,
- "master": self.master,
- "mtu": self.mtu,
- "driver": self.driver,
- "devlink": self._devlink}
+ try:
+ master = self.master
+ except DeviceNotFound:
+ master = None
+
+ try:
+ if_data = {"ifindex": self.ifindex,
+ "hwaddr": self.hwaddr,
+ "name": self.name,
+ "ip_addrs": self.ips,
+ "link_header_type": self.link_header_type,
+ "state": self.state,
+ "master": master,
+ "mtu": self.mtu,
+ "driver": self.driver,
+ "devlink": self._devlink}
+ except DeviceDeleted:
+ return {}
+
try:
ad_rx_coal, ad_tx_coal = self._read_adaptive_coalescing()
except DeviceError:
--
2.17.1