[dts] [PATCH 5/6] framework: Fix ifname not found error
Michael Qiu
michael.qiu at intel.com
Tue Jan 13 14:42:19 CET 2015
Currently, DTS try to get ifname by the file name below the dir:
/sys/bus/pci/devices/xxxx:xx:xx.x/net
But if the device driver has been unbind or not loaded successful,
kernel will not create that entry, so the ifname will not exist.
This will cause DTS failure.
Check that entry to avoid this issue.
Signed-off-by: Michael Qiu <michael.qiu at intel.com>
---
framework/crb.py | 21 +++++++++++++++------
framework/dut.py | 10 ++++++++++
framework/tester.py | 2 +-
3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/framework/crb.py b/framework/crb.py
index aca62c1..ee005c4 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -55,7 +55,8 @@ class Crb(object):
self.serializer = serializer
self.ports_info = None
- def send_expect(self, cmds, expected, timeout=TIMEOUT, alt_session=False):
+ def send_expect(self, cmds, expected, timeout=TIMEOUT,
+ alt_session=False, verify = False):
"""
Send commands to crb and return string before expected string. If
there's no expected string found before timeout, TimeoutException will
@@ -63,9 +64,10 @@ class Crb(object):
"""
if alt_session:
- return self.alt_session.session.send_expect(cmds, expected, timeout)
+ return self.alt_session.session.send_expect(cmds, expected,
+ timeout, verify)
- return self.session.send_expect(cmds, expected, timeout)
+ return self.session.send_expect(cmds, expected, timeout, verify)
def set_test_types(self, func_tests, perf_tests):
"""
@@ -166,7 +168,9 @@ class Crb(object):
addr_array = pci_bus.split(':')
itf = self.get_interface_name(addr_array[0], addr_array[1])
- self.send_expect("ifconfig %s up" % itf, "# ")
+ # In case the device driver has already been unbind
+ if itf:
+ self.send_expect("ifconfig %s up" % itf, "# ")
except Exception as e:
self.logger.error(" !!! Restore ITF: " + e.message)
@@ -226,8 +230,13 @@ class Crb(object):
"""
Get interface name of specified pci device on linux.
"""
- command = 'ls /sys/bus/pci/devices/0000:%s:%s/net' % (bus_id, devfun_id)
- return self.send_expect(command, '# ')
+ ifname_path = '/sys/bus/pci/devices/0000:%s:%s/net' % (bus_id, devfun_id)
+ # In case the device driver has already been unbind
+ ret = self.send_expect("ls %s"% ifname_path, '# ', verify=True)
+ if ret == -1:
+ return None
+ else:
+ return ret
def get_interface_name_freebsd(self, bus_id, devfun_id):
"""
diff --git a/framework/dut.py b/framework/dut.py
index d7099ef..96b8bd6 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -424,6 +424,11 @@ class Dut(Crb):
if pci_id == '8086:10fb':
self.send_expect("echo 0000:%s > /sys/bus/pci/drivers/ixgbe/bind" % pci_bus, "# ")
intf = self.get_interface_name(bus_id, devfun_id)
+ # Skip undrived pci Eth device
+ if not intf:
+ self.logger.info("DUT: [000:%s %s] %s" % (pci_bus, pci_id,
+ skipped))
+ continue
out = self.send_expect("ip link show %s" % intf, "# ")
if "DOWN" in out:
@@ -478,6 +483,11 @@ class Dut(Crb):
continue
intf = self.get_interface_name(pci_bus)
+ # Skip undrived pci devices
+ if not intf:
+ self.logger.info("DUT: [%s %s] %s" % (pci_bus, pci_id,
+ skipped))
+ continue
macaddr = self.get_mac_addr(intf)
ipv6 = self.get_ipv6_addr(intf)
diff --git a/framework/tester.py b/framework/tester.py
index 0ebe29a..40f9344 100644
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -213,7 +213,7 @@ class Tester(Crb):
intf = self.get_interface_name(bus_id, devfun_id)
- if "No such file" in intf:
+ if not intf:
self.logger.info("Tester: [000:%s %s] %s" % (pci_bus, pci_id,
"unknow_interface"))
continue
--
1.9.3
More information about the dts
mailing list