On Thu, Aug 06, 2015 at 02:45:30PM +0200, Jan Tluka wrote:
Method get_devices_by_params can be used for more variable queries
for
example query by both driver name and hardware address. Basically
everything that provides Device::get_if_data(). Method has one parameter
params that is a dictionary of queried parameter key-values.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Slave/NetTestSlave.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index a725a62..0c9e627 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -154,6 +154,21 @@ class SlaveMethods:
return matched
+ def get_devices_by_params(self, params):
+ devices = self._if_manager.get_devices()
+ matched = []
+ for dev in devices:
+ dev_data = dev.get_if_data()
+ for key, value in params.iteritems():
+ if dev_data[key] != value:
^^^
what if 'key' is undefined in dev_data... that
will raise an Exception
+ break
+
+ entry = {"name": dev.get_name(),
+ "hwaddr": dev.get_hwaddr()}
+ matched.append(entry)
^^^^^
This is still in the second for loop -> each time a parameter passes you
add the device to matched, and then if one fails you decide to skip the
rest of the parameters, but the device is already in the "matched"
list... I'm thinking this isn't what you wanted to do.
+
+ return matched
+
def get_if_data(self, if_id):
dev = self._if_manager.get_mapped_device(if_id)
if dev is None:
--
2.1.0
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers