CSIT-1043: Execute pci rescan only if needed 61/12961/10
authorjuraj.linkes <juraj.linkes@pantheon.tech>
Fri, 8 Jun 2018 08:47:27 +0000 (10:47 +0200)
committerTibor Frank <tifrank@cisco.com>
Fri, 22 Jun 2018 08:42:28 +0000 (08:42 +0000)
Pci rescan is a rather invasive process, which is why it should be
executed only if needed. This patch moves the pci rescan after
pci device driver discovery, rescanning the devices for further attemps
at driver discovery.

Change-Id: I29c939b44c3f67371416a99c711e057f711ba9b4
Signed-off-by: juraj.linkes <juraj.linkes@pantheon.tech>
resources/libraries/python/DUTSetup.py
resources/libraries/python/InterfaceUtil.py

index d08704b..5e07ee0 100644 (file)
@@ -385,24 +385,31 @@ class DUTSetup(object):
     def get_pci_dev_driver(node, pci_addr):
         """Get current PCI device driver on node.
 
+        .. note::
+            # lspci -vmmks 0000:00:05.0
+            Slot:   00:05.0
+            Class:  Ethernet controller
+            Vendor: Red Hat, Inc
+            Device: Virtio network device
+            SVendor:        Red Hat, Inc
+            SDevice:        Device 0001
+            PhySlot:        5
+            Driver: virtio-pci
+
         :param node: DUT node.
         :param pci_addr: PCI device address.
         :type node: dict
         :type pci_addr: str
         :returns: Driver or None
         :raises RuntimeError: If PCI rescan or lspci command execution failed.
+        :raises RuntimeError: If it is not possible to get the interface driver
+            information from the node.
         """
         ssh = SSH()
         ssh.connect(node)
 
         for i in range(3):
-            logger.trace('Try {0}: Get interface driver'.format(i))
-            cmd = 'sh -c "echo 1 > /sys/bus/pci/rescan"'
-            ret_code, _, _ = ssh.exec_command_sudo(cmd)
-            if int(ret_code) != 0:
-                raise RuntimeError("'{0}' failed on '{1}'"
-                                   .format(cmd, node['host']))
-
+            logger.trace('Try number {0}: Get PCI device driver'.format(i))
             cmd = 'lspci -vmmks {0}'.format(pci_addr)
             ret_code, stdout, _ = ssh.exec_command(cmd)
             if int(ret_code) != 0:
@@ -421,6 +428,16 @@ class DUTSetup(object):
                         return None
                 if name == 'Driver:':
                     return value
+
+            if i < 2:
+                logger.trace('Driver for PCI device {} not found, executing '
+                             'pci rescan and retrying'.format(pci_addr))
+                cmd = 'sh -c "echo 1 > /sys/bus/pci/rescan"'
+                ret_code, _, _ = ssh.exec_command_sudo(cmd)
+                if int(ret_code) != 0:
+                    raise RuntimeError("'{0}' failed on '{1}'"
+                                       .format(cmd, node['host']))
+
         return None
 
     @staticmethod
index 25540dc..5e3c4c4 100644 (file)
@@ -19,6 +19,7 @@ from robot.api import logger
 
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.IPUtil import convert_ipv4_netmask_prefix
+from resources.libraries.python.DUTSetup import DUTSetup
 from resources.libraries.python.ssh import exec_cmd_no_error
 from resources.libraries.python.topology import NodeType, Topology
 from resources.libraries.python.VatExecutor import VatExecutor, VatTerminal
@@ -353,51 +354,9 @@ class InterfaceUtil(object):
         :type pci_addr: str
         :returns: Interface driver or None if not found.
         :rtype: str
-        :raises RuntimeError: If it is not possible to get the interface driver
-            information from the node.
-
-        .. note::
-            # lspci -vmmks 0000:00:05.0
-            Slot:   00:05.0
-            Class:  Ethernet controller
-            Vendor: Red Hat, Inc
-            Device: Virtio network device
-            SVendor:        Red Hat, Inc
-            SDevice:        Device 0001
-            PhySlot:        5
-            Driver: virtio-pci
+        :raises RuntimeError: If PCI rescan or lspci command execution failed.
         """
-        ssh = SSH()
-        ssh.connect(node)
-
-        for i in range(3):
-            logger.trace('Try {}: Get interface driver'.format(i))
-            cmd = 'sh -c "echo 1 > /sys/bus/pci/rescan"'
-            (ret_code, _, _) = ssh.exec_command_sudo(cmd)
-            if int(ret_code) != 0:
-                raise RuntimeError("'{0}' failed on '{1}'"
-                                   .format(cmd, node['host']))
-
-            cmd = 'lspci -vmmks {0}'.format(pci_addr)
-            (ret_code, stdout, _) = ssh.exec_command(cmd)
-            if int(ret_code) != 0:
-                raise RuntimeError("'{0}' failed on '{1}'"
-                                   .format(cmd, node['host']))
-
-            for line in stdout.splitlines():
-                if len(line) == 0:
-                    continue
-                try:
-                    (name, value) = line.split("\t", 1)
-                except ValueError:
-                    if name != "Driver:":
-                        pass
-                    else:
-                        return None
-                if name == 'Driver:':
-                    return value if value else None
-        raise RuntimeError('Get interface driver for: {0}'
-                           .format(pci_addr))
+        return DUTSetup.get_pci_dev_driver(node, pci_addr)
 
     @staticmethod
     def tg_set_interfaces_udev_rules(node):

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.