add the expected prompt for ubuntu root user
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 25540dc..7286633 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
@@ -67,9 +68,9 @@ class InterfaceUtil(object):
 
         if node['type'] == NodeType.DUT:
             if state == 'up':
-                state = 'admin-up'
+                state = 'admin-up link-up'
             elif state == 'down':
-                state = 'admin-down'
+                state = 'admin-down link-down'
             else:
                 raise ValueError('Unexpected interface state: {}'.format(state))
             VatExecutor.cmd_from_template(node, 'set_if_state.vat',
@@ -122,7 +123,54 @@ class InterfaceUtil(object):
             InterfaceUtil.set_interface_ethernet_mtu(node, ifc, 1500)
 
     @staticmethod
-    def vpp_node_interfaces_ready_wait(node, timeout=10):
+    def vpp_set_interface_mtu(node, interface, mtu=9200):
+        """Set Ethernet MTU on interface.
+
+        :param node: VPP node.
+        :param interface: Interface to setup MTU. Default: 9200.
+        :param mtu: Ethernet MTU size in Bytes.
+        :type node: dict
+        :type interface: str or int
+        :type mtu: int
+        """
+        if isinstance(interface, basestring):
+            sw_if_index = Topology.get_interface_sw_index(node, interface)
+        else:
+            sw_if_index = interface
+
+        if sw_if_index:
+            with VatTerminal(node, json_param=False) as vat:
+                vat.vat_terminal_exec_cmd_from_template(
+                    "hw_interface_set_mtu.vat", sw_if_index=sw_if_index,
+                    mtu=mtu)
+
+    @staticmethod
+    def vpp_set_interfaces_mtu_on_node(node, mtu=9200):
+        """Set Ethernet MTU on all interfaces.
+
+        :param node: VPP node.
+        :param mtu: Ethernet MTU size in Bytes. Default: 9200.
+        :type node: dict
+        :type mtu: int
+        """
+        for interface in node['interfaces']:
+            InterfaceUtil.vpp_set_interface_mtu(node, interface, mtu)
+
+    @staticmethod
+    def vpp_set_interfaces_mtu_on_all_duts(nodes, mtu=9200):
+        """Set Ethernet MTU on all interfaces on all DUTs.
+
+        :param nodes: VPP nodes.
+        :param mtu: Ethernet MTU size in Bytes. Default: 9200.
+        :type nodes: dict
+        :type mtu: int
+        """
+        for node in nodes.values():
+            if node['type'] == NodeType.DUT:
+                InterfaceUtil.vpp_set_interfaces_mtu_on_node(node, mtu)
+
+    @staticmethod
+    def vpp_node_interfaces_ready_wait(node, timeout=30):
         """Wait until all interfaces with admin-up are in link-up state.
 
         :param node: Node to wait on.
@@ -157,7 +205,7 @@ class InterfaceUtil(object):
                 sleep(1)
 
     @staticmethod
-    def vpp_nodes_interfaces_ready_wait(nodes, timeout=10):
+    def vpp_nodes_interfaces_ready_wait(nodes, timeout=30):
         """Wait until all interfaces with admin-up are in link-up state for
         listed nodes.
 
@@ -171,7 +219,7 @@ class InterfaceUtil(object):
             InterfaceUtil.vpp_node_interfaces_ready_wait(node, timeout)
 
     @staticmethod
-    def all_vpp_interfaces_ready_wait(nodes, timeout=10):
+    def all_vpp_interfaces_ready_wait(nodes, timeout=30):
         """Wait until all interfaces with admin-up are in link-up state for all
         nodes in the topology.
 
@@ -353,51 +401,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):