blob: 8177f63be96b59ab731b186821ac071adffdcfe8 [file] [log] [blame]
George Keishingb88df3d2017-01-10 07:28:08 -06001*** Settings ***
George Keishingbec365b2017-01-19 01:28:41 -06002Resource ../lib/utils.robot
3Variables ../data/variables.py
George Keishingb88df3d2017-01-10 07:28:08 -06004
5*** Variables ***
6
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -06007${BMC_READY_STATE} Ready
8${BMC_NOT_READY_STATE} NotReady
George Keishingb88df3d2017-01-10 07:28:08 -06009${QUIET} ${0}
10
George Keishing43a021f2017-01-30 11:10:13 -060011# "0" indicates that the new "xyz" interface should be used.
12${OBMC_STATES_VERSION} ${0}
13
George Keishingb88df3d2017-01-10 07:28:08 -060014*** 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
36Is Host Running
37 [Documentation] Check if Chassis and Host state is ON.
38 ${power_state}= Get Chassis Power State
George Keishing59d6cb42017-01-19 08:26:03 -060039 Should Be Equal On ${power_state}
George Keishingb88df3d2017-01-10 07:28:08 -060040 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -060041 Should Be Equal Running ${host_state}
George Keishingb88df3d2017-01-10 07:28:08 -060042
43
44Is Host Off
45 [Documentation] Check if Chassis and Host state is OFF.
46 ${power_state}= Get Chassis Power State
George Keishing59d6cb42017-01-19 08:26:03 -060047 Should Be Equal Off ${power_state}
George Keishingb88df3d2017-01-10 07:28:08 -060048 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -060049 Should Be Equal Off ${host_state}
George Keishingb88df3d2017-01-10 07:28:08 -060050
51
52Get Host State
53 [Documentation] Return the state of the host as a string.
54 [Arguments] ${quiet}=${QUIET}
55 # quiet - Suppress REST output logging to console.
56 ${state}=
57 ... Read Attribute ${HOST_STATE_URI} CurrentHostState
58 ... quiet=${quiet}
George Keishing59d6cb42017-01-19 08:26:03 -060059 [Return] ${state.rsplit('.', 1)[1]}
George Keishingb88df3d2017-01-10 07:28:08 -060060
61
62Get Chassis Power State
63 [Documentation] Return the power state of the Chassis
64 ... as a string.
65 [Arguments] ${quiet}=${QUIET}
66 # quiet - Suppress REST output logging to console.
67 ${state}=
68 ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState
69 ... quiet=${quiet}
George Keishing59d6cb42017-01-19 08:26:03 -060070 [Return] ${state.rsplit('.', 1)[1]}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -060071
72
73Get BMC State
74 [Documentation] Return the state of the BMC.
75 [Arguments] ${quiet}=${QUIET}
76 # quiet - Suppress REST output logging to console.
77 ${state}=
78 ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet}
79 [Return] ${state.rsplit('.', 1)[1]}
80
81
82Put BMC State
83 [Documentation] Put BMC in given state.
84 [Arguments] ${expected_state}
85 # expected_state - expected BMC state
86
87 ${bmc_state}= Get BMC State
88 Run Keyword If '${bmc_state}' == '${expected_state}'
89 ... Log BMC is already in ${expected_state} state
90 ... ELSE Run Keywords Initiate BMC Reboot AND
91 ... Wait for BMC state ${expected_state}
92
93
94Initiate BMC Reboot
95 [Documentation] Initiate BMC reboot.
96 ${args}= Create Dictionary data=${BMC_REBOOT_TRANS}
97 Write Attribute
98 ... ${BMC_STATE_URI} RequestedBMCTransition data=${args}
99
100 ${session_active}= Check If BMC Reboot Is Initiated
101 Run Keyword If '${session_active}' == '${True}'
102 ... Fail msg=BMC Reboot didn't occur
103
104 Check If BMC is Up
105
106Check If BMC Reboot Is Initiated
107 [Documentation] Checks whether BMC Reboot is initiated by checking
108 ... BMC connection loss.
109 # Reboot adds 3 seconds delay before forcing reboot
110 # To minimize race conditions, we wait for 7 seconds
111 Sleep 7s
112 ${alive}= Run Keyword and Return Status
113 ... Open Connection And Log In
114 Return From Keyword If '${alive}' == '${False}' ${False}
115 [Return] ${True}
116
117Is BMC Ready
118 [Documentation] Check if BMC state is Ready.
119 ${bmc_state}= Get BMC State
120 Should Be Equal ${BMC_READY_STATE} ${bmc_state}
121
122Is BMC Not Ready
123 [Documentation] Check if BMC state is Not Ready.
124 ${bmc_state}= Get BMC State
125 Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state}
126
127Wait for BMC state
128 [Documentation] Wait until given BMC state is reached.
129 [Arguments] ${state}
130 # state - BMC state to wait for
131 Run Keyword If '${state}' == '${BMC_READY_STATE}'
132 ... Wait Until Keyword Succeeds
133 ... 10 min 10 sec Is BMC Ready
134 ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}'
135 ... Wait Until Keyword Succeeds
136 ... 10 min 10 sec Is BMC Not Ready
137 ... ELSE Fail msg=Invalid BMC state
George Keishing43a021f2017-01-30 11:10:13 -0600138
139
140Set State Interface Version
141 [Documentation] Set version to indicate which interface to use.
142 ${resp}= Openbmc Get Request ${CONTROL_URI}chassis0
143 ${status}= Run Keyword And Return Status
144 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
145 Run Keyword If '${status}' == '${True}'
146 ... Set Global Variable ${OBMC_STATES_VERSION} ${1}
147 ... ELSE
148 ... Set Global Variable ${OBMC_STATES_VERSION} ${0}
149
150
151Power Off Request
152 [Documentation] Select appropriate poweroff keyword.
153 Run Keyword If '${OBMC_STATES_VERSION}' == '${1}'
154 ... Initiate Power Off
155 ... ELSE
156 ... Initiate Host PowerOff
157
158
159Wait For BMC Ready
160 [Documentation] Check BMC state and wait for BMC Ready.
161 @{states}= Create List BMC_READY HOST_POWERED_OFF
162 Run Keyword If '${OBMC_STATES_VERSION}' == '${1}'
163 ... Wait Until Keyword Succeeds 10 min 10 sec
164 ... Verify BMC State ${states}
165 ... ELSE
166 ... Wait Until Keyword Succeeds 10 min 10 sec
167 ... Is BMC Ready
168
169