CSIT-665: Re-write L1 robot keywords in python
[csit.git] / resources / libraries / python / DUTSetup.py
index dabdfce..bccf108 100644 (file)
@@ -15,8 +15,7 @@
 
 from robot.api import logger
 
 
 from robot.api import logger
 
-from resources.libraries.python.topology import NodeType
-from resources.libraries.python.topology import Topology
+from resources.libraries.python.topology import NodeType, Topology
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.constants import Constants
 from resources.libraries.python.VatExecutor import VatExecutor
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.constants import Constants
 from resources.libraries.python.VatExecutor import VatExecutor
@@ -49,6 +48,17 @@ class DUTSetup(object):
         vat = VatExecutor()
         vat.execute_script("show_version_verbose.vat", node, json_out=False)
 
         vat = VatExecutor()
         vat.execute_script("show_version_verbose.vat", node, json_out=False)
 
+    @staticmethod
+    def show_vpp_version_on_all_duts(nodes):
+        """Show VPP version verbose on all DUTs.
+
+        :param nodes: VPP nodes
+        :type nodes: dict
+        """
+        for node in nodes.values():
+            if node['type'] == NodeType.DUT:
+                DUTSetup.vpp_show_version_verbose(node)
+
     @staticmethod
     def vpp_api_trace_save(node):
         """Run "api trace save" CLI command.
     @staticmethod
     def vpp_api_trace_save(node):
         """Run "api trace save" CLI command.
@@ -106,32 +116,38 @@ class DUTSetup(object):
 
         :param node: DUT node.
         :type node: dict
 
         :param node: DUT node.
         :type node: dict
-        :return: PID
+        :returns: PID
         :rtype: int
         :raises RuntimeError if it is not possible to get the PID.
         """
 
         ssh = SSH()
         ssh.connect(node)
         :rtype: int
         :raises RuntimeError if it is not possible to get the PID.
         """
 
         ssh = SSH()
         ssh.connect(node)
-        ret_code, stdout, stderr = ssh.exec_command('pidof vpp')
 
 
-        logger.trace(stdout)
-        logger.trace(stderr)
+        for i in range(3):
+            logger.trace('Try {}: Get VPP PID'.format(i))
+            ret_code, stdout, stderr = ssh.exec_command('pidof vpp')
+
+            if int(ret_code) != 0:
+                raise RuntimeError('Not possible to get PID of VPP process '
+                                   'on node: {0}\n {1}'.
+                                   format(node['host'], stdout + stderr))
+
+            if len(stdout.splitlines()) == 1:
+                return int(stdout)
+            elif len(stdout.splitlines()) == 0:
+                logger.debug("No VPP PID found on node {0}".
+                             format(node['host']))
+                continue
+            else:
+                logger.debug("More then one VPP PID found on node {0}".
+                             format(node['host']))
+                ret_list = list()
+                for line in stdout.splitlines():
+                    ret_list.append(int(line))
+                return ret_list
 
 
-        if int(ret_code) != 0:
-            logger.debug('Not possible to get PID of VPP process on node: '
-                         '{0}\n {1}'.format(node['host'], stdout + stderr))
-            raise RuntimeError('Not possible to get PID of VPP process on node:'
-                               ' {}'.format(node['host']))
-
-        if len(stdout.splitlines()) == 1:
-            return int(stdout)
-        elif len(stdout.splitlines()) == 0:
-            raise RuntimeError("No VPP PID found on node {0}".
-                               format(node['host']))
-        else:
-            raise RuntimeError("More then one VPP PID found on node {0}".
-                               format(node['host']))
+        return None
 
     @staticmethod
     def get_vpp_pids(nodes):
 
     @staticmethod
     def get_vpp_pids(nodes):
@@ -139,7 +155,7 @@ class DUTSetup(object):
 
         :param nodes: DUT nodes.
         :type nodes: dict
 
         :param nodes: DUT nodes.
         :type nodes: dict
-        :return: PIDs
+        :returns: PIDs
         :rtype: dict
         """
 
         :rtype: dict
         """
 
@@ -180,8 +196,8 @@ class DUTSetup(object):
         ssh.connect(node)
 
         cryptodev = Topology.get_cryptodev(node)
         ssh.connect(node)
 
         cryptodev = Topology.get_cryptodev(node)
-        cmd = 'cat /sys/bus/pci/devices/{}/sriov_numvfs'.format(
-            cryptodev.replace(':', r'\:'))
+        cmd = 'cat /sys/bus/pci/devices/{}/sriov_numvfs'.\
+            format(cryptodev.replace(':', r'\:'))
 
         # Try to read number of VFs from PCI address of QAT device
         for _ in range(3):
 
         # Try to read number of VFs from PCI address of QAT device
         for _ in range(3):
@@ -190,8 +206,8 @@ class DUTSetup(object):
                 try:
                     sriov_numvfs = int(stdout)
                 except ValueError:
                 try:
                     sriov_numvfs = int(stdout)
                 except ValueError:
-                    logger.trace('Reading sriov_numvfs info failed on: {}'\
-                        .format(node['host']))
+                    logger.trace('Reading sriov_numvfs info failed on: {}'.
+                                 format(node['host']))
                 else:
                     if sriov_numvfs != numvfs:
                         if force_init:
                 else:
                     if sriov_numvfs != numvfs:
                         if force_init:
@@ -199,9 +215,10 @@ class DUTSetup(object):
                             # with numvfs
                             DUTSetup.crypto_device_init(node, numvfs)
                         else:
                             # with numvfs
                             DUTSetup.crypto_device_init(node, numvfs)
                         else:
-                            raise RuntimeError('QAT device {} is not '\
-                                'initialized to {} on host: {}'.format(\
-                                cryptodev, numvfs, node['host']))
+                            raise RuntimeError('QAT device {} is not '
+                                               'initialized to {} on host: {}'.
+                                               format(cryptodev, numvfs,
+                                                      node['host']))
                     break
 
     @staticmethod
                     break
 
     @staticmethod
@@ -308,8 +325,8 @@ class DUTSetup(object):
                 # Module is not loaded and we want to load it
                 DUTSetup.kernel_module_load(node, module)
             else:
                 # Module is not loaded and we want to load it
                 DUTSetup.kernel_module_load(node, module)
             else:
-                raise RuntimeError('Kernel module {} is not loaded on host: '\
-                    '{}'.format(module, node['host']))
+                raise RuntimeError('Kernel module {} is not loaded on host: {}'.
+                                   format(module, node['host']))
 
     @staticmethod
     def kernel_module_load(node, module):
 
     @staticmethod
     def kernel_module_load(node, module):
@@ -329,5 +346,5 @@ class DUTSetup(object):
         ret_code, _, _ = ssh.exec_command_sudo("modprobe {}".format(module))
 
         if int(ret_code) != 0:
         ret_code, _, _ = ssh.exec_command_sudo("modprobe {}".format(module))
 
         if int(ret_code) != 0:
-            raise RuntimeError('Failed to load {} kernel module on host: '\
-                '{}'.format(module, node['host']))
+            raise RuntimeError('Failed to load {} kernel module on host: {}'.
+                               format(module, node['host']))