Use new interfaces to check BMC state

This change fix includes:
    - Renaming Get BMC State of utils.robot with Deprecated as Suffix
    - Import state manager file for using new Get BMC State
    - Addedd 'Is OS Starting' Keyword to check boot progress state

Resolves  openbmc/openbmc-test-automation#307

Change-Id: I32a3da98de4100f324bbc5704f14a4f4e59980e6
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/extended/standby_bmc.robot b/extended/standby_bmc.robot
index b6e2074..995ed01 100644
--- a/extended/standby_bmc.robot
+++ b/extended/standby_bmc.robot
@@ -5,7 +5,8 @@
 ...                  - BMC is communicating
 ...                   (pinging, sshing and REST commands working)
 ...                  - Power state is 0 (off)
-...                  - BMC state is "BMC_READY" or "HOST_POWERED_OFF"
+...                  - BMC state is "Ready"
+...                  - HOST state is "Off"
 ...                  - Boot policy is "RESTORE_LAST_STATE"
 ...               Power cycle system via PDU if specified
 ...               Prune archived journal logs
@@ -13,6 +14,7 @@
 Resource          ../lib/boot/boot_resource_master.robot
 Resource          ../lib/utils.robot
 Resource          ../lib/pdu/pdu.robot
+Resource          ../lib/state_manager.robot
 
 *** Variables ***
 ${HOST_SETTING}      /org/openbmc/settings/host0
@@ -20,38 +22,35 @@
 *** Test Cases ***
 
 Get To Stable State
-    [Documentation]    BMC cleanup drive to stable state
-    ...                1. PDU powercycle if specified
-    ...                1. Ping Test
-    ...                2. SSH Connection session Test
-    ...                3. REST Connection session Test
-    ...                4. Reboot BMC if REST Test failed
-    ...                5. Check BMC state for standby
-    ...                6. Issue poweroff if not already in
-    ...                   standby state
-    ...                7. Update restore policy
+    [Documentation]  BMC cleanup drive to stable state
+    ...              1. PDU powercycle if specified
+    ...              1. Ping Test
+    ...              2. SSH Connection session Test
+    ...              3. REST Connection session Test
+    ...              4. Reboot BMC if REST Test failed
+    ...              5. Get BMC in Ready state if its not in this state
+    ...              6. Get Host in Off state if its not in this state
+    ...              7. Update restore policy
     [Tags]  Get_To_Stable_State
 
-    Run Keyword And Ignore Error   Powercycle System Via PDU
+    Run Keyword And Ignore Error  Powercycle System Via PDU
 
     Wait For Host To Ping  ${OPENBMC_HOST}  1 mins
-    Open Connection And Log In   host=${OPENBMC_HOST}
+    Open Connection And Log In  host=${OPENBMC_HOST}
 
-    ${l_rest}=   Run Keyword And Return Status
-    ...    Initialize OpenBMC
-    Run Keyword If  '${l_rest}' == '${False}'
-    ...    Reboot and Wait for BMC Online
+    ${rest_status}=  Run Keyword And Return Status  Initialize OpenBMC
+    Run Keyword If  '${rest_status}' == '${False}'
+    ...  Reboot and Wait for BMC Online
 
-    ${l_ready}=   Run Keyword And Return Status
-    ...    Get BMC State and Expect Standby
+    ${ready_status}=  Run Keyword And Return Status  Is BMC Ready
+    Run Keyword If  '${ready_status}' == '${False}'  Put BMC State  Ready
 
-    Run Keyword If  '${l_ready}' == '${False}'
-    ...    Initiate Power Off
+    ${hostoff_status}=  Run Keyword And Return Status  Is Host Off
+    Run Keyword If  '${hostoff_status}' == '${False}'  Initiate Host PowerOff
 
     Prune Journal Log
 
-    Run Keyword And Ignore Error
-    ...   Update Policy Setting   RESTORE_LAST_STATE
+    Run Keyword And Ignore Error  Update Policy Setting  RESTORE_LAST_STATE
 
 
 *** Keywords ***
@@ -84,14 +83,6 @@
     ...    10 min   10 sec   Verify BMC State   ${states}
 
 
-Get BMC State and Expect Standby
-    [Documentation]   Get BMC state and should be at standby
-
-    @{states}=     Create List   BMC_READY   HOST_POWERED_OFF
-    ${bmc_state}=  Get BMC State
-    Should Contain  ${states}   ${bmc_state}
-
-
 Update Policy Setting
     [Documentation]   Update the given restore policy
     [Arguments]   ${policy}
diff --git a/lib/utils.robot b/lib/utils.robot
index 418f2c6..d4297f8 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -181,7 +181,7 @@
 
     rqprint_timen  The operating system is now communicating.
 
-Get BMC State
+Get BMC State Deprecated
     [Documentation]  Returns the state of the BMC as a string. (i.e: BMC_READY)
     [Arguments]  ${quiet}=${QUIET}
 
@@ -251,9 +251,14 @@
 
 Is System State Host Booted
     [Documentation]  Checks whether system state is HOST_BOOTED.
-    ${state}=    Get BMC State
+    ${state}=    Get BMC State Deprecated
     should be equal as strings     ${state}     HOST_BOOTED
 
+Is OS Starting
+    [Documentation]  Check if boot progress is OS starting.
+    ${boot_progress}=  Get Boot Progress
+    Should Be Equal  ${boot_progress}  FW Progress, Starting OS
+
 Verify Ping and REST Authentication
     ${l_ping}=   Run Keyword And Return Status
     ...    Ping Host  ${OPENBMC_HOST}
@@ -375,7 +380,7 @@
     ...               BMC state is as expected.
     [Arguments]       ${expected}
 
-    ${current}=  Get BMC State
+    ${current}=  Get BMC State Deprecated
     Should Contain  ${expected}   ${current}
 
 Start Journal Log
diff --git a/tests/test_time.robot b/tests/test_time.robot
index c91f178..b70edd1 100644
--- a/tests/test_time.robot
+++ b/tests/test_time.robot
@@ -4,6 +4,7 @@
 Resource               ../lib/rest_client.robot
 Resource               ../lib/ipmi_client.robot
 Resource               ../lib/openbmc_ffdc.robot
+Resource               ../lib/state_manager.robot
 Resource               ../lib/resource.txt
 
 Library                OperatingSystem
@@ -250,13 +251,12 @@
     ...  ${SETTING_HOST}/attr/time_owner  data=${valueDict}
     ${jsondata}=  to JSON  ${resp.content}
 
-    @{states}=  Create List  BMC_READY  HOST_POWERED_OFF
-    ${bmc_state}=  Get BMC State
+    ${host_state}=  Get Host State
 
-    Run Keyword If  '${bmc_state}' in ${states}
+    Run Keyword If  '${host_state}' == 'Off'
     ...  Log  System is in off state so owner change will get applied.
     ...  ELSE   Run keyword
-    ...  Initiate Power Off
+    ...  Initiate Host PowerOff
 
     ${owner}=  Read Attribute  ${SETTING_HOST}  time_owner
     Should Be Equal  ${owner}  ${args}