blob: df00d2d9eaf7fd7328a562b098b267dddb17ad7f [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
Michael Walsha6723f22016-11-22 11:12:01 -06008Library gen_print.py
9Library gen_robot_print.py
Michael Walsh5f3f4142017-05-22 17:09:47 -050010Library gen_cmd.py
Sunil Macd110a2017-05-23 04:14:32 -050011Library gen_robot_keyword.py
Michael Walshe53e47a2017-06-30 17:03:24 -050012Library bmc_ssh_utils.py
Michael Walshfdc5ced2017-08-17 13:15:15 -050013Library utils.py
Chris Austenb29d2e82016-06-07 12:25:35 -050014
15*** Variables ***
Sivas SRRd97aa9c2017-05-22 11:19:25 -050016${pflash_cmd} /usr/sbin/pflash -r /dev/stdout -P VERSION
Chris Austenb29d2e82016-06-07 12:25:35 -050017${SYSTEM_SHUTDOWN_TIME} ${5}
Michael Walsha6723f22016-11-22 11:12:01 -060018${dbuscmdBase}
George Keishing85ca05e2016-11-30 09:47:18 -060019... dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host
Michael Walsha6723f22016-11-22 11:12:01 -060020${dbuscmdGet}
George Keishing9485af92017-01-04 10:21:43 -060021... ${SETTINGS_URI}host0 org.freedesktop.DBus.Properties.Get
George Keishing85ca05e2016-11-30 09:47:18 -060022# Enable when ready with openbmc/openbmc-test-automation#203
23#${dbuscmdString}= string:"xyz.openbmc_project.settings.Host" string:
Michael Walsha6723f22016-11-22 11:12:01 -060024${dbuscmdString}= string:"org.openbmc.settings.Host" string:
25
26# Assign default value to QUIET for programs which may not define it.
27${QUIET} ${0}
Sivas SRRea85d1f2016-11-13 22:44:28 -060028${bmc_mem_free_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
29${bmc_mem_total_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
30${bmc_cpu_usage_cmd}= top -n 1 | grep CPU: | cut -c 7-9
Sridevi Ramesh1699d372016-12-06 00:20:22 -060031${HOST_SETTING} ${SETTINGS_URI}host0
Sivas SRR352bc162017-02-13 22:12:29 -060032# /run/initramfs/ro associate filesystem should be 100% full always
Sivas SRRaca55712016-12-21 04:32:35 -060033${bmc_file_system_usage_cmd}=
Sivas SRR352bc162017-02-13 22:12:29 -060034... df -h | grep -v /run/initramfs/ro | cut -c 52-54 | grep 100 | wc -l
Chris Austenb29d2e82016-06-07 12:25:35 -050035
George Keishingcce9df22017-01-24 06:19:33 -060036${BOOT_TIME} ${0}
37${BOOT_COUNT} ${0}
Sweta Potthuri025e0122017-02-21 00:42:48 -060038${count} ${0}
Sivas SRR8254db62017-02-07 09:39:46 -060039${devicetree_base} /sys/firmware/devicetree/base/model
George Keishingcce9df22017-01-24 06:19:33 -060040
George Keishingb7c9b542017-05-23 08:19:58 -050041# Initialize default debug value to 0.
42${DEBUG} ${0}
43
Michael Walshfdc5ced2017-08-17 13:15:15 -050044# These variables are used to straddle between new and old methods of setting
45# values.
Michael Walshc972d4d2017-08-16 15:38:03 -050046${boot_prog_method} ${EMPTY}
47
Michael Walshfdc5ced2017-08-17 13:15:15 -050048${power_policy_setup} ${0}
49${bmc_power_policy_method} ${EMPTY}
50@{valid_power_policy_vars} RESTORE_LAST_STATE ALWAYS_POWER_ON
51... ALWAYS_POWER_OFF
52
Chris Austenb29d2e82016-06-07 12:25:35 -050053*** Keywords ***
Sridevi Ramesh1699d372016-12-06 00:20:22 -060054
Sivas SRRd97aa9c2017-05-22 11:19:25 -050055Verify PNOR Update
56 [Documentation] Verify that the PNOR is not corrupted.
57 # Example:
58 # FFS: Flash header not found. Code: 100
59 # Error 100 opening ffs !
60
61 Open Connection And Log In
62 ${pnor_info}= Execute Command On BMC ${pflash_cmd}
63 Should Not Contain Any ${pnor_info} Flash header not found Error
64
Sivas SRR8254db62017-02-07 09:39:46 -060065Get BMC System Model
66 [Documentation] Get the BMC model from the device tree.
67
Michael Walshe53e47a2017-06-30 17:03:24 -050068 ${bmc_model} ${stderr} ${rc}= BMC Execute Command
George Keishing90ab1772017-02-24 05:40:55 -060069 ... cat ${devicetree_base} | cut -d " " -f 1 return_stderr=True
Sivas SRR8254db62017-02-07 09:39:46 -060070 Should Be Empty ${stderr}
71 Should Not Be Empty ${bmc_model}
72 [Return] ${bmc_model}
73
74Verify BMC System Model
75 [Documentation] Verify the BMC model with ${OPENBMC_MODEL}.
76 [Arguments] ${bmc_model}
77
78 ${tmp_bmc_model}= Fetch From Right ${OPENBMC_MODEL} /
79 ${tmp_bmc_model}= Fetch From Left ${tmp_bmc_model} .
80 ${ret}= Run Keyword And Return Status Should Contain ${bmc_model}
81 ... ${tmp_bmc_model} ignore_case=True
82 [Return] ${ret}
83
Chris Austenb29d2e82016-06-07 12:25:35 -050084Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000085 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
86 ... ${interval}=5 sec
87
88 # host The DNS name or IP of the host to ping.
89 # timeout The amount of time after which attempts to ping cease.
90 # interval The amount of time in between attempts to ping.
91
92 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050093
94Ping Host
95 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050096 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060097 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050098 Log RC: ${RC}\nOutput:\n${output}
99 Should be equal ${RC} ${0}
100
101Get Boot Progress
Michael Walshc972d4d2017-08-16 15:38:03 -0500102 [Documentation] Get the boot progress and return it.
Michael Walsha6723f22016-11-22 11:12:01 -0600103 [Arguments] ${quiet}=${QUIET}
104
Michael Walshc972d4d2017-08-16 15:38:03 -0500105 # Description of argument(s):
106 # quiet Indicates whether this keyword should run without any output to
107 # the console.
108
109 Set Boot Progress Method
110 ${state}= Run Keyword If '${boot_prog_method}' == 'New'
111 ... New Get Boot Progress quiet=${quiet}
112 ... ELSE
113 ... Old Get Boot Progress quiet=${quiet}
114
115 [Return] ${state}
116
117Set Boot Progress Method
118 [Documentation] Set the boot_prog_method to either 'Old' or 'New'.
119
120 # The boot progress data has moved from an 'org' location to an 'xyz'
121 # location. This keyword will determine whether the new method of getting
122 # the boot progress is valid and will set the global boot_prog_method
123 # variable accordingly. If boot_prog_method is already set (either by a
124 # prior call to this function or via a -v parm), this keyword will simply
125 # return.
126
127 # Note: There are interim builds that contain boot_progress in both the old
128 # and the new location values. It is nearly impossible for this keyword to
129 # determine whether the old boot_progress or the new one is active. When
130 # using such builds where the old boot_progress is active, the only recourse
131 # users will have is that they may specify -v boot_prog_method:Old to force
132 # old behavior on such builds.
133
134 Run Keyword If '${boot_prog_method}' != '${EMPTY}' Return From Keyword
135
136 ${new_status} ${new_value}= Run Keyword And Ignore Error
137 ... New Get Boot Progress
138 # If the new style read fails, the method must necessarily be "Old".
139 Run Keyword If '${new_status}' == 'PASS'
140 ... Run Keywords
141 ... Set Global Variable ${boot_prog_method} New AND
142 ... Rqpvars boot_prog_method AND
143 ... Return From Keyword
144
145 # Default method is "Old".
146 Set Global Variable ${boot_prog_method} Old
147 Rqpvars boot_prog_method
148
149Old Get Boot Progress
150 [Documentation] Get the boot progress the old way (via org location).
151 [Arguments] ${quiet}=${QUIET}
152
153 # Description of argument(s):
154 # quiet Indicates whether this keyword should run without any output to
155 # the console.
156
George Keishing85ca05e2016-11-30 09:47:18 -0600157 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress
Michael Walsha6723f22016-11-22 11:12:01 -0600158 ... value quiet=${quiet}
Michael Walshc972d4d2017-08-16 15:38:03 -0500159
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600160 [Return] ${state}
Chris Austenb29d2e82016-06-07 12:25:35 -0500161
Michael Walshc972d4d2017-08-16 15:38:03 -0500162New Get Boot Progress
163 [Documentation] Get the boot progress the new way (via xyz location).
164 [Arguments] ${quiet}=${QUIET}
165
166 # Description of argument(s):
167 # quiet Indicates whether this keyword should run without any output to
168 # the console.
169
170 ${state}= Read Attribute ${HOST_STATE_URI} BootProgress quiet=${quiet}
171
172 [Return] ${state.rsplit('.', 1)[1]}
173
Chris Austenb29d2e82016-06-07 12:25:35 -0500174Is Power On
root442f0ef2016-08-04 20:23:05 +0000175 ${state}= Get Power State
176 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -0500177
178Is Power Off
root442f0ef2016-08-04 20:23:05 +0000179 ${state}= Get Power State
180 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -0500181
root442f0ef2016-08-04 20:23:05 +0000182Initiate Power On
183 [Documentation] Initiates the power on and waits until the Is Power On
184 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -0600185 [Arguments] ${wait}=${1}
186
Chris Austenb29d2e82016-06-07 12:25:35 -0500187 @{arglist}= Create List
188 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600189 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn
Michael Walsha6723f22016-11-22 11:12:01 -0600190 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -0500191 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500192
Michael Walsha6723f22016-11-22 11:12:01 -0600193 # Does caller want to wait for power on status?
194 Run Keyword If '${wait}' == '${0}' Return From Keyword
195 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500196
root442f0ef2016-08-04 20:23:05 +0000197Initiate Power Off
198 [Documentation] Initiates the power off and waits until the Is Power Off
199 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -0500200 @{arglist}= Create List
201 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600202 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff
Michael Walsha6723f22016-11-22 11:12:01 -0600203 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -0500204 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -0600205 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -0500206
Michael Walsh81843772017-03-02 14:44:44 -0600207Initiate OS Host Power Off
208 [Documentation] Initiate an OS reboot.
209 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
210 ... ${os_password}=${OS_PASSWORD}
211
212 # Description of arguments:
213 # os_host The DNS name or IP of the OS.
214 # os_username The username to be used to sign in to the OS.
215 # os_password The password to be used to sign in to the OS.
216
Michael Walshac275512017-03-07 11:39:28 -0600217 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600218 Login ${os_username} ${os_password}
219 ${cmd_buf} Catenate shutdown
220 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600221 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600222
223Initiate OS Host Reboot
224 [Documentation] Initiate an OS reboot.
225 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
226 ... ${os_password}=${OS_PASSWORD}
227
228 # Description of arguments:
229 # os_host The DNS name or IP of the OS.
230 # os_username The username to be used to sign in to the OS.
231 # os_password The password to be used to sign in to the OS.
232
Michael Walshac275512017-03-07 11:39:28 -0600233 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600234 Login ${os_username} ${os_password}
235 ${cmd_buf} Catenate reboot
236 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600237 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600238
239Initiate Auto Reboot
240 [Documentation] Initiate an auto reboot.
241
242 # Set the auto reboot policy.
Sweta Potthuri62a23572017-07-28 04:05:13 -0500243 Set Auto Reboot ${1}
Michael Walsh81843772017-03-02 14:44:44 -0600244 # Set the watchdog timer. Note: 5000 = milliseconds which is 5 seconds.
George Keishing37cfa6b2017-06-15 10:25:55 -0500245 Trigger Host Watchdog Error 5000
Michael Walsh81843772017-03-02 14:44:44 -0600246
Chris Austenb29d2e82016-06-07 12:25:35 -0500247Trigger Warm Reset
248 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -0600249 ${data}= create dictionary data=@{EMPTY}
George Keishing85ca05e2016-11-30 09:47:18 -0600250 ${resp}= openbmc post request
251 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -0500252 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -0500253 ${session_active}= Check If warmReset is Initiated
254 Run Keyword If '${session_active}' == '${True}'
255 ... Fail msg=warm reset didn't occur
256
Chris Austenb29d2e82016-06-07 12:25:35 -0500257 Sleep ${SYSTEM_SHUTDOWN_TIME}min
Rahul Maheshwari5f253c42017-01-30 05:19:51 -0600258 Check If BMC Is Up
Michael Walsh49ab0f42016-07-20 11:44:33 -0500259
260Check OS
root442f0ef2016-08-04 20:23:05 +0000261 [Documentation] Attempts to ping the host OS and then checks that the host
262 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500263
264 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -0600265 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
266 ... ${print_string}=${EMPTY}
Michael Walshac275512017-03-07 11:39:28 -0600267 [Teardown] SSHLibrary.Close Connection
Michael Walsh49ab0f42016-07-20 11:44:33 -0500268
269 # os_host The DNS name/IP of the OS host associated with our BMC.
270 # os_username The username to be used to sign on to the OS host.
271 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600272 # quiet Indicates whether this keyword should write to console.
273 # print_string A string to be printed before checking the OS.
274
275 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500276
root442f0ef2016-08-04 20:23:05 +0000277 # Attempt to ping the OS. Store the return code to check later.
278 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
279
Michael Walshac275512017-03-07 11:39:28 -0600280 SSHLibrary.Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500281
Michael Walsha6723f22016-11-22 11:12:01 -0600282 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
283 ... ${os_password}
284 ${err_msg1}= Sprint Error ${msg}
285 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
286 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500287 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
288 ... return_rc=True
289
Michael Walsha6723f22016-11-22 11:12:01 -0600290 ${temp_msg}= Catenate Could not execute a command on the operating
291 ... system.\n
292 ${err_msg1}= Sprint Error ${temp_msg}
293 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
294
295 # If the return code returned by "Execute Command" is non-zero, this
296 # keyword will fail.
297 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500298 # We will likewise fail if there is any stderr data.
299 Should Be Empty ${stderr}
300
Michael Walsha6723f22016-11-22 11:12:01 -0600301 ${temp_msg}= Set Variable Could not ping the operating system.\n
302 ${err_msg1}= Sprint Error ${temp_msg}
303 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
304 # We will likewise fail if the OS did not ping, as we could SSH but not
305 # ping
306 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000307
Michael Walsh49ab0f42016-07-20 11:44:33 -0500308Wait for OS
309 [Documentation] Waits for the host OS to come up via calls to "Check OS".
310 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
311 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600312 ... ${quiet}=${0}
313 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500314
315 # os_host The DNS name or IP of the OS host associated with our
316 # BMC.
317 # os_username The username to be used to sign on to the OS host.
318 # os_password The password to be used to sign on to the OS host.
319 # timeout The timeout in seconds indicating how long you're
320 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600321 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500322
323 # The interval to be used between calls to "Check OS".
324 ${interval}= Set Variable 5
325
Michael Walsha6723f22016-11-22 11:12:01 -0600326 ${message}= Catenate Checking every ${interval} seconds for up to
327 ... ${timeout} seconds for the operating system to communicate.
328 rqprint_timen ${message}
329
Michael Walsh49ab0f42016-07-20 11:44:33 -0500330 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
331 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600332 ... print_string=\#
333
334 rqprintn
335
336 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000337
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600338Get BMC State Deprecated
root442f0ef2016-08-04 20:23:05 +0000339 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600340 [Arguments] ${quiet}=${QUIET}
341
root442f0ef2016-08-04 20:23:05 +0000342 @{arglist}= Create List
343 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600344 ${resp}= Call Method ${OPENBMC_BASE_URI}managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600345 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000346 Should be equal as strings ${resp.status_code} ${HTTP_OK}
347 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600348 [Return] ${content["data"]}
root442f0ef2016-08-04 20:23:05 +0000349
350Get Power State
351 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600352 [Arguments] ${quiet}=${QUIET}
353
root442f0ef2016-08-04 20:23:05 +0000354 @{arglist}= Create List
355 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600356
George Keishing85ca05e2016-11-30 09:47:18 -0600357 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600358 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000359 Should be equal as strings ${resp.status_code} ${HTTP_OK}
360 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600361 [Return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500362
363Clear BMC Record Log
364 [Documentation] Clears all the event logs on the BMC. This would be
365 ... equivalent to ipmitool sel clear.
366 @{arglist}= Create List
367 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600368 ${resp}= Call Method
369 ... ${OPENBMC_BASE_URI}records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500370 should be equal as strings ${resp.status_code} ${HTTP_OK}
371
372Copy PNOR to BMC
373 Import Library SCPLibrary WITH NAME scp
374 Open Connection for SCP
375 Log Copying ${PNOR_IMAGE_PATH} to /tmp
376 scp.Put File ${PNOR_IMAGE_PATH} /tmp
377
378Flash PNOR
379 [Documentation] Calls flash bios update method to flash PNOR image
Gunnar Mills38032802016-12-12 13:43:40 -0600380 [Arguments] ${pnor_image}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500381 @{arglist}= Create List ${pnor_image}
382 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600383 ${resp}= Call Method ${OPENBMC_BASE_URI}control/flash/bios/ update
Michael Walsha6723f22016-11-22 11:12:01 -0600384 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500385 should be equal as strings ${resp.status_code} ${HTTP_OK}
386 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
387
388Get Flash BIOS Status
389 [Documentation] Returns the status of the flash BIOS API as a string. For
390 ... example 'Flashing', 'Flash Done', etc
George Keishing85ca05e2016-11-30 09:47:18 -0600391 ${data}= Read Properties ${OPENBMC_BASE_URI}control/flash/bios
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600392 [Return] ${data['status']}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500393
394Is PNOR Flashing
395 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
396 ... flashing has started.
397 ${status}= Get Flash BIOS Status
Rahul Maheshwari449dfb72017-05-08 02:06:48 -0500398 Should Contain ${status} Flashing
Jay Azurine4c52eb2016-08-16 20:51:10 -0500399
400Is PNOR Flash Done
401 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
402 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000403 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500404 should be equal as strings ${status} Flash Done
405
406Is System State Host Booted
407 [Documentation] Checks whether system state is HOST_BOOTED.
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600408 ${state}= Get BMC State Deprecated
Jay Azurine4c52eb2016-08-16 20:51:10 -0500409 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500410
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600411Is OS Starting
412 [Documentation] Check if boot progress is OS starting.
413 ${boot_progress}= Get Boot Progress
414 Should Be Equal ${boot_progress} FW Progress, Starting OS
415
George Keishing0af24412017-03-10 13:33:23 -0600416Is OS Off
417 [Documentation] Check if boot progress is "Off".
418 ${boot_progress}= Get Boot Progress
419 Should Be Equal ${boot_progress} Off
420
Rahul Maheshwariffd30de2017-06-27 05:57:45 -0500421Get Boot Progress To OS Starting State
422 [Documentation] Get the system to a boot progress state of 'FW Progress,
423 ... Starting OS'.
424
425 ${boot_progress}= Get Boot Progress
426 Run Keyword If '${boot_progress}' == 'FW Progress, Starting OS'
427 ... Log Host is already in OS starting state
428 ... ELSE
429 ... Run Keywords Initiate Host PowerOff AND Initiate Host Boot
430 ... AND Wait Until Keyword Succeeds 10 min 10 sec Is OS Starting
431
George Keishing5e870cd2016-08-24 10:05:47 -0500432Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600433 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500434 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500435 Run Keyword If '${l_ping}' == '${False}'
436 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500437
Michael Walsha6723f22016-11-22 11:12:01 -0600438 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500439 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500440 Run Keyword If '${l_rest}' == '${False}'
441 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500442
443 # Just to make sure the SSH is working for SCP
444 Open Connection And Log In
445 ${system} ${stderr}= Execute Command hostname return_stderr=True
446 Should Be Empty ${stderr}
447
George Keishingc4d3dc02016-09-19 03:45:55 -0500448Check If BMC is Up
449 [Documentation] Wait for Host to be online. Checks every X seconds
450 ... interval for Y minutes and fails if timed out.
451 ... Default MAX timedout is 10 min, interval 10 seconds.
Gunnar Mills38032802016-12-12 13:43:40 -0600452 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500453 ... ${interval}=10 sec
454
455 Wait Until Keyword Succeeds
456 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
457
George Keishingb3700812016-08-31 03:03:30 -0500458
459Check If warmReset is Initiated
460 [Documentation] Ping would be still alive, so try SSH to connect
461 ... if fails the ports are down indicating reboot
462 ... is in progress
George Keishing3c05d352016-12-13 06:54:50 -0600463
464 # Warm reset adds 3 seconds delay before forcing reboot
465 # To minimize race conditions, we wait for 7 seconds
466 Sleep 7s
George Keishingb3700812016-08-31 03:03:30 -0500467 ${alive}= Run Keyword and Return Status
468 ... Open Connection And Log In
469 Return From Keyword If '${alive}' == '${False}' ${False}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600470 [Return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500471
George Keishing06ae4aa2016-08-30 01:41:28 -0500472Flush REST Sessions
473 [Documentation] Removes all the active session objects
474 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500475
Sivas SRRe1143ae2016-08-26 22:31:02 -0500476Initialize DBUS cmd
477 [Documentation] Initialize dbus string with property string to extract
Gunnar Mills38032802016-12-12 13:43:40 -0600478 [Arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600479 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
480 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500481 Set Global Variable ${dbuscmd} ${cmd}
482
David Shawba2d2c22017-01-23 16:56:38 -0600483Create OS Console File Path
484 [Documentation] Create OS console file path name and return it.
485 [Arguments] ${log_file_path}=${EMPTY}
George Keishing30c12ff2016-09-02 10:25:29 -0500486
David Shawba2d2c22017-01-23 16:56:38 -0600487 # Description of arguements:
488 # file_path The caller's candidate value. If this value is ${EMPTY}, this
489 # keyword will compose a file path name. Otherwise, this
490 # keyword will use the caller's file_path value. In either
491 # case, the value will be returned.
Gunnar Mills9c760342016-12-08 10:12:06 -0600492
David Shawba2d2c22017-01-23 16:56:38 -0600493 ${default_file_path}= Catenate /tmp/${OPENBMC_HOST}_os_console
494 ${log_file_path}= Set Variable If '${log_file_path}' == '${EMPTY}'
495 ... ${default_file_path} ${log_file_path}
Michael Walsh01bd3682017-01-10 11:21:05 -0600496
David Shawba2d2c22017-01-23 16:56:38 -0600497 [Return] ${log_file_path}
Gunnar Mills9c760342016-12-08 10:12:06 -0600498
David Shawba2d2c22017-01-23 16:56:38 -0600499Create OS Console Command String
500 [Documentation] Return a command string to start OS console logging.
Gunnar Mills9c760342016-12-08 10:12:06 -0600501
David Shawba2d2c22017-01-23 16:56:38 -0600502 # First make sure that the ssh_pw program is available.
503 ${cmd_buf}= Catenate which ssh_pw 2>&1
504 Rdpissuing ${cmd_buf}
505 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
506 Rdpvars rc output
507 Should Be Equal ${rc} ${0} msg=${output}\n
Gunnar Mills9c760342016-12-08 10:12:06 -0600508
David Shawba2d2c22017-01-23 16:56:38 -0600509 ${cmd_buf}= Catenate ssh_pw ${OPENBMC_PASSWORD} -p 2200
George Keishing1f9ec7f2017-06-06 08:59:19 -0500510 ... -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST}
George Keishing30c12ff2016-09-02 10:25:29 -0500511
David Shawba2d2c22017-01-23 16:56:38 -0600512 [Return] ${cmd_buf}
George Keishing30c12ff2016-09-02 10:25:29 -0500513
514Stop SOL Console Logging
David Shawba2d2c22017-01-23 16:56:38 -0600515 [Documentation] Stop system console logging and return log output.
George Keishing72992e42017-06-16 06:42:36 -0500516 [Arguments] ${log_file_path}=${EMPTY}
517 ... ${targ_file_path}=${EXECDIR}${/}logs${/}
Michael Walsh5f3f4142017-05-22 17:09:47 -0500518 ... ${return_data}=${1}
David Shawba2d2c22017-01-23 16:56:38 -0600519
520 # If there are muliple system console processes, they will all be stopped.
521 # If there is no existing log file this keyword will return an error
522 # message to that effect (and write that message to targ_file_path, if
523 # specified).
524 # NOTE: This keyword will not fail if there is no running system console
525 # process.
Michael Walsh01bd3682017-01-10 11:21:05 -0600526
527 # Description of arguments:
David Shawba2d2c22017-01-23 16:56:38 -0600528 # log_file_path The file path that was used to call "Start SOL
529 # Console Logging". See that keyword (above) for details.
530 # targ_file_path If specified, the file path to which the source
531 # file path (i.e. "log_file_path") should be copied.
Michael Walsh5f3f4142017-05-22 17:09:47 -0500532 # return_data If this is set to ${1}, this keyword will return the SOL
533 # data to the caller as a unicode string.
George Keishing30c12ff2016-09-02 10:25:29 -0500534
David Shawba2d2c22017-01-23 16:56:38 -0600535 ${log_file_path}= Create OS Console File Path ${log_file_path}
536 # Find the pid of the active system console logging session (if any).
537 ${search_string}= Create OS Console Command String
538 ${cmd_buf}= Catenate echo $(ps -ef | egrep '${search_string}'
539 ... | egrep -v grep | cut -c10-14)
540 Rdpissuing ${cmd_buf}
541 ${rc} ${os_con_pid}= Run And Return Rc And Output ${cmd_buf}
542 Rdpvars os_con_pid
543 # If rc is not zero it just means that there is no OS Console process
544 # running.
George Keishing30c12ff2016-09-02 10:25:29 -0500545
David Shawba2d2c22017-01-23 16:56:38 -0600546 ${cmd_buf}= Catenate kill -9 ${os_con_pid}
547 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpissuing ${cmd_buf}
548 ${rc} ${output}= Run Keyword If '${os_con_pid}' != '${EMPTY}'
549 ... Run And Return Rc And Output ${cmd_buf}
550 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpvars rc output
George Keishing30c12ff2016-09-02 10:25:29 -0500551
Michael Walsh01bd3682017-01-10 11:21:05 -0600552 Run Keyword If '${targ_file_path}' != '${EMPTY}'
David Shawba2d2c22017-01-23 16:56:38 -0600553 ... Run Keyword And Ignore Error
554 ... Copy File ${log_file_path} ${targ_file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500555
Michael Walsh5f3f4142017-05-22 17:09:47 -0500556 ${output}= Set Variable ${EMPTY}
557 ${loc_quiet}= Evaluate ${debug}^1
558 ${rc} ${output}= Run Keyword If '${return_data}' == '${1}'
559 ... Cmd Fnc cat ${log_file_path} quiet=${loc_quiet} print_output=${0}
560
David Shawba2d2c22017-01-23 16:56:38 -0600561 [Return] ${output}
562
563Start SOL Console Logging
564 [Documentation] Start system console log to file.
Michael Walsh5f3f4142017-05-22 17:09:47 -0500565 [Arguments] ${log_file_path}=${EMPTY} ${return_data}=${1}
David Shawba2d2c22017-01-23 16:56:38 -0600566
567 # This keyword will first call "Stop SOL Console Logging". Only then will
568 # it start SOL console logging. The data returned by "Stop SOL Console
569 # Logging" will in turn be returned by this keyword.
570
571 # Description of arguments:
Michael Walsh5f3f4142017-05-22 17:09:47 -0500572 # log_file_path The file path to which system console log data should be
573 # written. Note that this path is taken to be a location
574 # on the machine where this program is running rather than
575 # on the Open BMC system.
576 # return_data If this is set to ${1}, this keyword will return any SOL
577 # data to the caller as a unicode string.
David Shawba2d2c22017-01-23 16:56:38 -0600578
579 ${log_file_path}= Create OS Console File Path ${log_file_path}
580
581 ${log_output}= Stop SOL Console Logging ${log_file_path}
Michael Walsh5f3f4142017-05-22 17:09:47 -0500582 ... return_data=${return_data}
David Shawba2d2c22017-01-23 16:56:38 -0600583
584 # Validate by making sure we can create the file. Problems creating the
585 # file would not be noticed by the subsequent ssh command because we fork
586 # the command.
587 Create File ${log_file_path}
588 ${sub_cmd_buf}= Create OS Console Command String
589 # Routing stderr to stdout so that any startup error text will go to the
590 # output file.
591 ${cmd_buf}= Catenate ${sub_cmd_buf} > ${log_file_path} 2>&1 &
592 Rdpissuing ${cmd_buf}
593 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
594 # Because we are forking this command, we essentially will never get a
595 # non-zero return code or any output.
596 Should Be Equal ${rc} ${0}
597
598 [Return] ${log_output}
George Keishing30c12ff2016-09-02 10:25:29 -0500599
600Get Time Stamp
601 [Documentation] Get the current time stamp data
602 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500603 [Return] ${cur_time}
George Keishing30c12ff2016-09-02 10:25:29 -0500604
George Keishing1b150202016-09-29 08:51:58 -0500605
606Verify BMC State
607 [Documentation] Get the BMC state and verify if the current
608 ... BMC state is as expected.
609 [Arguments] ${expected}
610
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600611 ${current}= Get BMC State Deprecated
George Keishing8db0e1b2016-10-20 13:46:54 -0500612 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500613
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500614Start Journal Log
615 [Documentation] Start capturing journal log to a file in /tmp using
616 ... journalctl command. By default journal log is collected
617 ... at /tmp/journal_log else user input location.
618 ... The File is appended with datetime.
619 [Arguments] ${file_path}=/tmp/journal_log
620
621 Open Connection And Log In
622
623 ${cur_time}= Get Time Stamp
624 Set Global Variable ${LOG_TIME} ${cur_time}
625 Start Command
626 ... journalctl -f > ${file_path}-${LOG_TIME}
627 Log Journal Log Started: ${file_path}-${LOG_TIME}
628
David Shawba2d2c22017-01-23 16:56:38 -0600629
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500630Stop Journal Log
631 [Documentation] Stop journalctl process if its running.
632 ... By default return log from /tmp/journal_log else
633 ... user input location.
634 [Arguments] ${file_path}=/tmp/journal_log
635
636 Open Connection And Log In
637
638 ${rc}=
639 ... Execute Command
640 ... ps ax | grep journalctl | grep -v grep
641 ... return_stdout=False return_rc=True
642
643 Return From Keyword If '${rc}' == '${1}'
644 ... No journal log process running
645
646 ${output} ${stderr}=
647 ... Execute Command killall journalctl
648 ... return_stderr=True
649 Should Be Empty ${stderr}
650
651 ${journal_log} ${stderr}=
652 ... Execute Command
653 ... cat ${file_path}-${LOG_TIME}
654 ... return_stderr=True
655 Should Be Empty ${stderr}
656
657 Log ${journal_log}
658
659 Execute Command rm ${file_path}-${LOG_TIME}
660
661 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500662
663Mac Address To Hex String
664 [Documentation] Converts MAC address into hex format.
665 ... Example
666 ... Given the following MAC: 00:01:6C:80:02:78
667 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
668 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600669 ... i_macaddress MAC address in the following format
670 ... 00:01:6C:80:02:78
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500671 [Arguments] ${i_macaddress}
672
673 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600674 [Return] ${mac_hex}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500675
676IP Address To Hex String
677 [Documentation] Converts IP address into hex format.
678 ... Example:
679 ... Given the following IP: 10.3.164.100
680 ... This keyword will return: 0xa 0x3 0xa4 0xa0
681 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600682 ... i_ipaddress IP address in the following format
683 ... 10.10.10.10
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500684 [Arguments] ${i_ipaddress}
685
686 @{ip}= Split String ${i_ipaddress} .
687 ${index}= Set Variable ${0}
688
689 :FOR ${item} IN @{ip}
690 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
691 \ Set List Value ${ip} ${index} ${hex}
692 \ ${index}= Set Variable ${index + 1}
693 ${ip_hex}= Catenate @{ip}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600694 [Return] ${ip_hex}
Sivas SRRea85d1f2016-11-13 22:44:28 -0600695
696BMC CPU Performance Check
697 [Documentation] Minimal 10% of proc should be free in this instance
698
699 ${bmc_cpu_usage_output} ${stderr}= Execute Command ${bmc_cpu_usage_cmd}
700 ... return_stderr=True
701 Should be empty ${stderr}
702 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
703 Should be true ${bmc_cpu_percentage} < 90
704
705BMC Mem Performance Check
706 [Documentation] Minimal 10% of memory should be free in this instance
707
708 ${bmc_mem_free_output} ${stderr}= Execute Command ${bmc_mem_free_cmd}
709 ... return_stderr=True
710 Should be empty ${stderr}
711
712 ${bmc_mem_total_output} ${stderr}= Execute Command ${bmc_mem_total_cmd}
713 ... return_stderr=True
714 Should be empty ${stderr}
715
716 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
717 ${bmc_mem_percentage}= Evaluate
718 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
719 Should be true ${bmc_mem_percentage} > 10
720
Sivas SRRaca55712016-12-21 04:32:35 -0600721BMC File System Usage Check
722 [Documentation] Check the file system space. None should be 100% full
Sivas SRR352bc162017-02-13 22:12:29 -0600723 ... except /run/initramfs/ro
Sivas SRRaca55712016-12-21 04:32:35 -0600724 ${bmc_fs_usage_output} ${stderr}= Execute Command
725 ... ${bmc_file_system_usage_cmd} return_stderr=True
726 Should Be Empty ${stderr}
727 Should Be True ${bmc_fs_usage_output}==0
728
Sivas SRRea85d1f2016-11-13 22:44:28 -0600729Check BMC CPU Performance
730 [Documentation] Minimal 10% of proc should be free in 3 sample
731 :FOR ${var} IN Range 1 4
732 \ BMC CPU Performance check
733
734Check BMC Mem Performance
735 [Documentation] Minimal 10% of memory should be free
736
737 :FOR ${var} IN Range 1 4
738 \ BMC Mem Performance check
739
Sivas SRRaca55712016-12-21 04:32:35 -0600740Check BMC File System Performance
741 [Documentation] Check for file system usage for 4 times
742
743 :FOR ${var} IN Range 1 4
744 \ BMC File System Usage check
745
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500746Get URL List
747 [Documentation] Return list of URLs under given URL.
748 [Arguments] ${openbmc_url}
749 # Description of argument(s):
Michael Walsh5f3f4142017-05-22 17:09:47 -0500750 # openbmc_url URL for list operation (e.g.
751 # /xyz/openbmc_project/inventory).
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500752
George Keishing335f5362017-06-30 15:11:20 -0500753 ${url_list}= Read Properties ${openbmc_url}/list quiet=${1}
George Keishing184a89a2017-06-27 07:12:16 -0500754 Sort List ${url_list}
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500755 [Return] ${url_list}
756
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600757Get Endpoint Paths
758 [Documentation] Returns all url paths ending with given endpoint
759 ... Example:
760 ... Given the following endpoint: cpu
Michael Walsh01bd3682017-01-10 11:21:05 -0600761 ... This keyword will return: list of all urls ending with
762 ... cpu -
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600763 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0,
764 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1
765 ... Description of arguments:
766 ... path URL path for enumeration
767 ... endpoint string for which url path ending
768 [Arguments] ${path} ${endpoint}
769
770 ${resp}= Read Properties ${path}/enumerate timeout=30
771 log Dictionary ${resp}
772
773 ${list}= Get Dictionary Keys ${resp}
774 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600775 [Return] ${resp}
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500776
777Check Zombie Process
778 [Documentation] Check if any defunct process exist or not on BMC
Michael Walsh01bd3682017-01-10 11:21:05 -0600779 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500780 ... return_stderr=True return_rc=True
781 Should Be True ${count}==0
782 Should Be Empty ${stderr}
George Keishing5327d012016-12-08 08:43:29 -0600783
784Prune Journal Log
785 [Documentation] Prune archived journal logs.
786 [Arguments] ${vacuum_size}=1M
787
788 # This keyword can be used to prevent the journal
789 # log from filling up the /run filesystem.
790 # This command will retain only the latest logs
791 # of the user specified size.
792
793 Open Connection And Log In
794 ${output} ${stderr} ${rc}=
795 ... Execute Command
796 ... journalctl --vacuum-size=${vacuum_size}
797 ... return_stderr=True return_rc=True
798
799 Should Be Equal ${rc} ${0} msg=${stderr}
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600800
801Set BMC Power Policy
802 [Documentation] Set the given BMC power policy.
Michael Walshfdc5ced2017-08-17 13:15:15 -0500803 [Arguments] ${policy}
804
805 # Note that this function will translate the old style "RESTORE_LAST_STATE"
806 # policy to the new style "xyz.openbmc_project.Control.Power.RestorePolicy.
807 # Policy.Restore" for you.
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600808
George Keishing1c3a9662017-08-11 10:16:36 -0500809 # Description of argument(s):
Michael Walshfdc5ced2017-08-17 13:15:15 -0500810 # policy Power restore policy (e.g "RESTORE_LAST_STATE",
811 # ${RESTORE_LAST_STATE}).
812
813 # Set the bmc_power_policy_method to either 'Old' or 'New'.
814 Set Power Policy Method
815 # This translation helps bridge between old and new method for calling.
816 ${policy}= Translate Power Policy Value ${policy}
817 # Run the appropriate keyword.
818 Run Key ${bmc_power_policy_method} Set Power Policy \ ${policy}
819 ${currentPolicy}= Get System Power Policy
820 Should Be Equal ${currentPolicy} ${policy}
821
822New Set Power Policy
823 [Documentation] Set the given BMC power policy (new method).
824 [Arguments] ${policy}
825
826 # Description of argument(s):
827 # policy Power restore policy (e.g. ${RESTORE_LAST_STATE}).
George Keishing1c3a9662017-08-11 10:16:36 -0500828
829 ${valueDict}= Create Dictionary data=${policy}
830 Write Attribute
Michael Walshfdc5ced2017-08-17 13:15:15 -0500831 ... ${POWER_RESTORE_URI} PowerRestorePolicy data=${valueDict}
832
833Old Set Power Policy
834 [Documentation] Set the given BMC power policy (old method).
835 [Arguments] ${policy}
836
837 # Description of argument(s):
838 # policy Power restore policy (e.g. "RESTORE_LAST_STATE").
839
840 ${valueDict}= create dictionary data=${policy}
841 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
George Keishingcce9df22017-01-24 06:19:33 -0600842
George Keishing4d6f3d62017-02-06 09:50:41 -0600843Get System Power Policy
844 [Documentation] Get the BMC power policy.
Michael Walshfdc5ced2017-08-17 13:15:15 -0500845
846 # Set the bmc_power_policy_method to either 'Old' or 'New'.
847 Set Power Policy Method
848 ${cmd_buf}= Create List ${bmc_power_policy_method} Get Power Policy
849 # Run the appropriate keyword.
850 ${currentPolicy}= Run Keyword @{cmd_buf}
851 [Return] ${currentPolicy}
852
853New Get Power Policy
854 [Documentation] Get the BMC power policy (new method).
George Keishing1c3a9662017-08-11 10:16:36 -0500855 ${currentPolicy}= Read Attribute ${POWER_RESTORE_URI} PowerRestorePolicy
George Keishing4d6f3d62017-02-06 09:50:41 -0600856 [Return] ${currentPolicy}
George Keishingcce9df22017-01-24 06:19:33 -0600857
Michael Walshfdc5ced2017-08-17 13:15:15 -0500858Old Get Power Policy
859 [Documentation] Get the BMC power policy (old method).
860 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
861 [Return] ${currentPolicy}
862
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600863Get Auto Reboot
864 [Documentation] Returns auto reboot setting.
Sweta Potthuri62a23572017-07-28 04:05:13 -0500865 ${setting}= Read Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600866 [Return] ${setting}
867
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600868Set Auto Reboot
869 [Documentation] Set the given auto reboot setting.
870 [Arguments] ${setting}
Sweta Potthuri62a23572017-07-28 04:05:13 -0500871 # setting auto reboot's setting, i.e. 1 for enabling and 0 for disabling.
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600872
873 ${valueDict}= Set Variable ${setting}
874 ${data}= Create Dictionary data=${valueDict}
Sweta Potthuri62a23572017-07-28 04:05:13 -0500875 Write Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot data=${data}
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600876 ${current_setting}= Get Auto Reboot
Sweta Potthuri62a23572017-07-28 04:05:13 -0500877 Should Be Equal As Integers ${current_setting} ${setting}
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600878
879
George Keishingcce9df22017-01-24 06:19:33 -0600880Set BMC Reset Reference Time
881 [Documentation] Set current boot time as a reference and increment
George Keishing80dd5af2017-02-08 07:01:25 -0600882 ... boot count.
George Keishingcce9df22017-01-24 06:19:33 -0600883
884 ${cur_btime}= Get BMC Boot Time
George Keishing80dd5af2017-02-08 07:01:25 -0600885 Run Keyword If ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
George Keishingcce9df22017-01-24 06:19:33 -0600886 ... Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishing80dd5af2017-02-08 07:01:25 -0600887 ... ELSE IF ${cur_btime} > ${BOOT_TIME}
888 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishingcce9df22017-01-24 06:19:33 -0600889 ... AND
890 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
891
George Keishingcce9df22017-01-24 06:19:33 -0600892Get BMC Boot Time
893 [Documentation] Get boot time from /proc/stat.
894
895 Open Connection And Log In
896 ${output} ${stderr}=
897 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' '
898 ... return_stderr=True
899 Should Be Empty ${stderr}
900 ${btime}= Convert To Integer ${output}
901 [Return] ${btime}
George Keishingede30002017-02-02 09:33:07 -0600902
George Keishingede30002017-02-02 09:33:07 -0600903Execute Command On BMC
904 [Documentation] Execute given command on BMC and return output.
905 [Arguments] ${command}
906 ${stdout} ${stderr}= Execute Command ${command} return_stderr=True
907 Should Be Empty ${stderr}
908 [Return] ${stdout}
David Shawba2d2c22017-01-23 16:56:38 -0600909
Sridevi Rameshea36b412017-03-09 04:08:02 -0600910
George Keishing7a520222017-02-27 09:44:30 -0600911Enable Core Dump On BMC
912 [Documentation] Enable core dump collection.
913 Open Connection And Log In
914 ${core_pattern}= Execute Command On BMC
915 ... echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
916 Should Be Equal As Strings ${core_pattern} /tmp/core_%e.%p
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600917
Sivas SRR01262bd2017-03-19 10:00:23 -0500918Get Number Of BMC Core Dump Files
919 [Documentation] Get number of core dump files on BMC.
920 Open Connection And Log In
921 ${num_of_core_dump}= Execute Command
922 ... ls /tmp/core* 2>/dev/null | wc -l
923 [Return] ${num_of_core_dump}
924
925Set Core Dump File Size Unlimited
926 [Documentation] Set core dump file size to unlimited.
927 Open Connection And Log In
928 Execute Command On BMC
929 ... ulimit -c unlimited
930
931Check For Core Dumps
932 [Documentation] Check for any core dumps exist.
933 ${output}= Get Number Of BMC Core Dump Files
934 Run Keyword If ${output} > 0
935 ... Log **Warning** BMC core dump files exist level=WARN
936
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600937Trigger Host Watchdog Error
George Keishing37cfa6b2017-06-15 10:25:55 -0500938 [Documentation] Inject host watchdog timeout error via REST.
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600939 [Arguments] ${milliseconds}=1000 ${sleep_time}=5s
Michael Walshb5839d02017-04-12 16:11:20 -0500940 # Description of argument(s):
941 # milliseconds The time watchdog timer value in milliseconds (e.g. 1000 =
942 # 1 second).
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600943 # sleep_time Time delay for host watchdog error to get injected.
944 # Default is 5 seconds.
945
George Keishing37cfa6b2017-06-15 10:25:55 -0500946 ${data}= Create Dictionary data=${True}
947 Write Attribute /xyz/openbmc_project/watchdog/host0 Enabled data=${data}
948
949 ${data}= Create Dictionary data=${milliseconds}
950 Write Attribute /xyz/openbmc_project/watchdog/host0 TimeRemaining data=${data}
951
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600952 Sleep ${sleep_time}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500953
954Login To OS Host
955 [Documentation] Login to OS Host.
956 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
957 ... ${os_password}=${OS_PASSWORD}
958 # Desription of arguments:
959 # ${os_host} IP address of the OS Host.
960 # ${os_username} OS Host Login user name.
961 # ${os_password} OS Host Login passwrd.
962
963 ${os_state}= Run Keyword And Return Status Ping Host ${os_host}
964 Run Keyword If '${os_state}' == 'False'
965 ... Run Keywords Initiate Host Reboot AND
966 ... Is Host Running AND
967 ... Wait for OS ${os_host} ${os_username} ${os_password}
968
George Keishing3f223b82017-06-28 03:50:35 -0500969 SSHLibrary.Open Connection ${os_host}
Sridevi Rameshea36b412017-03-09 04:08:02 -0600970 ${resp}= Login ${os_username} ${os_password}
971 [Return] ${resp}
Prashanth Katti884ee062017-03-16 05:05:03 -0500972
973Configure Initial Settings
974 [Documentation] Restore old IP and route.
975 ... This keyword requires initial settings viz IP address,
976 ... Network Mask, default gatway and serial console IP and port
977 ... information which should be provided in command line.
978
Michael Walshb5839d02017-04-12 16:11:20 -0500979 [Arguments] ${host}=${OPENBMC_HOST} ${mask}=${NET_MASK}
980 ... ${gw_ip}=${GW_IP}
Prashanth Katti884ee062017-03-16 05:05:03 -0500981
Michael Walshb5839d02017-04-12 16:11:20 -0500982 # Open telnet connection and ignore the error, in case telnet session is
983 # already opened by the program calling this keyword.
Prashanth Katti884ee062017-03-16 05:05:03 -0500984
985 Run Keyword And Ignore Error Open Telnet Connection to BMC Serial Console
986 Telnet.write ifconfig eth0 ${host} netmask ${mask}
987 Telnet.write route add default gw ${gw_ip}
George Keishingd05b1082017-03-24 05:27:32 -0500988
989Install Debug Tarball On BMC
George Keishing55441822017-05-18 14:17:59 -0500990 [Documentation] Copy the debug tar file to BMC and install.
991 [Arguments] ${tarball_file_path}=${EXECDIR}/obmc-phosphor-debug-tarball-witherspoon.tar.xz
992 ... ${targ_tarball_dir_path}=/home/root/tarball/
George Keishingd05b1082017-03-24 05:27:32 -0500993
George Keishing55441822017-05-18 14:17:59 -0500994 # Description of arguments:
995 # tarball_file_path Path of the debug tarball file.
996 # The tar file is downloaded from the build page
997 # https://openpower.xyz/job/openbmc-build/
998 # obmc-phosphor-debug-tarball-witherspoon.tar.xz
999 #
1000 # targ_tarball_dir_path The directory path where the tarball is to be
1001 # installed.
1002
1003 OperatingSystem.File Should Exist ${tarball_file_path}
1004 ... msg=${tarball_file_path} doesn't exist.
1005
1006 # Upload the file to BMC.
George Keishingd05b1082017-03-24 05:27:32 -05001007 Import Library SCPLibrary WITH NAME scp
1008 Open Connection for SCP
George Keishing55441822017-05-18 14:17:59 -05001009 scp.Put File ${tarball_file_path} /tmp/debug-tarball.tar.xz
1010
1011 # Create tarball directory and install.
George Keishingd05b1082017-03-24 05:27:32 -05001012 Open Connection And Log In
George Keishing55441822017-05-18 14:17:59 -05001013 Execute Command On BMC mkdir -p ${targ_tarball_dir_path}
1014 Execute Command On BMC
1015 ... tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path}
1016
1017 # Create symlink to callout-test binary.
1018 Execute Command On BMC
1019 ... ln -s ${targ_tarball_dir_path}/bin/callout-test /usr/bin/callout-test
1020
George Keishing4fc998b2017-05-26 05:24:12 -05001021 # Create symlink to logging-test binary.
1022 Execute Command On BMC
1023 ... ln -s ${targ_tarball_dir_path}/bin/logging-test /usr/bin/logging-test
1024
George Keishingd05b1082017-03-24 05:27:32 -05001025 # Remove the tarball file from BMC
1026 Execute Command On BMC rm /tmp/debug-tarball.tar.xz
1027
George Keishing55441822017-05-18 14:17:59 -05001028
Sweta Potthuri025e0122017-02-21 00:42:48 -06001029Get BMC Boot Count
1030 [Documentation] Get BMC boot count based on boot time.
1031 ${cur_btime}= Get BMC Boot Time
1032
1033 # Set global variable BOOT_TIME to current boot time if current boot time
1034 # is changed. Also increase value of global variable BOOT_COUNT by 1.
1035 Run Keyword If ${cur_btime} > ${BOOT_TIME}
1036 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
1037 ... AND
1038 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
1039 [Return] ${BOOT_COUNT}
1040
1041Set BMC Boot Count
1042 [Documentation] Set BMC boot count to given value.
1043 [Arguments] ${count}
1044
1045 # Description of arguments:
1046 # count boot count value.
1047 ${cur_btime}= Get BMC Boot Time
1048
1049 # Set global variable BOOT_COUNT to given value.
1050 Set Global Variable ${BOOT_COUNT} ${count}
1051
1052 # Set BOOT_TIME variable to current boot time.
1053 Set Global Variable ${BOOT_COUNT} ${count}
Michael Walsh689fbbe2017-04-04 17:58:03 -05001054
Sweta Potthurie5a9fc72017-05-03 07:02:46 -05001055Get System LED State
1056 [Documentation] Return the state of given system LED.
1057 [Arguments] ${led_name}
1058
1059 # Description of argument(s):
1060 # led_name System LED name (e.g. heartbeat, identify, beep).
1061
1062 ${state}= Read Attribute ${LED_PHYSICAL_URI}${led_name} State
1063 [Return] ${state.rsplit('.', 1)[1]}
1064
Michael Walsh689fbbe2017-04-04 17:58:03 -05001065###############################################################################
George Keishingd2d90af2017-06-27 08:17:34 -05001066Delete Error Logs
Michael Walsh689fbbe2017-04-04 17:58:03 -05001067 [Documentation] Delete error logs.
1068
George Keishingd2d90af2017-06-27 08:17:34 -05001069 # Check if error logs entries exist, if not return.
George Keishing335f5362017-06-30 15:11:20 -05001070 ${resp}= OpenBMC Get Request ${BMC_LOGGING_ENTRY}${/}list quiet=${1}
George Keishingd2d90af2017-06-27 08:17:34 -05001071 Return From Keyword If ${resp.status_code} == ${HTTP_NOT_FOUND}
1072
1073 # Get the list of error logs entries and delete them all.
George Keishing335f5362017-06-30 15:11:20 -05001074 ${elog_entries}= Get URL List ${BMC_LOGGING_ENTRY}
George Keishingd2d90af2017-06-27 08:17:34 -05001075 :FOR ${entry} IN @{elog_entries}
1076 \ Delete Error Log Entry ${entry}
George Keishingdb34c2f2017-04-18 13:20:25 -05001077
1078###############################################################################
George Keishingd2d90af2017-06-27 08:17:34 -05001079Delete Error Log Entry
George Keishingdb34c2f2017-04-18 13:20:25 -05001080 [Documentation] Delete error log entry.
1081 [Arguments] ${entry_path}
1082
1083 # Description of argument(s):
1084 # entry_path Delete an error log entry.
1085 # Ex. /xyz/openbmc_project/logging/entry/1
1086
George Keishing6a8ed0f2017-07-11 22:54:42 -05001087 # Skip delete if entry URI is a callout.
1088 # Example: /xyz/openbmc_project/logging/entry/1/callout
1089 Return From Keyword If '${entry_path.rsplit('/', 1)[1]}' == 'callout'
1090
George Keishingdb34c2f2017-04-18 13:20:25 -05001091 ${data}= Create Dictionary data=@{EMPTY}
1092 ${resp}= Openbmc Delete Request ${entry_path} data=${data}
1093 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Rahul Maheshwari43be6932017-05-01 02:37:06 -05001094
1095
George Keishingad5817a2017-06-28 10:19:03 -05001096###############################################################################
Rahul Maheshwari43be6932017-05-01 02:37:06 -05001097Get LED State XYZ
1098 [Documentation] Returns state of given LED.
1099 [Arguments] ${led_name}
1100 # Description of argument(s):
1101 # led_name Name of LED
1102
1103 ${state}= Read Attribute ${LED_GROUPS_URI}${led_name} Asserted
1104 [Return] ${state}
Rahul Maheshwari13256d92017-06-15 10:05:40 -05001105
1106
George Keishingad5817a2017-06-28 10:19:03 -05001107###############################################################################
Rahul Maheshwari13256d92017-06-15 10:05:40 -05001108Get BMC Version
1109 [Documentation] Returns BMC version from /etc/os-release.
1110 ... e.g. "v1.99.6-141-ge662190"
1111
1112 Open Connection And Log In
1113 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
1114 ${output}= Execute Command On BMC ${cmd}
1115 [Return] ${output}
1116
George Keishingad5817a2017-06-28 10:19:03 -05001117
1118###############################################################################
1119Get Elog URL List
1120 [Documentation] Return error log entry list of URLs.
1121
1122 ${url_list}= Read Properties /xyz/openbmc_project/logging/entry/
1123 Sort List ${url_list}
1124 [Return] ${url_list}
1125
1126
1127###############################################################################