xref: /openbmc/openbmc-test-automation/lib/state_manager.robot (revision 09439a25fbd5173211d1afd3cd28432651f9c5d2)
1*** Settings ***
2Resource          ../lib/utils.robot
3Variables         ../data/variables.py
4
5*** Variables ***
6
7${BMC_READY_STATE}           Ready
8${BMC_NOT_READY_STATE}       NotReady
9${QUIET}  ${0}
10
11# "0" indicates that the new "xyz" interface should be used.
12${OBMC_STATES_VERSION}    ${0}
13
14*** Keywords ***
15
16Initiate Host Boot
17    [Documentation]  Initiate host power on.
18    ${args}=  Create Dictionary   data=${HOST_POWERON_TRANS}
19    Write Attribute
20    ...  ${HOST_STATE_URI}  RequestedHostTransition   data=${args}
21
22    Wait Until Keyword Succeeds
23    ...  10 min  10 sec  Is Host Running
24
25
26Initiate Host PowerOff
27    [Documentation]  Initiate host power off.
28    ${args}=  Create Dictionary   data=${HOST_POWEROFF_TRANS}
29    Write Attribute
30    ...  ${HOST_STATE_URI}  RequestedHostTransition   data=${args}
31
32    Wait Until Keyword Succeeds
33    ...  3 min  10 sec  Is Host Off
34
35
36Initiate Host Reboot
37    [Documentation]  Initiate host reboot via REST.
38
39    ${args}=  Create Dictionary  data=${HOST_REBOOT_TRANS}
40    Write Attribute
41    ...  ${HOST_STATE_URI}  RequestedHostTransition  data=${args}
42    Is Host Rebooted
43
44
45Is Host Running
46    [Documentation]  Check if host state is "Running".
47    ${host_state}=  Get Host State
48    Should Be Equal  Running  ${host_state}
49
50
51Is Host Off
52    [Documentation]  Check if host state is "Off".
53    ${host_state}=  Get Host State
54    Should Be Equal  Off  ${host_state}
55
56
57Is Host Rebooted
58    [Documentation]  Checks if host rebooted.
59
60    ${host_trans_state}=  Get Host Trans State
61    Should Be Equal  ${host_trans_state}  Reboot
62    Is Host Running
63
64
65Is Chassis On
66    [Documentation]  Check if chassis state is "On".
67    ${power_state}=  Get Chassis Power State
68    Should Be Equal  On  ${power_state}
69
70
71Is Chassis Off
72    [Documentation]  Check if chassis state is "Off".
73    ${power_state}=  Get Chassis Power State
74    Should Be Equal  Off  ${power_state}
75
76Is Host Quiesced
77    [Documentation]  Check if host state is quiesced.
78    ${host_state}=  Get Host State
79    Should Be Equal  Quiesced  ${host_state}
80    ${status}=  Run Keyword And Return Status  Should Be Equal
81    ...  ${host_state}  Quiesced
82    [Return]  ${status}
83
84
85Recover Quiesced Host
86    [Documentation]  Recover host from quisced state.
87
88    ${resp}=  Run Keyword And Return Status  Is Host Quiesced
89    Run Keyword If  '${resp}' == 'True'
90    ...  Run Keywords  Initiate Host PowerOff  AND
91    ...  Log  HOST is recovered from quiesced state
92
93
94Get Host State
95    [Documentation]  Return the state of the host as a string.
96    [Arguments]  ${quiet}=${QUIET}
97    # quiet - Suppress REST output logging to console.
98    ${state}=
99    ...  Read Attribute  ${HOST_STATE_URI}  CurrentHostState
100    ...  quiet=${quiet}
101    [Return]  ${state.rsplit('.', 1)[1]}
102
103Get Host Trans State
104    [Documentation]  Return the transition state of host as a string.
105    ...              e.g. On, Off, Reboot
106    [Arguments]  ${quiet}=${QUIET}
107    # Description of arguments:
108    # quiet  Suppress REST output logging to console.
109
110    ${state}=
111    ...  Read Attribute  ${HOST_STATE_URI}  RequestedHostTransition
112    ...  quiet=${quiet}
113    [Return]  ${state.rsplit('.', 1)[1]}
114
115Get Chassis Power State
116    [Documentation]  Return the power state of the Chassis
117    ...              as a string.
118    [Arguments]  ${quiet}=${QUIET}
119    # quiet - Suppress REST output logging to console.
120    ${state}=
121    ...  Read Attribute  ${CHASSIS_STATE_URI}  CurrentPowerState
122    ...  quiet=${quiet}
123    [Return]  ${state.rsplit('.', 1)[1]}
124
125
126Get BMC State
127    [Documentation]  Return the state of the BMC.
128    [Arguments]  ${quiet}=${QUIET}
129    # quiet - Suppress REST output logging to console.
130    ${state}=
131    ...  Read Attribute  ${BMC_STATE_URI}  CurrentBMCState  quiet=${quiet}
132    [Return]  ${state.rsplit('.', 1)[1]}
133
134
135Put BMC State
136    [Documentation]  Put BMC in given state.
137    [Arguments]  ${expected_state}
138    # expected_state - expected BMC state
139
140    ${bmc_state}=  Get BMC State
141    Run Keyword If  '${bmc_state}' == '${expected_state}'
142    ...  Log  BMC is already in ${expected_state} state
143    ...  ELSE  Run Keywords  Initiate BMC Reboot  AND
144    ...  Wait for BMC state  ${expected_state}
145
146
147Initiate BMC Reboot
148    [Documentation]  Initiate BMC reboot.
149    ${args}=  Create Dictionary   data=${BMC_REBOOT_TRANS}
150    Write Attribute
151    ...  ${BMC_STATE_URI}  RequestedBMCTransition   data=${args}
152
153    ${session_active}=   Check If BMC Reboot Is Initiated
154    Run Keyword If   '${session_active}' == '${True}'
155    ...    Fail   msg=BMC Reboot didn't occur
156
157    Check If BMC is Up
158
159Check If BMC Reboot Is Initiated
160    [Documentation]  Checks whether BMC Reboot is initiated by checking
161    ...              BMC connection loss.
162    # Reboot adds 3 seconds delay before forcing reboot
163    # To minimize race conditions, we wait for 7 seconds
164    Sleep  7s
165    ${alive}=   Run Keyword and Return Status
166    ...    Open Connection And Log In
167    Return From Keyword If   '${alive}' == '${False}'    ${False}
168    [Return]    ${True}
169
170Is BMC Ready
171    [Documentation]  Check if BMC state is Ready.
172    ${bmc_state}=  Get BMC State
173    Should Be Equal  ${BMC_READY_STATE}  ${bmc_state}
174
175Is BMC Not Ready
176    [Documentation]  Check if BMC state is Not Ready.
177    ${bmc_state}=  Get BMC State
178    Should Be Equal  ${BMC_NOT_READY_STATE}  ${bmc_state}
179
180Wait for BMC state
181    [Documentation]  Wait until given BMC state is reached.
182    [Arguments]  ${state}
183    # state - BMC state to wait for
184    Run Keyword If  '${state}' == '${BMC_READY_STATE}'
185    ...    Wait Until Keyword Succeeds
186    ...    10 min  10 sec  Is BMC Ready
187    ...  ELSE IF  '${state}' == '${BMC_NOT_READY_STATE}'
188    ...    Wait Until Keyword Succeeds
189    ...    10 min  10 sec  Is BMC Not Ready
190    ...  ELSE  Fail  msg=Invalid BMC state
191
192
193Set State Interface Version
194    [Documentation]  Set version to indicate which interface to use.
195    ${resp}=  Openbmc Get Request  ${CHASSIS_STATE_URI}
196    ${status}=  Run Keyword And Return Status
197    ...  Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
198    Run Keyword If  '${status}' == '${True}'
199    ...  Set Global Variable  ${OBMC_STATES_VERSION}  ${1}
200    ...  ELSE
201    ...  Set Global Variable  ${OBMC_STATES_VERSION}  ${0}
202
203
204Power Off Request
205    [Documentation]  Select appropriate poweroff keyword.
206    Run Keyword If  '${OBMC_STATES_VERSION}' == '${0}'
207    ...  Initiate Power Off
208    ...  ELSE
209    ...  Initiate Host PowerOff
210
211
212Wait For BMC Ready
213    [Documentation]  Check BMC state and wait for BMC Ready.
214    @{states}=  Create List  BMC_READY  HOST_POWERED_OFF
215    Run Keyword If  '${OBMC_STATES_VERSION}' == '${0}'
216    ...  Wait Until Keyword Succeeds  10 min  10 sec
217    ...  Verify BMC State  ${states}
218    ...  ELSE
219    ...  Wait Until Keyword Succeeds  10 min  10 sec
220    ...  Is BMC Ready
221
222
223