Fix various pylint 1.5.4 warnings
[csit.git] / resources / libraries / python / DPDK / SetupDPDKTest.py
index 0f70803..1e88f8d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cisco and/or its affiliates.
+# Copyright (c) 2018 Cisco and/or its affiliates.
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at:
@@ -28,12 +28,15 @@ from robot.libraries.BuiltIn import BuiltIn
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.constants import Constants as con
 from resources.libraries.python.topology import NodeType
+from resources.libraries.python.topology import Topology
 
 __all__ = ["SetupDPDKTest"]
 
 
 def pack_framework_dir():
-    """Pack the testing WS into temp file, return its name."""
+    """Pack the testing WS into temp file, return its name.
+
+    :raise RuntimeError: If command returns nonzero return code."""
 
     tmpfile = NamedTemporaryFile(suffix=".tgz", prefix="DPDK-testing-")
     file_name = tmpfile.name
@@ -49,7 +52,7 @@ def pack_framework_dir():
 
     return_code = proc.wait()
     if return_code != 0:
-        raise Exception("Could not pack testing framework.")
+        raise RuntimeError("Could not pack testing framework.")
 
     return file_name
 
@@ -80,6 +83,7 @@ def extract_tarball_at_node(tarball, node):
     :type tarball: str
     :type node: dict
     :returns: nothing
+    :raise RuntimeError: If command returns nonzero return code.
     """
     logger.console('Extracting tarball to {0} on {1}'.format(
         con.REMOTE_FW_DIR, node['host']))
@@ -91,7 +95,7 @@ def extract_tarball_at_node(tarball, node):
     (ret_code, _, stderr) = ssh.exec_command(cmd, timeout=30)
     if ret_code != 0:
         logger.error('Unpack error: {0}'.format(stderr))
-        raise Exception('Failed to unpack {0} at node {1}'.format(
+        raise RuntimeError('Failed to unpack {0} at node {1}'.format(
             tarball, node['host']))
 
 
@@ -102,6 +106,7 @@ def create_env_directory_at_node(node):
     :param node: Dictionary created from topology, will only install in the TG
     :type node: dict
     :returns: nothing
+    :raise RuntimeError: If command returns nonzero return code.
     """
     logger.console('Extracting virtualenv, installing requirements.txt '
                    'on {0}'.format(node['host']))
@@ -113,7 +118,7 @@ def create_env_directory_at_node(node):
         .format(con.REMOTE_FW_DIR), timeout=100)
     if ret_code != 0:
         logger.error('Virtualenv creation error: {0}'.format(stdout + stderr))
-        raise Exception('Virtualenv setup failed')
+        raise RuntimeError('Virtualenv setup failed')
     else:
         logger.console('Virtualenv created on {0}'.format(node['host']))
 
@@ -124,23 +129,25 @@ def install_dpdk_test(node):
     :param node: Dictionary created from topology
     :type node: dict
     :returns: nothing
+    :raise RuntimeError: If command returns nonzero return code.
     """
-    logger.console('Install the DPDK on {0}'.format(node['host']))
+    arch = Topology.get_node_arch(node)
+    logger.console('Install the DPDK on {0} ({1})'.format(node['host'],
+                                                          arch))
 
     ssh = SSH()
     ssh.connect(node)
 
     (ret_code, _, stderr) = ssh.exec_command(
-        'cd {0}/tests/dpdk/dpdk_scripts/ && ./install_dpdk.sh'
-        .format(con.REMOTE_FW_DIR), timeout=600)
+        'cd {0}/tests/dpdk/dpdk_scripts/ && ./install_dpdk.sh {1}'
+        .format(con.REMOTE_FW_DIR, arch), timeout=600)
 
     if ret_code != 0:
         logger.error('Install the DPDK error: {0}'.format(stderr))
-        raise Exception('Install the DPDK failed')
+        raise RuntimeError('Install the DPDK failed')
     else:
         logger.console('Install the DPDK on {0} success!'.format(node['host']))
 
-#pylint: disable=broad-except
 def setup_node(args):
     """Run all set-up methods for a node.
 
@@ -153,6 +160,11 @@ def setup_node(args):
     :rtype: bool
     """
     tarball, remote_tarball, node = args
+
+    # if unset, arch defaults to x86_64
+    if 'arch' not in node or not node['arch']:
+        node['arch'] = 'x86_64'
+
     try:
         copy_tarball_to_node(tarball, node)
         extract_tarball_at_node(remote_tarball, node)
@@ -160,7 +172,7 @@ def setup_node(args):
             install_dpdk_test(node)
         if node['type'] == NodeType.TG:
             create_env_directory_at_node(node)
-    except Exception as exc:
+    except RuntimeError as exc:
         logger.error("Node setup failed, error:'{0}'".format(exc.message))
         return False
     else:
@@ -210,9 +222,13 @@ class SetupDPDKTest(object):
             'Executed node setups in parallel, waiting for processes to end')
         result.wait()
 
-        logger.info('Results: {0}'.format(result.get()))
+        results = result.get()
+        node_setup_success = all(results)
+        logger.info('Results: {0}'.format(results))
 
         logger.trace('Test framework copied to all topology nodes')
         delete_local_tarball(tarball)
-        logger.console('All nodes are ready')
-
+        if node_setup_success:
+            logger.console('All nodes are ready')
+        else:
+            logger.console('Failed to setup dpdk on all the nodes')