Fix python3.x backward changes
Change-Id: Ia33d10935faa2306b19fa6082a1df8a2240ebf83
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/boot_data.py b/lib/boot_data.py
index 070a0e6..abb41b7 100755
--- a/lib/boot_data.py
+++ b/lib/boot_data.py
@@ -68,7 +68,7 @@
for boot in boot_table:
state_keys = ['start', 'end']
for state_key in state_keys:
- for sub_state in boot_table[boot][state_key]:
+ for sub_state in list(boot_table[boot][state_key]):
if sub_state.startswith("os_"):
boot_table[boot][state_key].pop(sub_state, None)
diff --git a/lib/gen_robot_plug_in.py b/lib/gen_robot_plug_in.py
index cfcb660..a5ce323 100755
--- a/lib/gen_robot_plug_in.py
+++ b/lib/gen_robot_plug_in.py
@@ -36,16 +36,13 @@
"""
cmd_buf = "validate_plug_ins.py \"" + plug_in_dir_paths + "\""
- if int(quiet) != 1:
- gp.print_issuing(cmd_buf)
- rc, out_buf = commands.getstatusoutput(cmd_buf)
+ rc, out_buf = gc.shell_cmd(cmd_buf, print_output=0)
if rc != 0:
- message = gp.sprint_varx("rc", rc, 1) + out_buf
- gp.printn(out_buf, 'STDERR')
BuiltIn().fail(gp.sprint_error("Validate plug ins call failed. See"
+ " stderr text for details.\n"))
- plug_in_packages_list = out_buf.split("\n")
+ # plug_in_packages_list = out_buf.split("\n")
+ plug_in_packages_list = list(filter(None, out_buf.split("\n")))
if len(plug_in_packages_list) == 1 and plug_in_packages_list[0] == "":
return []
diff --git a/lib/gen_robot_ssh.py b/lib/gen_robot_ssh.py
index 2bd0742..d40f5d8 100755
--- a/lib/gen_robot_ssh.py
+++ b/lib/gen_robot_ssh.py
@@ -12,7 +12,7 @@
try:
import exceptions
except ImportError:
- import builtins as exception
+ import builtins as exceptions
import gen_print as gp
import func_timer as ft
@@ -98,7 +98,7 @@
for connection in sshlib.get_connections():
# Create connection_dict from connection object.
connection_dict = dict((key, str(value)) for key, value in
- connection._config.iteritems())
+ connection._config.items())
if dict(connection_dict, **open_connection_args) == connection_dict:
return connection
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 11e9b0e..9e6aca5 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -185,8 +185,8 @@
ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
# Convert these program parms to lists for easier processing..
- boot_list = filter(None, boot_list.split(":"))
- boot_stack = filter(None, boot_stack.split(":"))
+ boot_list = list(filter(None, boot_list.split(":")))
+ boot_stack = list(filter(None, boot_stack.split(":")))
cleanup_boot_results_file()
boot_results_file_path = create_boot_results_file_path(pgm_name,
@@ -644,7 +644,7 @@
try:
plug_in_ffdc_list = \
open(ffdc_list_file_path, 'r').read().rstrip("\n").split("\n")
- plug_in_ffdc_list = filter(None, plug_in_ffdc_list)
+ plug_in_ffdc_list = list(filter(None, plug_in_ffdc_list))
except IOError:
plug_in_ffdc_list = []
@@ -1011,19 +1011,10 @@
# Process function parms.
for parm_name in main_func_parm_list:
# Get parm's value.
- cmd_buf = "parm_value = loc_" + parm_name
- exec(cmd_buf)
- gp.dpvar(parm_name)
- gp.dpvar(parm_value)
+ parm_value = eval("loc_" + parm_name)
+ gp.dpvars(parm_name, parm_value)
- if parm_value is None:
- # Parm was not specified by the calling function so set it to its
- # corresponding global value.
- cmd_buf = "loc_" + parm_name + " = BuiltIn().get_variable_value" +\
- "(\"${" + parm_name + "}\")"
- gp.dpissuing(cmd_buf)
- exec(cmd_buf)
- else:
+ if parm_value is not None:
# Save the global value on a stack.
cmd_buf = "save_stack.push(BuiltIn().get_variable_value(\"${" +\
parm_name + "}\"), \"" + parm_name + "\")"
diff --git a/lib/state.py b/lib/state.py
index 78f4cf4..4020b9c 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -151,9 +151,9 @@
standby_match_state = DotDict([('rest', '^1$'),
('chassis', '^Off$'),
('bmc', '^Ready$'),
- ('boot_progress', '^$'),
- ('operating_system', '^$'),
- ('host', '^$')])
+ ('boot_progress', '^Off|Unspecified$'),
+ ('operating_system', '^Inactive$'),
+ ('host', '^Off$')])
# A match state for checking that the system is at "os running".
os_running_match_state = DotDict([('chassis', '^On$'),
@@ -182,14 +182,12 @@
('host', '^$')])
-def return_state_constant(state_name='default'):
+def return_state_constant(state_name='default_state'):
r"""
Return the named state dictionary constant.
"""
- cmd_buf = "state = " + state_name
- exec(cmd_buf)
- return state
+ return eval(state_name)
def anchor_state(state):
@@ -262,8 +260,10 @@
if error_message != "":
BuiltIn().fail(gp.sprint_error(error_message))
- if type(match_state) in (str, unicode):
+ try:
match_state = return_state_constant(match_state)
+ except TypeError:
+ pass
default_match = (match_type == 'and')
for key, match_state_value in match_state.items():
@@ -350,10 +350,9 @@
if os_up:
if 'os_ping' in req_states:
# See if the OS pings.
- cmd_buf = "ping -c 1 -w 2 " + os_host
- if not quiet:
- gp.pissuing(cmd_buf)
- rc, out_buf = commands.getstatusoutput(cmd_buf)
+ rc, out_buf = gc.shell_cmd("ping -c 1 -w 2 " + os_host,
+ print_output=0, show_err=0,
+ ignore_err=1)
if rc == 0:
os_ping = 1
@@ -486,10 +485,9 @@
# Get the component states.
if 'ping' in req_states:
# See if the OS pings.
- cmd_buf = "ping -c 1 -w 2 " + openbmc_host
- if not quiet:
- gp.pissuing(cmd_buf)
- rc, out_buf = commands.getstatusoutput(cmd_buf)
+ rc, out_buf = gc.shell_cmd("ping -c 1 -w 2 " + openbmc_host,
+ print_output=0, show_err=0,
+ ignore_err=1)
if rc == 0:
ping = 1
@@ -497,9 +495,9 @@
# See if the OS pings.
cmd_buf = "ping -c 5 -w 5 " + openbmc_host +\
" | egrep 'packet loss' | sed -re 's/.* ([0-9]+)%.*/\\1/g'"
- if not quiet:
- gp.pissuing(cmd_buf)
- rc, out_buf = commands.getstatusoutput(cmd_buf)
+ rc, out_buf = gc.shell_cmd(cmd_buf,
+ print_output=0, show_err=0,
+ ignore_err=1)
if rc == 0:
packet_loss = out_buf.rstrip("\n")
@@ -509,14 +507,10 @@
remote_cmd_buf = "read uptime filler 2>/dev/null < /proc/uptime" +\
" && [ ! -z \"${uptime}\" ] && echo ${uptime}"
cmd_buf = ["BMC Execute Command",
- re.sub('\\$', '\\$', remote_cmd_buf), 'quiet=1']
- if not quiet:
- # Get loc_test_mode parm for improved output on pissuing.
- # See sprint_issuing in gen_print.py for details.
- loc_test_mode = int(gp.get_var_value(var_name="test_mode",
- default=0))
- grp.rpissuing_keyword(cmd_buf, loc_test_mode)
- gp.pissuing(remote_cmd_buf, loc_test_mode)
+ re.sub('\\$', '\\$', remote_cmd_buf), 'quiet=1',
+ 'test_mode=0']
+ gp.print_issuing(cmd_buf, 0)
+ gp.print_issuing(remote_cmd_buf, 0)
try:
stdout, stderr, rc =\
BuiltIn().wait_until_keyword_succeeds("10 sec", "0 sec",
@@ -568,10 +562,12 @@
for url_path in ret_values:
for attr_name in ret_values[url_path]:
# Create a state key value based on the attr_name.
- if isinstance(ret_values[url_path][attr_name], unicode):
+ try:
ret_values[url_path][attr_name] = \
re.sub(r'.*\.', "",
ret_values[url_path][attr_name])
+ except TypeError:
+ pass
# Do some key name manipulations.
new_attr_name = re.sub(r'^Current|(State|Transition)$',
"", attr_name)
@@ -751,8 +747,10 @@
quiet = int(gp.get_var_value(quiet, 0))
- if type(match_state) in (str, unicode):
+ try:
match_state = return_state_constant(match_state)
+ except TypeError:
+ pass
if not quiet:
if invert:
diff --git a/lib/utilities.py b/lib/utilities.py
index 5093333..ae3ad24 100755
--- a/lib/utilities.py
+++ b/lib/utilities.py
@@ -118,7 +118,7 @@
def main():
- print get_vpd_inventory_list('../data/Palmetto.py', 'DIMM')
+ print(get_vpd_inventory_list('../data/Palmetto.py', 'DIMM'))
if __name__ == "__main__":