[V1] framework/dut: optimize scripts

Message ID 20230714152304.1129546-1-songx.jiale@intel.com (mailing list archive)
State New
Headers
Series [V1] framework/dut: optimize scripts |

Checks

Context Check Description
ci/Intel-dts-format-test success Testing OK
ci/Intel-dts-pylama-test success Testing OK
ci/Intel-dts-suite-test success Testing OK

Commit Message

Jiale Song July 14, 2023, 3:23 p.m. UTC
  1. delete unnecessary waiting time. the iavf driver does not need to
execute a separate wait, which is invalid and only increases the invalid
waiting time.
2. when the NIC name is N/A or empty, the name cannot be changed no
matter how long it is waiting. after obtaining N/A, it is necessary to
rebind the driver of the NIC.

Signed-off-by: Jiale Song <songx.jiale@intel.com>
---
 framework/dut.py | 48 +++++++++++++++---------------------------------
 1 file changed, 15 insertions(+), 33 deletions(-)
  

Patch

diff --git a/framework/dut.py b/framework/dut.py
index 0adb2786..61ef2839 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -416,50 +416,32 @@  class Dut(Crb):
 
                 port = GetNicObj(self, domain_id, bus_id, devfun_id)
 
-                self.send_expect(
-                    "echo %s > /sys/bus/pci/devices/%s\:%s\:%s/driver/unbind"
-                    % (pci_bus, domain_id, bus_id, devfun_id),
-                    "# ",
-                    timeout=30,
-                )
-                # bind to linux kernel driver
-                if not self.is_container:
-                    self.send_expect("modprobe %s" % driver, "# ", timeout=30)
-                self.send_expect(
-                    "echo %s > /sys/bus/pci/drivers/%s/bind" % (pci_bus, driver),
-                    "# ",
-                    timeout=30,
-                )
                 pull_retries = 5
                 itf = "N/A"
                 while pull_retries > 0:
+                    self.send_expect(
+                        "echo %s > /sys/bus/pci/devices/%s\:%s\:%s/driver/unbind"
+                        % (pci_bus, domain_id, bus_id, devfun_id),
+                        "# ",
+                        timeout=30,
+                    )
+                    # bind to linux kernel driver
+                    if not self.is_container:
+                        self.send_expect("modprobe %s" % driver, "# ", timeout=30)
+                    self.send_expect(
+                        "echo %s > /sys/bus/pci/drivers/%s/bind" % (pci_bus, driver),
+                        "# ",
+                        timeout=30,
+                    )
+                    time.sleep(1)
                     if port_info["port_id"] == 1:
                         itf = port.get_interface_name()
                     else:
                         itf = port.get_interface2_name()
                     if not itf or itf == "N/A":
-                        time.sleep(1)
                         pull_retries -= 1
                     else:
                         break
-                else:
-                    # try to bind nic with iavf
-                    if driver == "iavf":
-                        self.send_expect("modprobe %s" % driver, "# ")
-                        self.send_expect(
-                            "echo %s > /sys/bus/pci/drivers/%s/bind"
-                            % (pci_bus, driver),
-                            "# ",
-                        )
-                        pull_retries = 5
-                        itf = "N/A"
-                        while pull_retries > 0:
-                            itf = port.get_interface_name()
-                            if not itf or itf == "N/A":
-                                time.sleep(1)
-                                pull_retries -= 1
-                            else:
-                                break
                 if itf == "N/A":
                     self.logger.warning("Fail to bind the device with the linux driver")
                 else: