Fixed 'REST Power Off' failure loop.

If a user calls 'REST Power On' with the system in a powered on state,
obmc boot test will first do a 'REST Power Off' to transition to valid
state to do the 'REST Power On'.  Previously, if the 'REST Power Off'
fails, obmc boot test, would try another and another ad infinitum.

This change has obmc boot test popping the stack if the transitional
boot fails.

This new message will be generated in this scenario:

The prior 'REST Power Off' was chosen to transition to a valid state
for 'REST Power On' which was at the top of the boot_stack.  Since
the 'REST Power Off' failed, the 'REST Power On' has been removed
from the stack to avoid and endless failure loop.

Change-Id: I336caa2755dc3195d8e97a6aa38a843787ea1955
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 8c76f84..b1cb8e6 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -338,9 +338,12 @@
     """
 
     global cp_setup_called
+    global transitional_boot_selected
 
     gp.qprintn()
 
+    transitional_boot_selected = False
+
     robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
     repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
     # If we can't find process_plug_in_packages.py, ssh_pw or
@@ -506,13 +509,27 @@
     state  The state of the machine.
     """
 
+    global transitional_boot_selected
     global boot_stack
 
     gp.qprint_timen("Selecting a boot test.")
 
+    if transitional_boot_selected and not boot_success:
+        prior_boot = next_boot
+        boot_candidate = boot_stack.pop()
+        gp.qprint_timen("The prior '" + next_boot + "' was chosen to" +
+                        " transition to a valid state for '" + boot_candidate +
+                        "' which was at the top of the boot_stack.  Since" +
+                        " the '" + next_boot + "' failed, the '" +
+                        boot_candidate + "' has been removed from the stack" +
+                        " to avoid and endless failure loop.")
+        if len(boot_stack) == 0:
+            return ""
+
     my_get_state()
     valid_state()
 
+    transitional_boot_selected = False
     stack_popped = 0
     if len(boot_stack) > 0:
         stack_popped = 1
@@ -555,6 +572,7 @@
             gp.qprint_varx("boot_table[" + boot_candidate + "][start]",
                            boot_table[boot_candidate]['start'], 1)
             boot_stack.append(boot_candidate)
+            transitional_boot_selected = True
             popped_boot = boot_candidate
 
     # Loop through your list selecting a boot_candidates