Fix for module level import not at top of file

Change-Id: I1994b58a027cdac3bf4084b77db61bc646aaaba6
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/bin/generate_inventory b/bin/generate_inventory
index 3654682..80f725e 100755
--- a/bin/generate_inventory
+++ b/bin/generate_inventory
@@ -3,6 +3,9 @@
 Generate an inventory variable file containing a list of properties
 fields from the YAML phosphor-dbus-interfaces repository.
 """
+
+from gen_print import *
+
 import sys
 import os
 import yaml
@@ -10,7 +13,6 @@
 
 lib_path = sys.path[0] + "/../lib"
 sys.path.insert(0, lib_path)
-from gen_print import *
 
 # This list will be longer when more development codes are available.
 inventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu']
diff --git a/bin/generate_testsuite_info.py b/bin/generate_testsuite_info.py
index 7cafd1e..6392145 100755
--- a/bin/generate_testsuite_info.py
+++ b/bin/generate_testsuite_info.py
@@ -5,14 +5,15 @@
 Refer to https://robot-framework.readthedocs.io/en/3.0.1/autodoc/robot.parsing.html
 """
 
-import sys
-import os
-from robot.parsing.model import TestData
-sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
-
 from gen_arg import *
 from gen_print import *
 from gen_valid import *
+from robot.parsing.model import TestData
+
+import sys
+import os
+
+sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
 
 # Set exit_on_error for gen_valid functions.
 set_exit_on_error(True)
diff --git a/bin/obmc_ser_num b/bin/obmc_ser_num
index ba620c8..8d86099 100755
--- a/bin/obmc_ser_num
+++ b/bin/obmc_ser_num
@@ -4,6 +4,10 @@
 This program will get the system serial number from an OBMC machine and print it to stdout.
 """
 
+from gen_arg import *
+from gen_print import *
+from gen_valid import *
+
 import sys
 import os
 import requests
@@ -11,10 +15,6 @@
 save_path_0 = sys.path[0]
 del sys.path[0]
 
-from gen_arg import *
-from gen_print import *
-from gen_valid import *
-
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)
 
diff --git a/bin/print_ffdc_functions b/bin/print_ffdc_functions
index dd46bc6..325fa06 100755
--- a/bin/print_ffdc_functions
+++ b/bin/print_ffdc_functions
@@ -4,16 +4,16 @@
 See help text for details.
 """
 
-import sys
-
-save_path_0 = sys.path[0]
-del sys.path[0]
-
 from gen_arg import *
 from gen_print import *
 from gen_valid import *
 from openbmc_ffdc_list import *
 
+import sys
+
+save_path_0 = sys.path[0]
+del sys.path[0]
+
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)
 
diff --git a/bin/prop_call.py b/bin/prop_call.py
index 15cff57..e167fa5 100755
--- a/bin/prop_call.py
+++ b/bin/prop_call.py
@@ -16,18 +16,18 @@
 my_program --test_mode=y --quiet=n file1 file2 file3
 """
 
-import sys
-import os
-
-save_path_0 = sys.path[0]
-del sys.path[0]
-
 from gen_arg import *
 from gen_print import *
 from gen_valid import *
 from gen_misc import *
 from gen_cmd import *
 
+import sys
+import os
+
+save_path_0 = sys.path[0]
+del sys.path[0]
+
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)
 
diff --git a/bin/validate_plug_ins.py b/bin/validate_plug_ins.py
index a202d2e..78e65e5 100755
--- a/bin/validate_plug_ins.py
+++ b/bin/validate_plug_ins.py
@@ -1,12 +1,18 @@
 #!/usr/bin/env python3
 
+
+from gen_print import *
+from gen_arg import *
+from gen_plug_in import *
+
 import sys
+import os
+
 try:
     import __builtin__
 except ImportError:
     import builtins as __builtin__
 
-import os
 
 # python puts the program's directory path in sys.path[0].  In other words, the user ordinarily has no way
 # to override python's choice of a module from its own dir.  We want to have that ability in our environment.
@@ -17,10 +23,6 @@
 save_path_0 = sys.path[0]
 del sys.path[0]
 
-from gen_print import *
-from gen_arg import *
-from gen_plug_in import *
-
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)
 
diff --git a/bin/websocket_monitor.py b/bin/websocket_monitor.py
index 846ccd5..712b0ee 100755
--- a/bin/websocket_monitor.py
+++ b/bin/websocket_monitor.py
@@ -4,6 +4,10 @@
 See help text for details.
 """
 
+from gen_print import *
+from gen_arg import *
+from gen_valid import *
+
 import json
 import sys
 import websocket
@@ -14,10 +18,6 @@
 save_path_0 = sys.path[0]
 del sys.path[0]
 
-from gen_print import *
-from gen_arg import *
-from gen_valid import *
-
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)
 
diff --git a/ffdc/collect_ffdc.py b/ffdc/collect_ffdc.py
index c1c9495..ca232f1 100644
--- a/ffdc/collect_ffdc.py
+++ b/ffdc/collect_ffdc.py
@@ -4,6 +4,8 @@
 CLI FFDC Collector.
 """
 
+from ffdc_collector import ffdc_collector
+
 import os
 import sys
 import click
@@ -12,14 +14,13 @@
 # Absolute path to openbmc-test-automation/ffdc
 abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
 full_path = abs_path.split('ffdc')[0]
+
 sys.path.append(full_path)
 # Walk path and append to sys.path
 for root, dirs, files in os.walk(full_path):
     for found_dir in dirs:
         sys.path.append(os.path.join(root, found_dir))
 
-from ffdc_collector import ffdc_collector
-
 
 @click.command(context_settings=dict(help_option_names=['-h', '--help']))
 @click.option('-r', '--remote',
diff --git a/ffdc/ffdc_collector.py b/ffdc/ffdc_collector.py
index 27b088c..9afd0ad 100644
--- a/ffdc/ffdc_collector.py
+++ b/ffdc/ffdc_collector.py
@@ -4,6 +4,10 @@
 See class prolog below for details.
 """
 
+from ssh_utility import SSHRemoteclient
+from telnet_utility import TelnetRemoteclient
+from errno import EACCES, EPERM
+
 import os
 import re
 import sys
@@ -12,7 +16,6 @@
 import time
 import logging
 import platform
-from errno import EACCES, EPERM
 import subprocess
 
 script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -22,8 +25,6 @@
     for dir in dirs:
         sys.path.append(os.path.join(root, dir))
 
-from ssh_utility import SSHRemoteclient
-from telnet_utility import TelnetRemoteclient
 
 r"""
 User define plugins python functions.
diff --git a/ffdc/plugins/scp_execution.py b/ffdc/plugins/scp_execution.py
index 0aca54c..9754c02 100644
--- a/ffdc/plugins/scp_execution.py
+++ b/ffdc/plugins/scp_execution.py
@@ -1,23 +1,25 @@
 #!/usr/bin/env python3
 
 
+# ssh_utility is in ../lib
+from ssh_utility import SSHRemoteclient
+
 import os
 import sys
 
 # ---------Set sys.path for pluqin execution---------------------------------------
 # Absolute path to this plugin
 abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+
 # full_path to plugins parent directory
 full_path = abs_path.split('plugins')[0]
 sys.path.append(full_path)
+
 # Walk path and append to sys.path
 for root, dirs, files in os.walk(full_path):
     for found_dir in dirs:
         sys.path.append(os.path.join(root, found_dir))
 
-# ssh_utility is in ../lib
-from ssh_utility import SSHRemoteclient
-
 
 def scp_remote_file(hostname,
                     username,
diff --git a/ffdc/plugins/ssh_execution.py b/ffdc/plugins/ssh_execution.py
index 087d887..db06596 100644
--- a/ffdc/plugins/ssh_execution.py
+++ b/ffdc/plugins/ssh_execution.py
@@ -1,6 +1,8 @@
 #!/usr/bin/env python3
 
 
+from ssh_utility import SSHRemoteclient
+
 import os
 import sys
 
@@ -16,7 +18,6 @@
         sys.path.append(os.path.join(root, found_dir))
 
 # ssh_utility is in ../lib
-from ssh_utility import SSHRemoteclient
 
 
 def ssh_execute_cmd(hostname,
diff --git a/ffdc/plugins/telnet_execution.py b/ffdc/plugins/telnet_execution.py
index 7cfd78b..726d3a6 100644
--- a/ffdc/plugins/telnet_execution.py
+++ b/ffdc/plugins/telnet_execution.py
@@ -1,6 +1,8 @@
 #!/usr/bin/env python3
 
 
+from telnet_utility import TelnetRemoteclient
+
 import os
 import sys
 
@@ -15,8 +17,6 @@
     for found_dir in dirs:
         sys.path.append(os.path.join(root, found_dir))
 
-from telnet_utility import TelnetRemoteclient
-
 
 def telnet_execute_cmd(hostname,
                        username,
diff --git a/lib/code_update_utils.py b/lib/code_update_utils.py
index e8ee562..5d69db6 100644
--- a/lib/code_update_utils.py
+++ b/lib/code_update_utils.py
@@ -4,24 +4,24 @@
 This module provides utilities for code updates.
 """
 
+from robot.libraries.BuiltIn import BuiltIn
+
+import bmc_ssh_utils as bsu
+import gen_robot_keyword as keyword
+import gen_print as gp
+import variables as var
+
 import os
 import re
 import sys
 import tarfile
 import time
 import collections
-from robot.libraries.BuiltIn import BuiltIn
 
 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
 repo_data_path = re.sub('/lib', '/data', robot_pgm_dir_path)
 sys.path.append(repo_data_path)
 
-import bmc_ssh_utils as bsu
-import gen_robot_keyword as keyword
-import gen_print as gp
-import variables as var
-from robot.libraries.BuiltIn import BuiltIn
-
 
 def get_bmc_firmware(image_type, sw_dict):
     r"""
diff --git a/lib/dump_utils.py b/lib/dump_utils.py
index d0b0108..7c65df9 100755
--- a/lib/dump_utils.py
+++ b/lib/dump_utils.py
@@ -10,14 +10,16 @@
 import bmc_ssh_utils as bsu
 import var_funcs as vf
 import os
-from robot.libraries.BuiltIn import BuiltIn
 import sys
 import os
 import imp
+import variables as var
+
+from robot.libraries.BuiltIn import BuiltIn
+
 base_path = os.path.dirname(os.path.dirname(
                             imp.find_module("gen_robot_print")[1])) + os.sep
 sys.path.append(base_path + "data/")
-import variables as var
 
 
 def get_dump_dict(quiet=None):
diff --git a/lib/ffdc_cli_robot_script.py b/lib/ffdc_cli_robot_script.py
index 013e4ab..eb2cb2e 100644
--- a/lib/ffdc_cli_robot_script.py
+++ b/lib/ffdc_cli_robot_script.py
@@ -4,12 +4,13 @@
 import sys
 
 
-sys.path.append(__file__.split(__file__.split("/")[-1])[0] + "../ffdc")
 from ffdc_collector import ffdc_collector
 from ssh_utility import SSHRemoteclient
 
 from robot.libraries.BuiltIn import BuiltIn as robotBuildIn
 
+sys.path.append(__file__.split(__file__.split("/")[-1])[0] + "../ffdc")
+
 # (Sub) String constants used for input dictionary key search
 HOST = "HOST"
 USER = "USERNAME"
diff --git a/lib/gen_robot_ssh.py b/lib/gen_robot_ssh.py
index ab68415..b0cd049 100755
--- a/lib/gen_robot_ssh.py
+++ b/lib/gen_robot_ssh.py
@@ -16,10 +16,13 @@
 
 import gen_print as gp
 import func_timer as ft
-func_timer = ft.func_timer_class()
+
 
 from robot.libraries.BuiltIn import BuiltIn
 from SSHLibrary import SSHLibrary
+
+func_timer = ft.func_timer_class()
+
 sshlib = SSHLibrary()
 
 
diff --git a/lib/ipmi_utils.py b/lib/ipmi_utils.py
index f8cc9be..b2a1b2b 100644
--- a/lib/ipmi_utils.py
+++ b/lib/ipmi_utils.py
@@ -14,9 +14,10 @@
 import var_funcs as vf
 import ipmi_client as ic
 import tempfile
-gru.my_import_resource("ipmi_client.robot")
-from robot.libraries.BuiltIn import BuiltIn
 import json
+from robot.libraries.BuiltIn import BuiltIn
+
+gru.my_import_resource("ipmi_client.robot")
 
 
 def get_sol_info():
diff --git a/lib/logging_utils.py b/lib/logging_utils.py
index e621d5e..0cdbea9 100644
--- a/lib/logging_utils.py
+++ b/lib/logging_utils.py
@@ -5,15 +5,17 @@
 """
 
 import gen_print as gp
+import variables as var
+import gen_robot_utils as gru
 import sys
 import os
 import imp
+
+from robot.libraries.BuiltIn import BuiltIn
+
 base_path = os.path.dirname(os.path.dirname(
                             imp.find_module("gen_robot_print")[1])) + os.sep
 sys.path.append(base_path + "data/")
-import variables as var
-from robot.libraries.BuiltIn import BuiltIn
-import gen_robot_utils as gru
 gru.my_import_resource("logging_utils.robot")
 
 
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 0dc245d..79358a6 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -33,12 +33,12 @@
 import gen_plug_in_utils as gpu
 import pel_utils as pel
 import logging_utils as log
+import run_keyword as rk
 
 base_path = os.path.dirname(os.path.dirname(
                             imp.find_module("gen_robot_print")[1])) +\
     os.sep
 sys.path.append(base_path + "extended/")
-import run_keyword as rk
 
 # Setting master_pid correctly influences the behavior of plug-ins like
 # DB_Logging
diff --git a/lib/pel_utils.py b/lib/pel_utils.py
index d361a4e..b06124c 100644
--- a/lib/pel_utils.py
+++ b/lib/pel_utils.py
@@ -6,6 +6,8 @@
 
 import func_args as fa
 import bmc_ssh_utils as bsu
+import pel_variables
+
 import json
 import os
 import sys
@@ -14,8 +16,6 @@
 base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 sys.path.append(base_path + "/data/")
 
-import pel_variables
-
 
 class peltool_exception(Exception):
     r"""
diff --git a/lib/state_map.py b/lib/state_map.py
index 5d72b5a..f8353de 100644
--- a/lib/state_map.py
+++ b/lib/state_map.py
@@ -6,6 +6,10 @@
    - Defines Valid states of the system
 
 """
+
+import gen_robot_keyword as keyword
+import variables as var
+
 import os
 import re
 import sys
@@ -16,8 +20,6 @@
 repo_data_dir_path = re.sub('/lib', '/data', robot_pgm_dir_path)
 sys.path.append(repo_data_dir_path)
 
-import gen_robot_keyword as keyword
-import variables as var
 
 BuiltIn().import_resource("state_manager.robot")
 BuiltIn().import_resource("rest_client.robot")
diff --git a/syslib/utils_os.py b/syslib/utils_os.py
index 2026d95..fe97de5 100755
--- a/syslib/utils_os.py
+++ b/syslib/utils_os.py
@@ -4,14 +4,14 @@
 This file contains utilities associated with the host OS.
 """
 
+import bmc_ssh_utils
+import var_funcs
+
 import sys
 import os
 
 sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
 
-import bmc_ssh_utils
-import var_funcs
-
 
 def get_os_release_info(default_cmd="cat /etc/os-release"):
     r"""
diff --git a/tools/ct_metrics/gen_csv_results.py b/tools/ct_metrics/gen_csv_results.py
index 342fe69..3ad9d67 100755
--- a/tools/ct_metrics/gen_csv_results.py
+++ b/tools/ct_metrics/gen_csv_results.py
@@ -14,19 +14,20 @@
 import re
 import stat
 import datetime
+
 from robot.api import ExecutionResult
 from robot.result.visitor import ResultVisitor
 from xml.etree import ElementTree
 
+from gen_arg import *
+from gen_print import *
+from gen_valid import *
+
 # Remove the python library path to restore with local project path later.
 save_path_0 = sys.path[0]
 del sys.path[0]
 sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib"))
 
-from gen_arg import *
-from gen_print import *
-from gen_valid import *
-
 # Restore sys.path[0].
 sys.path.insert(0, save_path_0)