New BMC state related interfaces
The changes introduce the following:
- New keywords to check and put BMC in required state.
Change-Id: Icbdc8ccf494f5921b7cc7971ee936f372c0c813a
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/data/variables.py b/data/variables.py
index c0340bb..55eb8c0 100644
--- a/data/variables.py
+++ b/data/variables.py
@@ -18,6 +18,8 @@
TIME_MANAGER_URI = OPENBMC_BASE_URI + 'TimeManager/'
# State Manager base variables.
+BMC_REBOOT_TRANS = 'xyz.openbmc_project.State.BMC.Transition.Reboot'
+
HOST_POWEROFF_TRANS = 'xyz.openbmc_project.State.Host.Transition.Off'
HOST_POWERON_TRANS = 'xyz.openbmc_project.State.Host.Transition.On'
HOST_POWEROFF_STATE = 'xyz.openbmc_project.State.Host.HostState.Off'
diff --git a/lib/state_manager.robot b/lib/state_manager.robot
index 0ff1456..97533dc 100755
--- a/lib/state_manager.robot
+++ b/lib/state_manager.robot
@@ -4,6 +4,8 @@
*** Variables ***
+${BMC_READY_STATE} Ready
+${BMC_NOT_READY_STATE} NotReady
${QUIET} ${0}
*** Keywords ***
@@ -63,3 +65,70 @@
... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState
... quiet=${quiet}
[Return] ${state.rsplit('.', 1)[1]}
+
+
+Get BMC State
+ [Documentation] Return the state of the BMC.
+ [Arguments] ${quiet}=${QUIET}
+ # quiet - Suppress REST output logging to console.
+ ${state}=
+ ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet}
+ [Return] ${state.rsplit('.', 1)[1]}
+
+
+Put BMC State
+ [Documentation] Put BMC in given state.
+ [Arguments] ${expected_state}
+ # expected_state - expected BMC state
+
+ ${bmc_state}= Get BMC State
+ Run Keyword If '${bmc_state}' == '${expected_state}'
+ ... Log BMC is already in ${expected_state} state
+ ... ELSE Run Keywords Initiate BMC Reboot AND
+ ... Wait for BMC state ${expected_state}
+
+
+Initiate BMC Reboot
+ [Documentation] Initiate BMC reboot.
+ ${args}= Create Dictionary data=${BMC_REBOOT_TRANS}
+ Write Attribute
+ ... ${BMC_STATE_URI} RequestedBMCTransition data=${args}
+
+ ${session_active}= Check If BMC Reboot Is Initiated
+ Run Keyword If '${session_active}' == '${True}'
+ ... Fail msg=BMC Reboot didn't occur
+
+ Check If BMC is Up
+
+Check If BMC Reboot Is Initiated
+ [Documentation] Checks whether BMC Reboot is initiated by checking
+ ... BMC connection loss.
+ # Reboot adds 3 seconds delay before forcing reboot
+ # To minimize race conditions, we wait for 7 seconds
+ Sleep 7s
+ ${alive}= Run Keyword and Return Status
+ ... Open Connection And Log In
+ Return From Keyword If '${alive}' == '${False}' ${False}
+ [Return] ${True}
+
+Is BMC Ready
+ [Documentation] Check if BMC state is Ready.
+ ${bmc_state}= Get BMC State
+ Should Be Equal ${BMC_READY_STATE} ${bmc_state}
+
+Is BMC Not Ready
+ [Documentation] Check if BMC state is Not Ready.
+ ${bmc_state}= Get BMC State
+ Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state}
+
+Wait for BMC state
+ [Documentation] Wait until given BMC state is reached.
+ [Arguments] ${state}
+ # state - BMC state to wait for
+ Run Keyword If '${state}' == '${BMC_READY_STATE}'
+ ... Wait Until Keyword Succeeds
+ ... 10 min 10 sec Is BMC Ready
+ ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}'
+ ... Wait Until Keyword Succeeds
+ ... 10 min 10 sec Is BMC Not Ready
+ ... ELSE Fail msg=Invalid BMC state