blob: 229b8583951ccff43604f029b428db41ed681c4a [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Resource ../lib/resource.txt
3Resource ../lib/rest_client.robot
George Keishing5e870cd2016-08-24 10:05:47 -05004Resource ../lib/connection_client.robot
George Keishing30c12ff2016-09-02 10:25:29 -05005Library DateTime
6Library Process
Chris Austenb29d2e82016-06-07 12:25:35 -05007Library OperatingSystem
8
9*** Variables ***
10${SYSTEM_SHUTDOWN_TIME} ${5}
Sivas SRRe1143ae2016-08-26 22:31:02 -050011${dbuscmdBase} = dbus-send --system --print-reply --dest=org.openbmc.settings.Host
12${dbuscmdGet} = /org/openbmc/settings/host0 org.freedesktop.DBus.Properties.Get
13${dbuscmdString} = string:"org.openbmc.settings.Host" string:
Chris Austenb29d2e82016-06-07 12:25:35 -050014
15*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050016Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000017 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
18 ... ${interval}=5 sec
19
20 # host The DNS name or IP of the host to ping.
21 # timeout The amount of time after which attempts to ping cease.
22 # interval The amount of time in between attempts to ping.
23
24 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050025
26Ping Host
27 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050028 Should Not Be Empty ${host} msg=No host provided
Chris Austenb29d2e82016-06-07 12:25:35 -050029 ${RC} ${output} = Run and return RC and Output ping -c 4 ${host}
30 Log RC: ${RC}\nOutput:\n${output}
31 Should be equal ${RC} ${0}
32
33Get Boot Progress
34 ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value
35 [return] ${state}
36
37Is Power On
root442f0ef2016-08-04 20:23:05 +000038 ${state}= Get Power State
39 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050040
41Is Power Off
root442f0ef2016-08-04 20:23:05 +000042 ${state}= Get Power State
43 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050044
root442f0ef2016-08-04 20:23:05 +000045Initiate Power On
46 [Documentation] Initiates the power on and waits until the Is Power On
47 ... keyword returns that the power state has switched to on.
Chris Austenb29d2e82016-06-07 12:25:35 -050048 @{arglist}= Create List
49 ${args}= Create Dictionary data=@{arglist}
50 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args}
51 should be equal as strings ${resp.status_code} ${HTTP_OK}
52 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
53
root442f0ef2016-08-04 20:23:05 +000054Initiate Power Off
55 [Documentation] Initiates the power off and waits until the Is Power Off
56 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050057 @{arglist}= Create List
58 ${args}= Create Dictionary data=@{arglist}
59 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args}
60 should be equal as strings ${resp.status_code} ${HTTP_OK}
61 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
62
63Trigger Warm Reset
64 log to console "Triggering warm reset"
65 ${data} = create dictionary data=@{EMPTY}
66 ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data}
67 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050068 ${session_active}= Check If warmReset is Initiated
69 Run Keyword If '${session_active}' == '${True}'
70 ... Fail msg=warm reset didn't occur
71
Chris Austenb29d2e82016-06-07 12:25:35 -050072 Sleep ${SYSTEM_SHUTDOWN_TIME}min
73 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050074
75Check OS
root442f0ef2016-08-04 20:23:05 +000076 [Documentation] Attempts to ping the host OS and then checks that the host
77 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050078
79 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
80 ... ${os_password}=${OS_PASSWORD}
81 [Teardown] Close Connection
82
83 # os_host The DNS name/IP of the OS host associated with our BMC.
84 # os_username The username to be used to sign on to the OS host.
85 # os_password The password to be used to sign on to the OS host.
86
root442f0ef2016-08-04 20:23:05 +000087 # Attempt to ping the OS. Store the return code to check later.
88 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
89
Michael Walsh49ab0f42016-07-20 11:44:33 -050090 Open connection ${os_host}
91 Login ${os_username} ${os_password}
92
93 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
94 ... return_rc=True
95
96 # If the return code returned by "Execute Command" is non-zero, this keyword
97 # will fail.
98 Should Be Equal ${rc} ${0}
99 # We will likewise fail if there is any stderr data.
100 Should Be Empty ${stderr}
101
root442f0ef2016-08-04 20:23:05 +0000102 # We will likewise fail if the OS did not ping, as we could SSH but not ping
103 Should Be Equal As Strings ${ping_rc} ${TRUE}
104
Michael Walsh49ab0f42016-07-20 11:44:33 -0500105Wait for OS
106 [Documentation] Waits for the host OS to come up via calls to "Check OS".
107 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
108 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
109
110 # os_host The DNS name or IP of the OS host associated with our
111 # BMC.
112 # os_username The username to be used to sign on to the OS host.
113 # os_password The password to be used to sign on to the OS host.
114 # timeout The timeout in seconds indicating how long you're
115 # willing to wait for the OS to respond.
116
117 # The interval to be used between calls to "Check OS".
118 ${interval}= Set Variable 5
119
120 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
121 ... ${os_host} ${os_username} ${os_password}
root442f0ef2016-08-04 20:23:05 +0000122
123Get BMC State
124 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
125 @{arglist}= Create List
126 ${args}= Create Dictionary data=@{arglist}
127 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState
128 ... data=${args}
129 Should be equal as strings ${resp.status_code} ${HTTP_OK}
130 ${content}= to json ${resp.content}
131 [return] ${content["data"]}
132
133Get Power State
134 [Documentation] Returns the power state as an integer. Either 0 or 1.
135 @{arglist}= Create List
136 ${args}= Create Dictionary data=@{arglist}
137 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState
138 ... data=${args}
139 Should be equal as strings ${resp.status_code} ${HTTP_OK}
140 ${content}= to json ${resp.content}
141 [return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500142
143Clear BMC Record Log
144 [Documentation] Clears all the event logs on the BMC. This would be
145 ... equivalent to ipmitool sel clear.
146 @{arglist}= Create List
147 ${args}= Create Dictionary data=@{arglist}
148 ${resp}= Call Method /org/openbmc/records/events/ clear data=${args}
149 should be equal as strings ${resp.status_code} ${HTTP_OK}
150
151Copy PNOR to BMC
152 Import Library SCPLibrary WITH NAME scp
153 Open Connection for SCP
154 Log Copying ${PNOR_IMAGE_PATH} to /tmp
155 scp.Put File ${PNOR_IMAGE_PATH} /tmp
156
157Flash PNOR
158 [Documentation] Calls flash bios update method to flash PNOR image
159 [arguments] ${pnor_image}
160 @{arglist}= Create List ${pnor_image}
161 ${args}= Create Dictionary data=@{arglist}
162 ${resp}= Call Method /org/openbmc/control/flash/bios/ update data=${args}
163 should be equal as strings ${resp.status_code} ${HTTP_OK}
164 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
165
166Get Flash BIOS Status
167 [Documentation] Returns the status of the flash BIOS API as a string. For
168 ... example 'Flashing', 'Flash Done', etc
169 ${data}= Read Properties /org/openbmc/control/flash/bios
170 [return] ${data['status']}
171
172Is PNOR Flashing
173 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
174 ... flashing has started.
175 ${status}= Get Flash BIOS Status
176 should be equal as strings ${status} Flashing
177
178Is PNOR Flash Done
179 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
180 ... PNOR flashing has completed.
181 ${status}= Get Flash BIOS Status
182 should be equal as strings ${status} Flash Done
183
184Is System State Host Booted
185 [Documentation] Checks whether system state is HOST_BOOTED.
186 ${state}= Get BMC State
187 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500188
189Verify Ping and REST Authentication
190 ${l_ping} = Run Keyword And Return Status
191 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500192 Run Keyword If '${l_ping}' == '${False}'
193 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500194
195 ${l_rest} = Run Keyword And Return Status
196 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500197 Run Keyword If '${l_rest}' == '${False}'
198 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500199
200 # Just to make sure the SSH is working for SCP
201 Open Connection And Log In
202 ${system} ${stderr}= Execute Command hostname return_stderr=True
203 Should Be Empty ${stderr}
204
George Keishingc4d3dc02016-09-19 03:45:55 -0500205
206Check If BMC is Up
207 [Documentation] Wait for Host to be online. Checks every X seconds
208 ... interval for Y minutes and fails if timed out.
209 ... Default MAX timedout is 10 min, interval 10 seconds.
210 [arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT}
211 ... ${interval}=10 sec
212
213 Wait Until Keyword Succeeds
214 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
215
George Keishingb3700812016-08-31 03:03:30 -0500216
217Check If warmReset is Initiated
218 [Documentation] Ping would be still alive, so try SSH to connect
219 ... if fails the ports are down indicating reboot
220 ... is in progress
221 ${alive}= Run Keyword and Return Status
222 ... Open Connection And Log In
223 Return From Keyword If '${alive}' == '${False}' ${False}
224 [return] ${True}
225
George Keishing06ae4aa2016-08-30 01:41:28 -0500226Flush REST Sessions
227 [Documentation] Removes all the active session objects
228 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500229
Sivas SRRe1143ae2016-08-26 22:31:02 -0500230Initialize DBUS cmd
231 [Documentation] Initialize dbus string with property string to extract
232 [arguments] ${boot_property}
233 ${cmd} = Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
234 ${cmd} = Catenate ${cmd}${boot_property}
235 Set Global Variable ${dbuscmd} ${cmd}
236
George Keishing30c12ff2016-09-02 10:25:29 -0500237
238Start SOL Console Logging
239 [Documentation] Start logging to a file in /tmp so that it can
240 ... be read by any other test cases. Stop existing
241 ... running client processes if there is any.
242 ... By default logging at /tmp/obmc-console.log else
243 ... user input location.
244 ... The File is appended with datetime and pid of
245 ... process which created this log file.
246 [Arguments] ${file_path}=/tmp/obmc-console.log
247
248 Open Connection And Log In
249
250 ${cur_time}= Get Time Stamp
251 Set Global Variable ${LOG_TIME} ${cur_time}
252 Start Command
253 ... obmc-console-client > ${file_path}-${LOG_TIME}_$$
254
255
256Stop SOL Console Logging
257 [Documentation] Login to BMC and Stop the obmc-console-client process.
258 ... Find the pids from the log to filter the one started by
259 ... specific test datetime and stop that process only.
260 ... Ignore if there is no process running and return message
261 ... "No obmc-console-client process running"
262 ... By default retrieving log from /tmp/obmc-console.log else
263 ... user input location.
264 [Arguments] ${file_path}=/tmp/obmc-console.log
265
266 Open Connection And Log In
267
268 ${pid} ${stderr} =
269 ... Execute Command
270 ... ls ${file_path}-${LOG_TIME}_* | cut -d'_' -f 2
271 ... return_stderr=True
George Keishing30c12ff2016-09-02 10:25:29 -0500272 Should Be Empty ${stderr}
273
George Keishingd4678952016-10-12 04:29:28 -0500274 ${rc}=
275 ... Execute Command
276 ... ps ax | grep ${pid} | grep -v grep
277 ... return_stdout=False return_rc=True
278
279 Return From Keyword If '${rc}' == '${1}'
280 ... No obmc-console-client process running
281
George Keishing30c12ff2016-09-02 10:25:29 -0500282 ${console} ${stderr}=
283 ... Execute Command kill -s KILL ${pid}
284 ... return_stderr=True
285 Should Be Empty ${stderr}
George Keishingd4678952016-10-12 04:29:28 -0500286 Log Current Client PID:${pid}
George Keishing30c12ff2016-09-02 10:25:29 -0500287
288 ${console} ${stderr}=
289 ... Execute Command
290 ... cat ${file_path}-${LOG_TIME}_${pid}
291 ... return_stderr=True
292 Should Be Empty ${stderr}
293
294 [Return] ${console}
295
296
297Get Time Stamp
298 [Documentation] Get the current time stamp data
299 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
300 [return] ${cur_time}
301
George Keishing1b150202016-09-29 08:51:58 -0500302
303Verify BMC State
304 [Documentation] Get the BMC state and verify if the current
305 ... BMC state is as expected.
306 [Arguments] ${expected}
307
308 ${current}= Get BMC State
George Keishing8db0e1b2016-10-20 13:46:54 -0500309 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500310