From: Ondrej Lichtner <olichtne(a)redhat.com>
For now throwing an exception when trying to read/write coalescing
settings to a device that doesn't support them is still the best option.
However, there's a need to easily distinguish and ignore this error in
operations that try to access all properties of a Device class instance,
e.g. enable_readonly_cache. In such cases the tester probably doesn't
care that coalescing isn't supported and has no option to skip it for
the cache generation operation leading to the recipe failing with an
exception.
Handling device capabilities dynamically is a larger feature that might
be hard to implement for now so instead a special
DeviceFeatureNotSupported exception class is added that can be safely
ignored when performing these "bulk"/"iterative" operations.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/DeviceError.py | 3 +++
lnst/Devices/Device.py | 11 +++++++----
lnst/Devices/RemoteDevice.py | 8 +++++++-
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/lnst/Common/DeviceError.py b/lnst/Common/DeviceError.py
index c89541e..dc17205 100644
--- a/lnst/Common/DeviceError.py
+++ b/lnst/Common/DeviceError.py
@@ -32,3 +32,6 @@ class DeviceReadOnly(DeviceError):
class DeviceConfigValueError(DeviceConfigError):
pass
+
+class DeviceFeatureNotSupported(DeviceError):
+ pass
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py
index 3984776..e69a297 100644
--- a/lnst/Devices/Device.py
+++ b/lnst/Devices/Device.py
@@ -23,6 +23,7 @@
from lnst.Common.ExecCmd import exec_cmd
from lnst.Common.DeviceError import DeviceError, DeviceDeleted, DeviceDisabled
from lnst.Common.DeviceError import DeviceConfigError, DeviceConfigValueError
+from lnst.Common.DeviceError import DeviceFeatureNotSupported
from lnst.Common.IpAddress import ipaddress
from lnst.Common.HWAddress import hwaddress
@@ -624,8 +625,9 @@ def _read_adaptive_coalescing(self):
try:
res = re.search(regex, res).groups()
except AttributeError:
- raise DeviceError("No values for coalescence of %s." %
- self.name)
+ raise DeviceFeatureNotSupported(
+ "No values for coalescence of %s." % self.name
+ )
return list(res)
def _write_adaptive_coalescing(self, rx_val, tx_val):
@@ -635,8 +637,9 @@ def _write_adaptive_coalescing(self, rx_val, tx_val):
exec_cmd("ethtool -C %s adaptive-rx %s adaptive-tx %s" %
(self.name, rx_val, tx_val))
except:
- raise DeviceConfigError("Not allowed to modify coalescence "
- "settings for %s." % self.name)
+ raise DeviceFeatureNotSupported(
+ "Not allowed to modify coalescence settings for %s." %
self.name
+ )
def restore_coalescing(self):
rx_val = self._cleanup_data["adaptive_rx_coalescing"]
diff --git a/lnst/Devices/RemoteDevice.py b/lnst/Devices/RemoteDevice.py
index 17bc52b..55912ea 100644
--- a/lnst/Devices/RemoteDevice.py
+++ b/lnst/Devices/RemoteDevice.py
@@ -11,9 +11,11 @@
olichtne(a)redhat.com (Ondrej Lichtner)
"""
+import logging
from copy import deepcopy
from lnst.Devices.Device import Device
from lnst.Common.DeviceError import DeviceDeleted, DeviceReadOnly
+from lnst.Common.DeviceError import DeviceFeatureNotSupported
def remotedev_decorator(cls):
def func(*args, **kwargs):
@@ -150,7 +152,11 @@ def __iter__(self):
attr = getattr(self._dev_cls, x)
if not callable(attr):
- yield (x, getattr(self, x))
+ try:
+ yield (x, getattr(self, x))
+ except DeviceFeatureNotSupported as e:
+ logging.debug(str(e))
+ continue
def _match_update_data(self, data):
return False
--
2.23.0
Show replies by date