blob: 219f9510af88cbdadfb23c376584fcf59e2c2326 [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}
192 Return From Keyword If '${l_ping}' == '${False}' ${False}
193
194 ${l_rest} = Run Keyword And Return Status
195 ... Initialize OpenBMC
196 Return From Keyword If '${l_rest}' == '${False}' ${False}
197
198 # Just to make sure the SSH is working for SCP
199 Open Connection And Log In
200 ${system} ${stderr}= Execute Command hostname return_stderr=True
201 Should Be Empty ${stderr}
202
203 [return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500204
205Check If warmReset is Initiated
206 [Documentation] Ping would be still alive, so try SSH to connect
207 ... if fails the ports are down indicating reboot
208 ... is in progress
209 ${alive}= Run Keyword and Return Status
210 ... Open Connection And Log In
211 Return From Keyword If '${alive}' == '${False}' ${False}
212 [return] ${True}
213
George Keishing06ae4aa2016-08-30 01:41:28 -0500214Flush REST Sessions
215 [Documentation] Removes all the active session objects
216 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500217
Sivas SRRe1143ae2016-08-26 22:31:02 -0500218Initialize DBUS cmd
219 [Documentation] Initialize dbus string with property string to extract
220 [arguments] ${boot_property}
221 ${cmd} = Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
222 ${cmd} = Catenate ${cmd}${boot_property}
223 Set Global Variable ${dbuscmd} ${cmd}
224
George Keishing30c12ff2016-09-02 10:25:29 -0500225
226Start SOL Console Logging
227 [Documentation] Start logging to a file in /tmp so that it can
228 ... be read by any other test cases. Stop existing
229 ... running client processes if there is any.
230 ... By default logging at /tmp/obmc-console.log else
231 ... user input location.
232 ... The File is appended with datetime and pid of
233 ... process which created this log file.
234 [Arguments] ${file_path}=/tmp/obmc-console.log
235
236 Open Connection And Log In
237
238 ${cur_time}= Get Time Stamp
239 Set Global Variable ${LOG_TIME} ${cur_time}
240 Start Command
241 ... obmc-console-client > ${file_path}-${LOG_TIME}_$$
242
243
244Stop SOL Console Logging
245 [Documentation] Login to BMC and Stop the obmc-console-client process.
246 ... Find the pids from the log to filter the one started by
247 ... specific test datetime and stop that process only.
248 ... Ignore if there is no process running and return message
249 ... "No obmc-console-client process running"
250 ... By default retrieving log from /tmp/obmc-console.log else
251 ... user input location.
252 [Arguments] ${file_path}=/tmp/obmc-console.log
253
254 Open Connection And Log In
255
256 ${pid} ${stderr} =
257 ... Execute Command
258 ... ls ${file_path}-${LOG_TIME}_* | cut -d'_' -f 2
259 ... return_stderr=True
260 Return From Keyword If '${pid}' == '${EMPTY}'
261 ... No obmc-console-client process running
262 Should Be Empty ${stderr}
263
264 ${console} ${stderr}=
265 ... Execute Command kill -s KILL ${pid}
266 ... return_stderr=True
267 Should Be Empty ${stderr}
268 Log Current Client PID:${pid}
269
270 ${console} ${stderr}=
271 ... Execute Command
272 ... cat ${file_path}-${LOG_TIME}_${pid}
273 ... return_stderr=True
274 Should Be Empty ${stderr}
275
276 [Return] ${console}
277
278
279Get Time Stamp
280 [Documentation] Get the current time stamp data
281 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
282 [return] ${cur_time}
283