Fix various pylint violations
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 5e3c4c4..e43935e 100644 (file)
@@ -68,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',
@@ -123,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.
@@ -158,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.
 
@@ -172,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.
 
@@ -736,11 +783,10 @@ class InterfaceUtil(object):
                 "tap_dump.vat")
         if name is None:
             return response[0]
-        else:
-            for item in response[0]:
-                if name == item['dev_name']:
-                    return item
-            return {}
+        for item in response[0]:
+            if name == item['dev_name']:
+                return item
+        return {}
 
     @staticmethod
     def create_subinterface(node, interface, sub_id, outer_vlan_id=None,
@@ -886,11 +932,11 @@ class InterfaceUtil(object):
             the node.
         """
         hw_addr = '' if mac is None else 'hw-addr {mac}'.format(mac=mac)
-        lb = '' if load_balance is None \
-            else 'lb {lb}'.format(lb=load_balance)
+        ldb = '' if load_balance is None \
+            else 'lb {ldb}'.format(ldb=load_balance)
 
         output = VatExecutor.cmd_from_template(
-            node, 'create_bond_interface.vat', mode=mode, lb=lb, mac=hw_addr)
+            node, 'create_bond_interface.vat', mode=mode, lb=ldb, mac=hw_addr)
 
         if output[0].get('retval') == 0:
             sw_if_idx = output[0].get('sw_if_index')
@@ -898,8 +944,8 @@ class InterfaceUtil(object):
             if_key = Topology.get_interface_by_sw_index(node, sw_if_idx)
             return if_key
         else:
-            raise RuntimeError('Create bond interface failed on node "{n}"'
-                               .format(n=node['host']))
+            raise RuntimeError('Create bond interface failed on "{host}"'
+                               .format(host=node['host']))
 
     @staticmethod
     def add_bond_eth_interface(node, ifc_name=None, sw_if_idx=None):