Fix python3.x backward changes

Change-Id: Ia33d10935faa2306b19fa6082a1df8a2240ebf83
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
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: