Changes to support Redfish boot progress

Signed-off-by: Michael Shepos <shepos@us.ibm.com>
Change-Id: Icfe34896b5801f13a344b6a3983696796dc476cb
diff --git a/lib/boot_data.py b/lib/boot_data.py
index e644166..42af3f7 100755
--- a/lib/boot_data.py
+++ b/lib/boot_data.py
@@ -26,6 +26,9 @@
 # The code base directory will be one level up from the directory containing this module.
 code_base_dir_path = os.path.dirname(os.path.dirname(__file__)) + os.sep
 
+redfish_support_trans_state = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \
+    int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0))
+
 
 def create_boot_table(file_path=None,
                       os_host=""):
@@ -47,7 +50,10 @@
                                     boot entries.
     """
     if file_path is None:
-        file_path = os.environ.get('BOOT_TABLE_PATH', 'data/boot_table.json')
+        if redfish_support_trans_state:
+            file_path = os.environ.get('BOOT_TABLE_PATH', 'data/boot_table_redfish.json')
+        else:
+            file_path = os.environ.get('BOOT_TABLE_PATH', 'data/boot_table.json')
 
     if not file_path.startswith("/"):
         file_path = code_base_dir_path + file_path
diff --git a/lib/state.py b/lib/state.py
index fa5d929..61223f0 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -78,6 +78,9 @@
 
 OBMC_STATES_VERSION = int(os.environ.get('OBMC_STATES_VERSION', 1))
 
+redfish_support_trans_state = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \
+    int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0))
+
 # When a user calls get_state w/o specifying req_states, default_req_states
 # is used as its value.
 default_req_states = ['rest',
@@ -90,9 +93,13 @@
                       'os_login',
                       'os_run_cmd']
 
+if redfish_support_trans_state:
+    default_req_states.remove('operating_system')
+
 # valid_req_states is a list of sub states supported by the get_state function.
 # valid_req_states, default_req_states and master_os_up_match are used by the
 # get_state function.
+
 valid_req_states = ['ping',
                     'packet_loss',
                     'uptime',
@@ -131,50 +138,91 @@
 USE_BMC_EPOCH_TIME = int(os.environ.get('USE_BMC_EPOCH_TIME', 0))
 
 # Useful state constant definition(s).
-# default_state is an initial value which may be of use to callers.
-default_state = DotDict([('rest', '1'),
-                         ('chassis', 'On'),
-                         ('bmc', 'Ready'),
-                         ('boot_progress', 'OSStart'),
-                         ('operating_system', 'BootComplete'),
-                         ('host', 'Running'),
-                         ('os_ping', '1'),
-                         ('os_login', '1'),
-                         ('os_run_cmd', '1')])
+if not redfish_support_trans_state:
+    # default_state is an initial value which may be of use to callers.
+    default_state = DotDict([('rest', '1'),
+                             ('chassis', 'On'),
+                             ('bmc', 'Ready'),
+                             ('boot_progress', 'OSStart'),
+                             ('operating_system', 'BootComplete'),
+                             ('host', 'Running'),
+                             ('os_ping', '1'),
+                             ('os_login', '1'),
+                             ('os_run_cmd', '1')])
 
-# A match state for checking that the system is at "standby".
-standby_match_state = DotDict([('rest', '^1$'),
-                               ('chassis', '^Off$'),
-                               ('bmc', '^Ready$'),
-                               ('boot_progress', '^Off|Unspecified$'),
-                               ('operating_system', '^Inactive$'),
-                               ('host', '^Off$')])
+    # A match state for checking that the system is at "standby".
+    standby_match_state = DotDict([('rest', '^1$'),
+                                   ('chassis', '^Off$'),
+                                   ('bmc', '^Ready$'),
+                                   ('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$'),
+    # A match state for checking that the system is at "os running".
+    os_running_match_state = DotDict([('chassis', '^On$'),
+                                      ('bmc', '^Ready$'),
+                                      ('boot_progress',
+                                       'FW Progress, Starting OS|OSStart'),
+                                      ('operating_system', 'BootComplete'),
+                                      ('host', '^Running$'),
+                                      ('os_ping', '^1$'),
+                                      ('os_login', '^1$'),
+                                      ('os_run_cmd', '^1$')])
+
+    # A master dictionary to determine whether the os may be up.
+    master_os_up_match = DotDict([('chassis', '^On$'),
                                   ('bmc', '^Ready$'),
                                   ('boot_progress',
                                    'FW Progress, Starting OS|OSStart'),
                                   ('operating_system', 'BootComplete'),
-                                  ('host', '^Running$'),
-                                  ('os_ping', '^1$'),
-                                  ('os_login', '^1$'),
-                                  ('os_run_cmd', '^1$')])
+                                  ('host', '^Running|Quiesced$')])
 
-# A master dictionary to determine whether the os may be up.
-master_os_up_match = DotDict([('chassis', '^On$'),
-                              ('bmc', '^Ready$'),
-                              ('boot_progress',
-                               'FW Progress, Starting OS|OSStart'),
-                              ('operating_system', 'BootComplete'),
-                              ('host', '^Running|Quiesced$')])
+    invalid_state_match = DotDict([('rest', '^$'),
+                                   ('chassis', '^$'),
+                                   ('bmc', '^$'),
+                                   ('boot_progress', '^$'),
+                                   ('operating_system', '^$'),
+                                   ('host', '^$')])
+else:
+    # default_state is an initial value which may be of use to callers.
+    default_state = DotDict([('rest', '1'),
+                             ('chassis', 'On'),
+                             ('bmc', 'Ready'),
+                             ('boot_progress', 'SystemInitComplete|OSRunning'),
+                             ('host', 'Running'),
+                             ('os_ping', '1'),
+                             ('os_login', '1'),
+                             ('os_run_cmd', '1')])
 
-invalid_state_match = DotDict([('rest', '^$'),
-                               ('chassis', '^$'),
-                               ('bmc', '^$'),
-                               ('boot_progress', '^$'),
-                               ('operating_system', '^$'),
-                               ('host', '^$')])
+    # A match state for checking that the system is at "standby".
+    standby_match_state = DotDict([('rest', '^1$'),
+                                   ('chassis', '^Off$'),
+                                   ('bmc', '^Ready$'),
+                                   ('boot_progress', '^Off|Unspecified$'),
+                                   ('host', '^Off$')])
+
+    # A match state for checking that the system is at "os running".
+    os_running_match_state = DotDict([('chassis', '^On$'),
+                                      ('bmc', '^Ready$'),
+                                      ('boot_progress',
+                                       'SystemInitComplete|OSRunning'),
+                                      ('host', '^Running$'),
+                                      ('os_ping', '^1$'),
+                                      ('os_login', '^1$'),
+                                      ('os_run_cmd', '^1$')])
+
+    # A master dictionary to determine whether the os may be up.
+    master_os_up_match = DotDict([('chassis', '^On$'),
+                                  ('bmc', '^Ready$'),
+                                  ('boot_progress',
+                                   'SystemInitComplete|OSRunning'),
+                                  ('host', '^Running|Quiesced$')])
+
+    invalid_state_match = DotDict([('rest', '^$'),
+                                   ('chassis', '^$'),
+                                   ('bmc', '^$'),
+                                   ('boot_progress', '^$'),
+                                   ('host', '^$')])
 
 
 def return_state_constant(state_name='default_state'):