Update python code for python 3.8 or higher compatibility

Changes:
     - Update shebang directive to use python3 explicitly.
     - remove preexec_fn feature which is deprecated in higher
       python version 3.8 and above.
     - bufsize fix, from documentation bufsize 1 means line buffered
      (only usable if universal_newlines=True i.e., in a text mode)
      refer: https://docs.python.org/3/library/subprocess.html
     - Fix SyntaxWarning: "is" with "=="

Change-Id: Ib96c1ba8c2327d6774d0d731b48ca7e61a4a297a
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_network_utils.py b/lib/bmc_network_utils.py
index d73a1e1..a704392 100644
--- a/lib/bmc_network_utils.py
+++ b/lib/bmc_network_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Network generic functions.
diff --git a/lib/bmc_redfish.py b/lib/bmc_redfish.py
index 5ce17f6..1679ca4 100644
--- a/lib/bmc_redfish.py
+++ b/lib/bmc_redfish.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 See class prolog below for details.
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index 2ea250f..a361146 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 BMC redfish utility functions.
diff --git a/lib/bmc_ssh_utils.py b/lib/bmc_ssh_utils.py
index c82788f..3aa90fa 100755
--- a/lib/bmc_ssh_utils.py
+++ b/lib/bmc_ssh_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides many valuable bmc ssh functions such as bmc_execute_command.
diff --git a/lib/boot_data.py b/lib/boot_data.py
index f1b7147..eaa7a52 100755
--- a/lib/boot_data.py
+++ b/lib/boot_data.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module has functions to support various data structures such as the boot_table, valid_boot_list and
diff --git a/lib/code_update_utils.py b/lib/code_update_utils.py
index 35953c7..e8ee562 100644
--- a/lib/code_update_utils.py
+++ b/lib/code_update_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides utilities for code updates.
diff --git a/lib/disable_warning_urllib.py b/lib/disable_warning_urllib.py
index 55a7239..4c08a24 100644
--- a/lib/disable_warning_urllib.py
+++ b/lib/disable_warning_urllib.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 import logging
 import warnings
 try:
diff --git a/lib/dump_utils.py b/lib/dump_utils.py
index 94c409f..add5f5b 100755
--- a/lib/dump_utils.py
+++ b/lib/dump_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This file contains functions which are useful for processing BMC dumps.
diff --git a/lib/event_notification.py b/lib/event_notification.py
index 1e12bbc..363caf4 100755
--- a/lib/event_notification.py
+++ b/lib/event_notification.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import requests
 import websocket
diff --git a/lib/external_intf/management_console_utils.py b/lib/external_intf/management_console_utils.py
index 2cc62a9..d754bea 100644
--- a/lib/external_intf/management_console_utils.py
+++ b/lib/external_intf/management_console_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import os
 import re
diff --git a/lib/firmware_utils.py b/lib/firmware_utils.py
index 99ad7c6..959693d 100755
--- a/lib/firmware_utils.py
+++ b/lib/firmware_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains functions which pertain to firmware.
diff --git a/lib/func_args.py b/lib/func_args.py
index 4edb5cd..306af38 100644
--- a/lib/func_args.py
+++ b/lib/func_args.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides argument manipulation functions like pop_arg.
diff --git a/lib/func_timer.py b/lib/func_timer.py
index 27cfa52..0021163 100644
--- a/lib/func_timer.py
+++ b/lib/func_timer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Define the func_timer class.
diff --git a/lib/gen_arg.py b/lib/gen_arg.py
index b89d4cd..afa7b57 100755
--- a/lib/gen_arg.py
+++ b/lib/gen_arg.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides valuable argument processing functions like gen_get_options and sprint_args.
diff --git a/lib/gen_call_robot.py b/lib/gen_call_robot.py
index 62ea130..2e51626 100755
--- a/lib/gen_call_robot.py
+++ b/lib/gen_call_robot.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides functions which are useful to plug-ins call-point programs that wish to make external
@@ -359,7 +359,7 @@
     # It TMP_ROBOT_DIR_PATH is set, it means the caller wanted the robot output initially directed to
     # TMP_ROBOT_DIR_PATH but later moved to FFDC_DIR_PATH.  Otherwise, we're done.
 
-    if os.environ.get("TMP_ROBOT_DIR_PATH", "") is "":
+    if os.environ.get("TMP_ROBOT_DIR_PATH", "") == "":
         return
 
     # We're directing these to the FFDC dir path so that they'll be subjected to FFDC cleanup.
diff --git a/lib/gen_cmd.py b/lib/gen_cmd.py
index 18b79e9..cac5ba4 100644
--- a/lib/gen_cmd.py
+++ b/lib/gen_cmd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides command execution functions such as cmd_fnc and cmd_fnc_u.
@@ -83,6 +83,7 @@
     sub_proc = subprocess.Popen(cmd_buf,
                                 bufsize=1,
                                 shell=True,
+                                universal_newlines=True,
                                 executable='/bin/bash',
                                 stdout=subprocess.PIPE,
                                 stderr=stderr)
@@ -353,11 +354,11 @@
     func_out_history_buf = ""
     for attempt_num in range(1, max_attempts + 1):
         sub_proc = subprocess.Popen(command_string,
-                                    preexec_fn=os.setsid,
                                     bufsize=1,
                                     shell=True,
                                     universal_newlines=True,
                                     executable='/bin/bash',
+                                    stdin=subprocess.PIPE,
                                     stdout=subprocess.PIPE,
                                     stderr=stderr)
         if fork:
diff --git a/lib/gen_misc.py b/lib/gen_misc.py
index 8857d63..ad5beea 100755
--- a/lib/gen_misc.py
+++ b/lib/gen_misc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides many valuable functions such as my_parm_file.
diff --git a/lib/gen_plug_in.py b/lib/gen_plug_in.py
index 95776d5..fc57cef 100755
--- a/lib/gen_plug_in.py
+++ b/lib/gen_plug_in.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides functions which are useful for running plug-ins.
diff --git a/lib/gen_plug_in_utils.py b/lib/gen_plug_in_utils.py
index 825801f..7ec2088 100755
--- a/lib/gen_plug_in_utils.py
+++ b/lib/gen_plug_in_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides functions which are useful to plug-in call point programs.
diff --git a/lib/gen_print.py b/lib/gen_print.py
index d65ed39..5f87343 100755
--- a/lib/gen_print.py
+++ b/lib/gen_print.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides many print functions such as sprint_var, sprint_time, sprint_error, sprint_call_stack.
diff --git a/lib/gen_robot_keyword.py b/lib/gen_robot_keyword.py
index 1bac73d..f4b2e73 100755
--- a/lib/gen_robot_keyword.py
+++ b/lib/gen_robot_keyword.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides robot keyword execution functions such as run_key..
diff --git a/lib/gen_robot_plug_in.py b/lib/gen_robot_plug_in.py
index 0920067..0f6deda 100755
--- a/lib/gen_robot_plug_in.py
+++ b/lib/gen_robot_plug_in.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides functions which are useful for running plug-ins from a robot program.
diff --git a/lib/gen_robot_print.py b/lib/gen_robot_print.py
index 7dd1384..fb958e0 100755
--- a/lib/gen_robot_print.py
+++ b/lib/gen_robot_print.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This file contains functions useful for printing to stdout from robot programs.
diff --git a/lib/gen_robot_ssh.py b/lib/gen_robot_ssh.py
index b79daf6..38391d1 100755
--- a/lib/gen_robot_ssh.py
+++ b/lib/gen_robot_ssh.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides many valuable ssh functions such as sprint_connection, execute_ssh_command, etc.
diff --git a/lib/gen_robot_utils.py b/lib/gen_robot_utils.py
index fd15eed..bd61a87 100644
--- a/lib/gen_robot_utils.py
+++ b/lib/gen_robot_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains utility and wrapper functions useful to robot python
diff --git a/lib/gen_robot_valid.py b/lib/gen_robot_valid.py
index df8038c..5580a5e 100755
--- a/lib/gen_robot_valid.py
+++ b/lib/gen_robot_valid.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides validation functions like valid_value(), valid_integer(), etc. for robot programs.
diff --git a/lib/gen_valid.py b/lib/gen_valid.py
index d934054..57c1a1d 100755
--- a/lib/gen_valid.py
+++ b/lib/gen_valid.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides validation functions like valid_value(), valid_integer(), etc.
diff --git a/lib/ipmi_client.py b/lib/ipmi_client.py
index 85a7342..7eb8f08 100644
--- a/lib/ipmi_client.py
+++ b/lib/ipmi_client.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 A python companion file for ipmi_client.robot.
diff --git a/lib/ipmi_utils.py b/lib/ipmi_utils.py
index 910db87..a23e9e5 100644
--- a/lib/ipmi_utils.py
+++ b/lib/ipmi_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Provide useful ipmi functions.
diff --git a/lib/jobs_processing.py b/lib/jobs_processing.py
index 3368bd7..5555b62 100644
--- a/lib/jobs_processing.py
+++ b/lib/jobs_processing.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains keyword functions to support multiprocessing
diff --git a/lib/logging_utils.py b/lib/logging_utils.py
index 5186b17..e621d5e 100644
--- a/lib/logging_utils.py
+++ b/lib/logging_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Provide useful error log utility keywords.
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 17a329e..0f69e03 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module is the python counterpart to obmc_boot_test.
diff --git a/lib/openbmc_ffdc.py b/lib/openbmc_ffdc.py
index e4153f8..5a4657b 100644
--- a/lib/openbmc_ffdc.py
+++ b/lib/openbmc_ffdc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module is the python counterpart to openbmc_ffdc.robot..
diff --git a/lib/openbmc_ffdc_list.py b/lib/openbmc_ffdc_list.py
index 910bce0..d3ca829 100755
--- a/lib/openbmc_ffdc_list.py
+++ b/lib/openbmc_ffdc_list.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 r"""
 #    @file     openbmc_ffdc_list.py
 #    @brief    List for FFDC ( First failure data capture )
diff --git a/lib/openbmctool_utils.py b/lib/openbmctool_utils.py
index 7f98963..a6c94e9 100755
--- a/lib/openbmctool_utils.py
+++ b/lib/openbmctool_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides many valuable openbmctool.py functions such as
diff --git a/lib/pel_utils.py b/lib/pel_utils.py
index 2ad9f52..9321347 100644
--- a/lib/pel_utils.py
+++ b/lib/pel_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 PEL functions.
diff --git a/lib/pldm_utils.py b/lib/pldm_utils.py
index 8e0f2cc..35fe929 100755
--- a/lib/pldm_utils.py
+++ b/lib/pldm_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 PLDM functions.
diff --git a/lib/redfish_plus.py b/lib/redfish_plus.py
index 96e9daf..e2125ca 100755
--- a/lib/redfish_plus.py
+++ b/lib/redfish_plus.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 See redfish_plus class prolog below for details.
diff --git a/lib/redfish_request.py b/lib/redfish_request.py
index 1918a07..6add29f 100644
--- a/lib/redfish_request.py
+++ b/lib/redfish_request.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import requests
 import urllib.request
diff --git a/lib/secureboot/secureboot.py b/lib/secureboot/secureboot.py
index 99728c8..1aa5f06 100644
--- a/lib/secureboot/secureboot.py
+++ b/lib/secureboot/secureboot.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides some functions for Secure Boot verification.
diff --git a/lib/state.py b/lib/state.py
index ea45dd2..b688566 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains functions having to do with machine state: get_state,
@@ -571,12 +571,12 @@
         if os_host is None:
             os_host = ""
 
-    if os_username is "":
+    if os_username == "":
         os_username = BuiltIn().get_variable_value("${OS_USERNAME}")
         if os_username is None:
             os_username = ""
 
-    if os_password is "":
+    if os_password == "":
         os_password = BuiltIn().get_variable_value("${OS_PASSWORD}")
         if os_password is None:
             os_password = ""
diff --git a/lib/state_map.py b/lib/state_map.py
index 908b159..5d72b5a 100644
--- a/lib/state_map.py
+++ b/lib/state_map.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 State Manager module:
diff --git a/lib/tally_sheet.py b/lib/tally_sheet.py
index c48e161..03162af 100755
--- a/lib/tally_sheet.py
+++ b/lib/tally_sheet.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Define the tally_sheet class.
diff --git a/lib/tftp_update_utils.py b/lib/tftp_update_utils.py
index 2d0f7e3..6220591 100644
--- a/lib/tftp_update_utils.py
+++ b/lib/tftp_update_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains functions for tftp update.
diff --git a/lib/utilities.py b/lib/utilities.py
index dd7da09..6416aa9 100755
--- a/lib/utilities.py
+++ b/lib/utilities.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -u
+#!/usr/bin/env python3 -u
 import sys
 from robot.libraries.BuiltIn import BuiltIn
 import imp
diff --git a/lib/utils.py b/lib/utils.py
index 72cb202..20dbef1 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Companion file to utils.robot.
diff --git a/lib/utils_files.py b/lib/utils_files.py
index 3395e65..0b19432 100755
--- a/lib/utils_files.py
+++ b/lib/utils_files.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module contains file functions such as file_diff.
diff --git a/lib/var_funcs.py b/lib/var_funcs.py
index 72a0f62..fdde68e 100644
--- a/lib/var_funcs.py
+++ b/lib/var_funcs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Define variable manipulation functions.
diff --git a/lib/var_stack.py b/lib/var_stack.py
index 0b73b91..3ea3813 100644
--- a/lib/var_stack.py
+++ b/lib/var_stack.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 Define the var_stack class.
diff --git a/lib/vpd_utils.py b/lib/vpd_utils.py
index 38a86d7..eb31c71 100644
--- a/lib/vpd_utils.py
+++ b/lib/vpd_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 VPD functions.
diff --git a/lib/wrap_utils.py b/lib/wrap_utils.py
index de678b3..231dff8 100755
--- a/lib/wrap_utils.py
+++ b/lib/wrap_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 r"""
 This module provides functions which are useful for writing python wrapper functions (i.e. in this context, a