blob: bf33b84deb788060c1a910134f0a4c832f03d6f0 [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
Chris Austenb29d2e82016-06-07 12:25:35 -050013
14*** Variables ***
Sivas SRRd97aa9c2017-05-22 11:19:25 -050015${pflash_cmd} /usr/sbin/pflash -r /dev/stdout -P VERSION
Chris Austenb29d2e82016-06-07 12:25:35 -050016${SYSTEM_SHUTDOWN_TIME} ${5}
Michael Walsha6723f22016-11-22 11:12:01 -060017${dbuscmdBase}
George Keishing85ca05e2016-11-30 09:47:18 -060018... dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host
Michael Walsha6723f22016-11-22 11:12:01 -060019${dbuscmdGet}
George Keishing9485af92017-01-04 10:21:43 -060020... ${SETTINGS_URI}host0 org.freedesktop.DBus.Properties.Get
George Keishing85ca05e2016-11-30 09:47:18 -060021# Enable when ready with openbmc/openbmc-test-automation#203
22#${dbuscmdString}= string:"xyz.openbmc_project.settings.Host" string:
Michael Walsha6723f22016-11-22 11:12:01 -060023${dbuscmdString}= string:"org.openbmc.settings.Host" string:
24
25# Assign default value to QUIET for programs which may not define it.
26${QUIET} ${0}
Sivas SRRea85d1f2016-11-13 22:44:28 -060027${bmc_mem_free_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
28${bmc_mem_total_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
29${bmc_cpu_usage_cmd}= top -n 1 | grep CPU: | cut -c 7-9
Sridevi Ramesh1699d372016-12-06 00:20:22 -060030${HOST_SETTING} ${SETTINGS_URI}host0
Sivas SRR352bc162017-02-13 22:12:29 -060031# /run/initramfs/ro associate filesystem should be 100% full always
Sivas SRRaca55712016-12-21 04:32:35 -060032${bmc_file_system_usage_cmd}=
Sivas SRR352bc162017-02-13 22:12:29 -060033... df -h | grep -v /run/initramfs/ro | cut -c 52-54 | grep 100 | wc -l
Chris Austenb29d2e82016-06-07 12:25:35 -050034
George Keishingcce9df22017-01-24 06:19:33 -060035${BOOT_TIME} ${0}
36${BOOT_COUNT} ${0}
Sweta Potthuri025e0122017-02-21 00:42:48 -060037${count} ${0}
Sivas SRR8254db62017-02-07 09:39:46 -060038${devicetree_base} /sys/firmware/devicetree/base/model
George Keishingcce9df22017-01-24 06:19:33 -060039
George Keishingb7c9b542017-05-23 08:19:58 -050040# Initialize default debug value to 0.
41${DEBUG} ${0}
42
Michael Walshc972d4d2017-08-16 15:38:03 -050043${boot_prog_method} ${EMPTY}
44
Chris Austenb29d2e82016-06-07 12:25:35 -050045*** Keywords ***
Sridevi Ramesh1699d372016-12-06 00:20:22 -060046
Sivas SRRd97aa9c2017-05-22 11:19:25 -050047Verify PNOR Update
48 [Documentation] Verify that the PNOR is not corrupted.
49 # Example:
50 # FFS: Flash header not found. Code: 100
51 # Error 100 opening ffs !
52
53 Open Connection And Log In
54 ${pnor_info}= Execute Command On BMC ${pflash_cmd}
55 Should Not Contain Any ${pnor_info} Flash header not found Error
56
Sivas SRR8254db62017-02-07 09:39:46 -060057Get BMC System Model
58 [Documentation] Get the BMC model from the device tree.
59
Michael Walshe53e47a2017-06-30 17:03:24 -050060 ${bmc_model} ${stderr} ${rc}= BMC Execute Command
George Keishing90ab1772017-02-24 05:40:55 -060061 ... cat ${devicetree_base} | cut -d " " -f 1 return_stderr=True
Sivas SRR8254db62017-02-07 09:39:46 -060062 Should Be Empty ${stderr}
63 Should Not Be Empty ${bmc_model}
64 [Return] ${bmc_model}
65
66Verify BMC System Model
67 [Documentation] Verify the BMC model with ${OPENBMC_MODEL}.
68 [Arguments] ${bmc_model}
69
70 ${tmp_bmc_model}= Fetch From Right ${OPENBMC_MODEL} /
71 ${tmp_bmc_model}= Fetch From Left ${tmp_bmc_model} .
72 ${ret}= Run Keyword And Return Status Should Contain ${bmc_model}
73 ... ${tmp_bmc_model} ignore_case=True
74 [Return] ${ret}
75
Chris Austenb29d2e82016-06-07 12:25:35 -050076Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000077 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
78 ... ${interval}=5 sec
79
80 # host The DNS name or IP of the host to ping.
81 # timeout The amount of time after which attempts to ping cease.
82 # interval The amount of time in between attempts to ping.
83
84 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050085
86Ping Host
87 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050088 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060089 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050090 Log RC: ${RC}\nOutput:\n${output}
91 Should be equal ${RC} ${0}
92
93Get Boot Progress
Michael Walshc972d4d2017-08-16 15:38:03 -050094 [Documentation] Get the boot progress and return it.
Michael Walsha6723f22016-11-22 11:12:01 -060095 [Arguments] ${quiet}=${QUIET}
96
Michael Walshc972d4d2017-08-16 15:38:03 -050097 # Description of argument(s):
98 # quiet Indicates whether this keyword should run without any output to
99 # the console.
100
101 Set Boot Progress Method
102 ${state}= Run Keyword If '${boot_prog_method}' == 'New'
103 ... New Get Boot Progress quiet=${quiet}
104 ... ELSE
105 ... Old Get Boot Progress quiet=${quiet}
106
107 [Return] ${state}
108
109Set Boot Progress Method
110 [Documentation] Set the boot_prog_method to either 'Old' or 'New'.
111
112 # The boot progress data has moved from an 'org' location to an 'xyz'
113 # location. This keyword will determine whether the new method of getting
114 # the boot progress is valid and will set the global boot_prog_method
115 # variable accordingly. If boot_prog_method is already set (either by a
116 # prior call to this function or via a -v parm), this keyword will simply
117 # return.
118
119 # Note: There are interim builds that contain boot_progress in both the old
120 # and the new location values. It is nearly impossible for this keyword to
121 # determine whether the old boot_progress or the new one is active. When
122 # using such builds where the old boot_progress is active, the only recourse
123 # users will have is that they may specify -v boot_prog_method:Old to force
124 # old behavior on such builds.
125
126 Run Keyword If '${boot_prog_method}' != '${EMPTY}' Return From Keyword
127
128 ${new_status} ${new_value}= Run Keyword And Ignore Error
129 ... New Get Boot Progress
130 # If the new style read fails, the method must necessarily be "Old".
131 Run Keyword If '${new_status}' == 'PASS'
132 ... Run Keywords
133 ... Set Global Variable ${boot_prog_method} New AND
134 ... Rqpvars boot_prog_method AND
135 ... Return From Keyword
136
137 # Default method is "Old".
138 Set Global Variable ${boot_prog_method} Old
139 Rqpvars boot_prog_method
140
141Old Get Boot Progress
142 [Documentation] Get the boot progress the old way (via org location).
143 [Arguments] ${quiet}=${QUIET}
144
145 # Description of argument(s):
146 # quiet Indicates whether this keyword should run without any output to
147 # the console.
148
George Keishing85ca05e2016-11-30 09:47:18 -0600149 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress
Michael Walsha6723f22016-11-22 11:12:01 -0600150 ... value quiet=${quiet}
Michael Walshc972d4d2017-08-16 15:38:03 -0500151
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600152 [Return] ${state}
Chris Austenb29d2e82016-06-07 12:25:35 -0500153
Michael Walshc972d4d2017-08-16 15:38:03 -0500154New Get Boot Progress
155 [Documentation] Get the boot progress the new way (via xyz location).
156 [Arguments] ${quiet}=${QUIET}
157
158 # Description of argument(s):
159 # quiet Indicates whether this keyword should run without any output to
160 # the console.
161
162 ${state}= Read Attribute ${HOST_STATE_URI} BootProgress quiet=${quiet}
163
164 [Return] ${state.rsplit('.', 1)[1]}
165
Chris Austenb29d2e82016-06-07 12:25:35 -0500166Is Power On
root442f0ef2016-08-04 20:23:05 +0000167 ${state}= Get Power State
168 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -0500169
170Is Power Off
root442f0ef2016-08-04 20:23:05 +0000171 ${state}= Get Power State
172 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -0500173
root442f0ef2016-08-04 20:23:05 +0000174Initiate Power On
175 [Documentation] Initiates the power on and waits until the Is Power On
176 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -0600177 [Arguments] ${wait}=${1}
178
Chris Austenb29d2e82016-06-07 12:25:35 -0500179 @{arglist}= Create List
180 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600181 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn
Michael Walsha6723f22016-11-22 11:12:01 -0600182 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -0500183 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500184
Michael Walsha6723f22016-11-22 11:12:01 -0600185 # Does caller want to wait for power on status?
186 Run Keyword If '${wait}' == '${0}' Return From Keyword
187 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500188
root442f0ef2016-08-04 20:23:05 +0000189Initiate Power Off
190 [Documentation] Initiates the power off and waits until the Is Power Off
191 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -0500192 @{arglist}= Create List
193 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600194 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff
Michael Walsha6723f22016-11-22 11:12:01 -0600195 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -0500196 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -0600197 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -0500198
Michael Walsh81843772017-03-02 14:44:44 -0600199Initiate OS Host Power Off
200 [Documentation] Initiate an OS reboot.
201 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
202 ... ${os_password}=${OS_PASSWORD}
203
204 # Description of arguments:
205 # os_host The DNS name or IP of the OS.
206 # os_username The username to be used to sign in to the OS.
207 # os_password The password to be used to sign in to the OS.
208
Michael Walshac275512017-03-07 11:39:28 -0600209 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600210 Login ${os_username} ${os_password}
211 ${cmd_buf} Catenate shutdown
212 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600213 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600214
215Initiate OS Host Reboot
216 [Documentation] Initiate an OS reboot.
217 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
218 ... ${os_password}=${OS_PASSWORD}
219
220 # Description of arguments:
221 # os_host The DNS name or IP of the OS.
222 # os_username The username to be used to sign in to the OS.
223 # os_password The password to be used to sign in to the OS.
224
Michael Walshac275512017-03-07 11:39:28 -0600225 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600226 Login ${os_username} ${os_password}
227 ${cmd_buf} Catenate reboot
228 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600229 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600230
231Initiate Auto Reboot
232 [Documentation] Initiate an auto reboot.
233
234 # Set the auto reboot policy.
Sweta Potthuri62a23572017-07-28 04:05:13 -0500235 Set Auto Reboot ${1}
Michael Walsh81843772017-03-02 14:44:44 -0600236 # Set the watchdog timer. Note: 5000 = milliseconds which is 5 seconds.
George Keishing37cfa6b2017-06-15 10:25:55 -0500237 Trigger Host Watchdog Error 5000
Michael Walsh81843772017-03-02 14:44:44 -0600238
Chris Austenb29d2e82016-06-07 12:25:35 -0500239Trigger Warm Reset
240 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -0600241 ${data}= create dictionary data=@{EMPTY}
George Keishing85ca05e2016-11-30 09:47:18 -0600242 ${resp}= openbmc post request
243 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -0500244 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -0500245 ${session_active}= Check If warmReset is Initiated
246 Run Keyword If '${session_active}' == '${True}'
247 ... Fail msg=warm reset didn't occur
248
Chris Austenb29d2e82016-06-07 12:25:35 -0500249 Sleep ${SYSTEM_SHUTDOWN_TIME}min
Rahul Maheshwari5f253c42017-01-30 05:19:51 -0600250 Check If BMC Is Up
Michael Walsh49ab0f42016-07-20 11:44:33 -0500251
252Check OS
root442f0ef2016-08-04 20:23:05 +0000253 [Documentation] Attempts to ping the host OS and then checks that the host
254 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500255
256 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -0600257 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
258 ... ${print_string}=${EMPTY}
Michael Walshac275512017-03-07 11:39:28 -0600259 [Teardown] SSHLibrary.Close Connection
Michael Walsh49ab0f42016-07-20 11:44:33 -0500260
261 # os_host The DNS name/IP of the OS host associated with our BMC.
262 # os_username The username to be used to sign on to the OS host.
263 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600264 # quiet Indicates whether this keyword should write to console.
265 # print_string A string to be printed before checking the OS.
266
267 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500268
root442f0ef2016-08-04 20:23:05 +0000269 # Attempt to ping the OS. Store the return code to check later.
270 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
271
Michael Walshac275512017-03-07 11:39:28 -0600272 SSHLibrary.Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500273
Michael Walsha6723f22016-11-22 11:12:01 -0600274 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
275 ... ${os_password}
276 ${err_msg1}= Sprint Error ${msg}
277 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
278 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500279 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
280 ... return_rc=True
281
Michael Walsha6723f22016-11-22 11:12:01 -0600282 ${temp_msg}= Catenate Could not execute a command on the operating
283 ... system.\n
284 ${err_msg1}= Sprint Error ${temp_msg}
285 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
286
287 # If the return code returned by "Execute Command" is non-zero, this
288 # keyword will fail.
289 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500290 # We will likewise fail if there is any stderr data.
291 Should Be Empty ${stderr}
292
Michael Walsha6723f22016-11-22 11:12:01 -0600293 ${temp_msg}= Set Variable Could not ping the operating system.\n
294 ${err_msg1}= Sprint Error ${temp_msg}
295 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
296 # We will likewise fail if the OS did not ping, as we could SSH but not
297 # ping
298 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000299
Michael Walsh49ab0f42016-07-20 11:44:33 -0500300Wait for OS
301 [Documentation] Waits for the host OS to come up via calls to "Check OS".
302 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
303 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600304 ... ${quiet}=${0}
305 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500306
307 # os_host The DNS name or IP of the OS host associated with our
308 # BMC.
309 # os_username The username to be used to sign on to the OS host.
310 # os_password The password to be used to sign on to the OS host.
311 # timeout The timeout in seconds indicating how long you're
312 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600313 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500314
315 # The interval to be used between calls to "Check OS".
316 ${interval}= Set Variable 5
317
Michael Walsha6723f22016-11-22 11:12:01 -0600318 ${message}= Catenate Checking every ${interval} seconds for up to
319 ... ${timeout} seconds for the operating system to communicate.
320 rqprint_timen ${message}
321
Michael Walsh49ab0f42016-07-20 11:44:33 -0500322 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
323 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600324 ... print_string=\#
325
326 rqprintn
327
328 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000329
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600330Get BMC State Deprecated
root442f0ef2016-08-04 20:23:05 +0000331 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600332 [Arguments] ${quiet}=${QUIET}
333
root442f0ef2016-08-04 20:23:05 +0000334 @{arglist}= Create List
335 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600336 ${resp}= Call Method ${OPENBMC_BASE_URI}managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600337 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000338 Should be equal as strings ${resp.status_code} ${HTTP_OK}
339 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600340 [Return] ${content["data"]}
root442f0ef2016-08-04 20:23:05 +0000341
342Get Power State
343 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600344 [Arguments] ${quiet}=${QUIET}
345
root442f0ef2016-08-04 20:23:05 +0000346 @{arglist}= Create List
347 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600348
George Keishing85ca05e2016-11-30 09:47:18 -0600349 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600350 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000351 Should be equal as strings ${resp.status_code} ${HTTP_OK}
352 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600353 [Return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500354
355Clear BMC Record Log
356 [Documentation] Clears all the event logs on the BMC. This would be
357 ... equivalent to ipmitool sel clear.
358 @{arglist}= Create List
359 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600360 ${resp}= Call Method
361 ... ${OPENBMC_BASE_URI}records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500362 should be equal as strings ${resp.status_code} ${HTTP_OK}
363
364Copy PNOR to BMC
365 Import Library SCPLibrary WITH NAME scp
366 Open Connection for SCP
367 Log Copying ${PNOR_IMAGE_PATH} to /tmp
368 scp.Put File ${PNOR_IMAGE_PATH} /tmp
369
370Flash PNOR
371 [Documentation] Calls flash bios update method to flash PNOR image
Gunnar Mills38032802016-12-12 13:43:40 -0600372 [Arguments] ${pnor_image}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500373 @{arglist}= Create List ${pnor_image}
374 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600375 ${resp}= Call Method ${OPENBMC_BASE_URI}control/flash/bios/ update
Michael Walsha6723f22016-11-22 11:12:01 -0600376 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500377 should be equal as strings ${resp.status_code} ${HTTP_OK}
378 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
379
380Get Flash BIOS Status
381 [Documentation] Returns the status of the flash BIOS API as a string. For
382 ... example 'Flashing', 'Flash Done', etc
George Keishing85ca05e2016-11-30 09:47:18 -0600383 ${data}= Read Properties ${OPENBMC_BASE_URI}control/flash/bios
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600384 [Return] ${data['status']}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500385
386Is PNOR Flashing
387 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
388 ... flashing has started.
389 ${status}= Get Flash BIOS Status
Rahul Maheshwari449dfb72017-05-08 02:06:48 -0500390 Should Contain ${status} Flashing
Jay Azurine4c52eb2016-08-16 20:51:10 -0500391
392Is PNOR Flash Done
393 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
394 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000395 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500396 should be equal as strings ${status} Flash Done
397
398Is System State Host Booted
399 [Documentation] Checks whether system state is HOST_BOOTED.
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600400 ${state}= Get BMC State Deprecated
Jay Azurine4c52eb2016-08-16 20:51:10 -0500401 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500402
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600403Is OS Starting
404 [Documentation] Check if boot progress is OS starting.
405 ${boot_progress}= Get Boot Progress
406 Should Be Equal ${boot_progress} FW Progress, Starting OS
407
George Keishing0af24412017-03-10 13:33:23 -0600408Is OS Off
409 [Documentation] Check if boot progress is "Off".
410 ${boot_progress}= Get Boot Progress
411 Should Be Equal ${boot_progress} Off
412
Rahul Maheshwariffd30de2017-06-27 05:57:45 -0500413Get Boot Progress To OS Starting State
414 [Documentation] Get the system to a boot progress state of 'FW Progress,
415 ... Starting OS'.
416
417 ${boot_progress}= Get Boot Progress
418 Run Keyword If '${boot_progress}' == 'FW Progress, Starting OS'
419 ... Log Host is already in OS starting state
420 ... ELSE
421 ... Run Keywords Initiate Host PowerOff AND Initiate Host Boot
422 ... AND Wait Until Keyword Succeeds 10 min 10 sec Is OS Starting
423
George Keishing5e870cd2016-08-24 10:05:47 -0500424Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600425 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500426 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500427 Run Keyword If '${l_ping}' == '${False}'
428 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500429
Michael Walsha6723f22016-11-22 11:12:01 -0600430 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500431 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500432 Run Keyword If '${l_rest}' == '${False}'
433 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500434
435 # Just to make sure the SSH is working for SCP
436 Open Connection And Log In
437 ${system} ${stderr}= Execute Command hostname return_stderr=True
438 Should Be Empty ${stderr}
439
George Keishingc4d3dc02016-09-19 03:45:55 -0500440Check If BMC is Up
441 [Documentation] Wait for Host to be online. Checks every X seconds
442 ... interval for Y minutes and fails if timed out.
443 ... Default MAX timedout is 10 min, interval 10 seconds.
Gunnar Mills38032802016-12-12 13:43:40 -0600444 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500445 ... ${interval}=10 sec
446
447 Wait Until Keyword Succeeds
448 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
449
George Keishingb3700812016-08-31 03:03:30 -0500450
451Check If warmReset is Initiated
452 [Documentation] Ping would be still alive, so try SSH to connect
453 ... if fails the ports are down indicating reboot
454 ... is in progress
George Keishing3c05d352016-12-13 06:54:50 -0600455
456 # Warm reset adds 3 seconds delay before forcing reboot
457 # To minimize race conditions, we wait for 7 seconds
458 Sleep 7s
George Keishingb3700812016-08-31 03:03:30 -0500459 ${alive}= Run Keyword and Return Status
460 ... Open Connection And Log In
461 Return From Keyword If '${alive}' == '${False}' ${False}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600462 [Return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500463
George Keishing06ae4aa2016-08-30 01:41:28 -0500464Flush REST Sessions
465 [Documentation] Removes all the active session objects
466 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500467
Sivas SRRe1143ae2016-08-26 22:31:02 -0500468Initialize DBUS cmd
469 [Documentation] Initialize dbus string with property string to extract
Gunnar Mills38032802016-12-12 13:43:40 -0600470 [Arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600471 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
472 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500473 Set Global Variable ${dbuscmd} ${cmd}
474
David Shawba2d2c22017-01-23 16:56:38 -0600475Create OS Console File Path
476 [Documentation] Create OS console file path name and return it.
477 [Arguments] ${log_file_path}=${EMPTY}
George Keishing30c12ff2016-09-02 10:25:29 -0500478
David Shawba2d2c22017-01-23 16:56:38 -0600479 # Description of arguements:
480 # file_path The caller's candidate value. If this value is ${EMPTY}, this
481 # keyword will compose a file path name. Otherwise, this
482 # keyword will use the caller's file_path value. In either
483 # case, the value will be returned.
Gunnar Mills9c760342016-12-08 10:12:06 -0600484
David Shawba2d2c22017-01-23 16:56:38 -0600485 ${default_file_path}= Catenate /tmp/${OPENBMC_HOST}_os_console
486 ${log_file_path}= Set Variable If '${log_file_path}' == '${EMPTY}'
487 ... ${default_file_path} ${log_file_path}
Michael Walsh01bd3682017-01-10 11:21:05 -0600488
David Shawba2d2c22017-01-23 16:56:38 -0600489 [Return] ${log_file_path}
Gunnar Mills9c760342016-12-08 10:12:06 -0600490
David Shawba2d2c22017-01-23 16:56:38 -0600491Create OS Console Command String
492 [Documentation] Return a command string to start OS console logging.
Gunnar Mills9c760342016-12-08 10:12:06 -0600493
David Shawba2d2c22017-01-23 16:56:38 -0600494 # First make sure that the ssh_pw program is available.
495 ${cmd_buf}= Catenate which ssh_pw 2>&1
496 Rdpissuing ${cmd_buf}
497 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
498 Rdpvars rc output
499 Should Be Equal ${rc} ${0} msg=${output}\n
Gunnar Mills9c760342016-12-08 10:12:06 -0600500
David Shawba2d2c22017-01-23 16:56:38 -0600501 ${cmd_buf}= Catenate ssh_pw ${OPENBMC_PASSWORD} -p 2200
George Keishing1f9ec7f2017-06-06 08:59:19 -0500502 ... -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST}
George Keishing30c12ff2016-09-02 10:25:29 -0500503
David Shawba2d2c22017-01-23 16:56:38 -0600504 [Return] ${cmd_buf}
George Keishing30c12ff2016-09-02 10:25:29 -0500505
506Stop SOL Console Logging
David Shawba2d2c22017-01-23 16:56:38 -0600507 [Documentation] Stop system console logging and return log output.
George Keishing72992e42017-06-16 06:42:36 -0500508 [Arguments] ${log_file_path}=${EMPTY}
509 ... ${targ_file_path}=${EXECDIR}${/}logs${/}
Michael Walsh5f3f4142017-05-22 17:09:47 -0500510 ... ${return_data}=${1}
David Shawba2d2c22017-01-23 16:56:38 -0600511
512 # If there are muliple system console processes, they will all be stopped.
513 # If there is no existing log file this keyword will return an error
514 # message to that effect (and write that message to targ_file_path, if
515 # specified).
516 # NOTE: This keyword will not fail if there is no running system console
517 # process.
Michael Walsh01bd3682017-01-10 11:21:05 -0600518
519 # Description of arguments:
David Shawba2d2c22017-01-23 16:56:38 -0600520 # log_file_path The file path that was used to call "Start SOL
521 # Console Logging". See that keyword (above) for details.
522 # targ_file_path If specified, the file path to which the source
523 # file path (i.e. "log_file_path") should be copied.
Michael Walsh5f3f4142017-05-22 17:09:47 -0500524 # return_data If this is set to ${1}, this keyword will return the SOL
525 # data to the caller as a unicode string.
George Keishing30c12ff2016-09-02 10:25:29 -0500526
David Shawba2d2c22017-01-23 16:56:38 -0600527 ${log_file_path}= Create OS Console File Path ${log_file_path}
528 # Find the pid of the active system console logging session (if any).
529 ${search_string}= Create OS Console Command String
530 ${cmd_buf}= Catenate echo $(ps -ef | egrep '${search_string}'
531 ... | egrep -v grep | cut -c10-14)
532 Rdpissuing ${cmd_buf}
533 ${rc} ${os_con_pid}= Run And Return Rc And Output ${cmd_buf}
534 Rdpvars os_con_pid
535 # If rc is not zero it just means that there is no OS Console process
536 # running.
George Keishing30c12ff2016-09-02 10:25:29 -0500537
David Shawba2d2c22017-01-23 16:56:38 -0600538 ${cmd_buf}= Catenate kill -9 ${os_con_pid}
539 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpissuing ${cmd_buf}
540 ${rc} ${output}= Run Keyword If '${os_con_pid}' != '${EMPTY}'
541 ... Run And Return Rc And Output ${cmd_buf}
542 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpvars rc output
George Keishing30c12ff2016-09-02 10:25:29 -0500543
Michael Walsh01bd3682017-01-10 11:21:05 -0600544 Run Keyword If '${targ_file_path}' != '${EMPTY}'
David Shawba2d2c22017-01-23 16:56:38 -0600545 ... Run Keyword And Ignore Error
546 ... Copy File ${log_file_path} ${targ_file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500547
Michael Walsh5f3f4142017-05-22 17:09:47 -0500548 ${output}= Set Variable ${EMPTY}
549 ${loc_quiet}= Evaluate ${debug}^1
550 ${rc} ${output}= Run Keyword If '${return_data}' == '${1}'
551 ... Cmd Fnc cat ${log_file_path} quiet=${loc_quiet} print_output=${0}
552
David Shawba2d2c22017-01-23 16:56:38 -0600553 [Return] ${output}
554
555Start SOL Console Logging
556 [Documentation] Start system console log to file.
Michael Walsh5f3f4142017-05-22 17:09:47 -0500557 [Arguments] ${log_file_path}=${EMPTY} ${return_data}=${1}
David Shawba2d2c22017-01-23 16:56:38 -0600558
559 # This keyword will first call "Stop SOL Console Logging". Only then will
560 # it start SOL console logging. The data returned by "Stop SOL Console
561 # Logging" will in turn be returned by this keyword.
562
563 # Description of arguments:
Michael Walsh5f3f4142017-05-22 17:09:47 -0500564 # log_file_path The file path to which system console log data should be
565 # written. Note that this path is taken to be a location
566 # on the machine where this program is running rather than
567 # on the Open BMC system.
568 # return_data If this is set to ${1}, this keyword will return any SOL
569 # data to the caller as a unicode string.
David Shawba2d2c22017-01-23 16:56:38 -0600570
571 ${log_file_path}= Create OS Console File Path ${log_file_path}
572
573 ${log_output}= Stop SOL Console Logging ${log_file_path}
Michael Walsh5f3f4142017-05-22 17:09:47 -0500574 ... return_data=${return_data}
David Shawba2d2c22017-01-23 16:56:38 -0600575
576 # Validate by making sure we can create the file. Problems creating the
577 # file would not be noticed by the subsequent ssh command because we fork
578 # the command.
579 Create File ${log_file_path}
580 ${sub_cmd_buf}= Create OS Console Command String
581 # Routing stderr to stdout so that any startup error text will go to the
582 # output file.
583 ${cmd_buf}= Catenate ${sub_cmd_buf} > ${log_file_path} 2>&1 &
584 Rdpissuing ${cmd_buf}
585 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
586 # Because we are forking this command, we essentially will never get a
587 # non-zero return code or any output.
588 Should Be Equal ${rc} ${0}
589
590 [Return] ${log_output}
George Keishing30c12ff2016-09-02 10:25:29 -0500591
592Get Time Stamp
593 [Documentation] Get the current time stamp data
594 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500595 [Return] ${cur_time}
George Keishing30c12ff2016-09-02 10:25:29 -0500596
George Keishing1b150202016-09-29 08:51:58 -0500597
598Verify BMC State
599 [Documentation] Get the BMC state and verify if the current
600 ... BMC state is as expected.
601 [Arguments] ${expected}
602
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600603 ${current}= Get BMC State Deprecated
George Keishing8db0e1b2016-10-20 13:46:54 -0500604 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500605
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500606Start Journal Log
607 [Documentation] Start capturing journal log to a file in /tmp using
608 ... journalctl command. By default journal log is collected
609 ... at /tmp/journal_log else user input location.
610 ... The File is appended with datetime.
611 [Arguments] ${file_path}=/tmp/journal_log
612
613 Open Connection And Log In
614
615 ${cur_time}= Get Time Stamp
616 Set Global Variable ${LOG_TIME} ${cur_time}
617 Start Command
618 ... journalctl -f > ${file_path}-${LOG_TIME}
619 Log Journal Log Started: ${file_path}-${LOG_TIME}
620
David Shawba2d2c22017-01-23 16:56:38 -0600621
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500622Stop Journal Log
623 [Documentation] Stop journalctl process if its running.
624 ... By default return log from /tmp/journal_log else
625 ... user input location.
626 [Arguments] ${file_path}=/tmp/journal_log
627
628 Open Connection And Log In
629
630 ${rc}=
631 ... Execute Command
632 ... ps ax | grep journalctl | grep -v grep
633 ... return_stdout=False return_rc=True
634
635 Return From Keyword If '${rc}' == '${1}'
636 ... No journal log process running
637
638 ${output} ${stderr}=
639 ... Execute Command killall journalctl
640 ... return_stderr=True
641 Should Be Empty ${stderr}
642
643 ${journal_log} ${stderr}=
644 ... Execute Command
645 ... cat ${file_path}-${LOG_TIME}
646 ... return_stderr=True
647 Should Be Empty ${stderr}
648
649 Log ${journal_log}
650
651 Execute Command rm ${file_path}-${LOG_TIME}
652
653 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500654
655Mac Address To Hex String
656 [Documentation] Converts MAC address into hex format.
657 ... Example
658 ... Given the following MAC: 00:01:6C:80:02:78
659 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
660 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600661 ... i_macaddress MAC address in the following format
662 ... 00:01:6C:80:02:78
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500663 [Arguments] ${i_macaddress}
664
665 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600666 [Return] ${mac_hex}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500667
668IP Address To Hex String
669 [Documentation] Converts IP address into hex format.
670 ... Example:
671 ... Given the following IP: 10.3.164.100
672 ... This keyword will return: 0xa 0x3 0xa4 0xa0
673 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600674 ... i_ipaddress IP address in the following format
675 ... 10.10.10.10
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500676 [Arguments] ${i_ipaddress}
677
678 @{ip}= Split String ${i_ipaddress} .
679 ${index}= Set Variable ${0}
680
681 :FOR ${item} IN @{ip}
682 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
683 \ Set List Value ${ip} ${index} ${hex}
684 \ ${index}= Set Variable ${index + 1}
685 ${ip_hex}= Catenate @{ip}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600686 [Return] ${ip_hex}
Sivas SRRea85d1f2016-11-13 22:44:28 -0600687
688BMC CPU Performance Check
689 [Documentation] Minimal 10% of proc should be free in this instance
690
691 ${bmc_cpu_usage_output} ${stderr}= Execute Command ${bmc_cpu_usage_cmd}
692 ... return_stderr=True
693 Should be empty ${stderr}
694 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
695 Should be true ${bmc_cpu_percentage} < 90
696
697BMC Mem Performance Check
698 [Documentation] Minimal 10% of memory should be free in this instance
699
700 ${bmc_mem_free_output} ${stderr}= Execute Command ${bmc_mem_free_cmd}
701 ... return_stderr=True
702 Should be empty ${stderr}
703
704 ${bmc_mem_total_output} ${stderr}= Execute Command ${bmc_mem_total_cmd}
705 ... return_stderr=True
706 Should be empty ${stderr}
707
708 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
709 ${bmc_mem_percentage}= Evaluate
710 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
711 Should be true ${bmc_mem_percentage} > 10
712
Sivas SRRaca55712016-12-21 04:32:35 -0600713BMC File System Usage Check
714 [Documentation] Check the file system space. None should be 100% full
Sivas SRR352bc162017-02-13 22:12:29 -0600715 ... except /run/initramfs/ro
Sivas SRRaca55712016-12-21 04:32:35 -0600716 ${bmc_fs_usage_output} ${stderr}= Execute Command
717 ... ${bmc_file_system_usage_cmd} return_stderr=True
718 Should Be Empty ${stderr}
719 Should Be True ${bmc_fs_usage_output}==0
720
Sivas SRRea85d1f2016-11-13 22:44:28 -0600721Check BMC CPU Performance
722 [Documentation] Minimal 10% of proc should be free in 3 sample
723 :FOR ${var} IN Range 1 4
724 \ BMC CPU Performance check
725
726Check BMC Mem Performance
727 [Documentation] Minimal 10% of memory should be free
728
729 :FOR ${var} IN Range 1 4
730 \ BMC Mem Performance check
731
Sivas SRRaca55712016-12-21 04:32:35 -0600732Check BMC File System Performance
733 [Documentation] Check for file system usage for 4 times
734
735 :FOR ${var} IN Range 1 4
736 \ BMC File System Usage check
737
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500738Get URL List
739 [Documentation] Return list of URLs under given URL.
740 [Arguments] ${openbmc_url}
741 # Description of argument(s):
Michael Walsh5f3f4142017-05-22 17:09:47 -0500742 # openbmc_url URL for list operation (e.g.
743 # /xyz/openbmc_project/inventory).
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500744
George Keishing335f5362017-06-30 15:11:20 -0500745 ${url_list}= Read Properties ${openbmc_url}/list quiet=${1}
George Keishing184a89a2017-06-27 07:12:16 -0500746 Sort List ${url_list}
Rahul Maheshwari63c105b2017-05-12 05:13:52 -0500747 [Return] ${url_list}
748
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600749Get Endpoint Paths
750 [Documentation] Returns all url paths ending with given endpoint
751 ... Example:
752 ... Given the following endpoint: cpu
Michael Walsh01bd3682017-01-10 11:21:05 -0600753 ... This keyword will return: list of all urls ending with
754 ... cpu -
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600755 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0,
756 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1
757 ... Description of arguments:
758 ... path URL path for enumeration
759 ... endpoint string for which url path ending
760 [Arguments] ${path} ${endpoint}
761
762 ${resp}= Read Properties ${path}/enumerate timeout=30
763 log Dictionary ${resp}
764
765 ${list}= Get Dictionary Keys ${resp}
766 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600767 [Return] ${resp}
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500768
769Check Zombie Process
770 [Documentation] Check if any defunct process exist or not on BMC
Michael Walsh01bd3682017-01-10 11:21:05 -0600771 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500772 ... return_stderr=True return_rc=True
773 Should Be True ${count}==0
774 Should Be Empty ${stderr}
George Keishing5327d012016-12-08 08:43:29 -0600775
776Prune Journal Log
777 [Documentation] Prune archived journal logs.
778 [Arguments] ${vacuum_size}=1M
779
780 # This keyword can be used to prevent the journal
781 # log from filling up the /run filesystem.
782 # This command will retain only the latest logs
783 # of the user specified size.
784
785 Open Connection And Log In
786 ${output} ${stderr} ${rc}=
787 ... Execute Command
788 ... journalctl --vacuum-size=${vacuum_size}
789 ... return_stderr=True return_rc=True
790
791 Should Be Equal ${rc} ${0} msg=${stderr}
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600792
793Set BMC Power Policy
794 [Documentation] Set the given BMC power policy.
George Keishingd85b28f2017-08-17 00:31:54 -0500795 [arguments] ${power_restore_uri}=${POWER_RESTORE_URI}
796 ... ${policy_attribute}=PowerRestorePolicy
797 ... ${policy}=${RESTORE_LAST_STATE}
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600798
George Keishing1c3a9662017-08-11 10:16:36 -0500799 # Description of argument(s):
George Keishingd85b28f2017-08-17 00:31:54 -0500800 # power_restore_uri Power restore policy url.
801 # By default "/xyz/openbmc_project/control/host0/power_restore_policy/".
802 # policy Power restore policy.
803 # By default ""xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore".
George Keishing1c3a9662017-08-11 10:16:36 -0500804
805 ${valueDict}= Create Dictionary data=${policy}
806 Write Attribute
George Keishingd85b28f2017-08-17 00:31:54 -0500807 ... ${power_restore_uri} ${policy_attribute} data=${valueDict}
808 ${currentPolicy}=
809 ... Read Attribute ${power_restore_uri} ${policy_attribute}
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600810 Should Be Equal ${currentPolicy} ${policy}
George Keishingcce9df22017-01-24 06:19:33 -0600811
George Keishing4d6f3d62017-02-06 09:50:41 -0600812Get System Power Policy
813 [Documentation] Get the BMC power policy.
George Keishing1c3a9662017-08-11 10:16:36 -0500814 ${currentPolicy}= Read Attribute ${POWER_RESTORE_URI} PowerRestorePolicy
George Keishing4d6f3d62017-02-06 09:50:41 -0600815 [Return] ${currentPolicy}
George Keishingcce9df22017-01-24 06:19:33 -0600816
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600817Get Auto Reboot
818 [Documentation] Returns auto reboot setting.
Sweta Potthuri62a23572017-07-28 04:05:13 -0500819 ${setting}= Read Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600820 [Return] ${setting}
821
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600822Set Auto Reboot
823 [Documentation] Set the given auto reboot setting.
824 [Arguments] ${setting}
Sweta Potthuri62a23572017-07-28 04:05:13 -0500825 # setting auto reboot's setting, i.e. 1 for enabling and 0 for disabling.
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600826
827 ${valueDict}= Set Variable ${setting}
828 ${data}= Create Dictionary data=${valueDict}
Sweta Potthuri62a23572017-07-28 04:05:13 -0500829 Write Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot data=${data}
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600830 ${current_setting}= Get Auto Reboot
Sweta Potthuri62a23572017-07-28 04:05:13 -0500831 Should Be Equal As Integers ${current_setting} ${setting}
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600832
833
George Keishingcce9df22017-01-24 06:19:33 -0600834Set BMC Reset Reference Time
835 [Documentation] Set current boot time as a reference and increment
George Keishing80dd5af2017-02-08 07:01:25 -0600836 ... boot count.
George Keishingcce9df22017-01-24 06:19:33 -0600837
838 ${cur_btime}= Get BMC Boot Time
George Keishing80dd5af2017-02-08 07:01:25 -0600839 Run Keyword If ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
George Keishingcce9df22017-01-24 06:19:33 -0600840 ... Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishing80dd5af2017-02-08 07:01:25 -0600841 ... ELSE IF ${cur_btime} > ${BOOT_TIME}
842 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishingcce9df22017-01-24 06:19:33 -0600843 ... AND
844 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
845
George Keishingcce9df22017-01-24 06:19:33 -0600846Get BMC Boot Time
847 [Documentation] Get boot time from /proc/stat.
848
849 Open Connection And Log In
850 ${output} ${stderr}=
851 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' '
852 ... return_stderr=True
853 Should Be Empty ${stderr}
854 ${btime}= Convert To Integer ${output}
855 [Return] ${btime}
George Keishingede30002017-02-02 09:33:07 -0600856
George Keishingede30002017-02-02 09:33:07 -0600857Execute Command On BMC
858 [Documentation] Execute given command on BMC and return output.
859 [Arguments] ${command}
860 ${stdout} ${stderr}= Execute Command ${command} return_stderr=True
861 Should Be Empty ${stderr}
862 [Return] ${stdout}
David Shawba2d2c22017-01-23 16:56:38 -0600863
Sridevi Rameshea36b412017-03-09 04:08:02 -0600864
George Keishing7a520222017-02-27 09:44:30 -0600865Enable Core Dump On BMC
866 [Documentation] Enable core dump collection.
867 Open Connection And Log In
868 ${core_pattern}= Execute Command On BMC
869 ... echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
870 Should Be Equal As Strings ${core_pattern} /tmp/core_%e.%p
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600871
Sivas SRR01262bd2017-03-19 10:00:23 -0500872Get Number Of BMC Core Dump Files
873 [Documentation] Get number of core dump files on BMC.
874 Open Connection And Log In
875 ${num_of_core_dump}= Execute Command
876 ... ls /tmp/core* 2>/dev/null | wc -l
877 [Return] ${num_of_core_dump}
878
879Set Core Dump File Size Unlimited
880 [Documentation] Set core dump file size to unlimited.
881 Open Connection And Log In
882 Execute Command On BMC
883 ... ulimit -c unlimited
884
885Check For Core Dumps
886 [Documentation] Check for any core dumps exist.
887 ${output}= Get Number Of BMC Core Dump Files
888 Run Keyword If ${output} > 0
889 ... Log **Warning** BMC core dump files exist level=WARN
890
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600891Trigger Host Watchdog Error
George Keishing37cfa6b2017-06-15 10:25:55 -0500892 [Documentation] Inject host watchdog timeout error via REST.
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600893 [Arguments] ${milliseconds}=1000 ${sleep_time}=5s
Michael Walshb5839d02017-04-12 16:11:20 -0500894 # Description of argument(s):
895 # milliseconds The time watchdog timer value in milliseconds (e.g. 1000 =
896 # 1 second).
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600897 # sleep_time Time delay for host watchdog error to get injected.
898 # Default is 5 seconds.
899
George Keishing37cfa6b2017-06-15 10:25:55 -0500900 ${data}= Create Dictionary data=${True}
901 Write Attribute /xyz/openbmc_project/watchdog/host0 Enabled data=${data}
902
903 ${data}= Create Dictionary data=${milliseconds}
904 Write Attribute /xyz/openbmc_project/watchdog/host0 TimeRemaining data=${data}
905
Rahul Maheshwarie95622c2017-02-24 10:04:29 -0600906 Sleep ${sleep_time}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500907
908Login To OS Host
909 [Documentation] Login to OS Host.
910 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
911 ... ${os_password}=${OS_PASSWORD}
912 # Desription of arguments:
913 # ${os_host} IP address of the OS Host.
914 # ${os_username} OS Host Login user name.
915 # ${os_password} OS Host Login passwrd.
916
917 ${os_state}= Run Keyword And Return Status Ping Host ${os_host}
918 Run Keyword If '${os_state}' == 'False'
919 ... Run Keywords Initiate Host Reboot AND
920 ... Is Host Running AND
921 ... Wait for OS ${os_host} ${os_username} ${os_password}
922
George Keishing3f223b82017-06-28 03:50:35 -0500923 SSHLibrary.Open Connection ${os_host}
Sridevi Rameshea36b412017-03-09 04:08:02 -0600924 ${resp}= Login ${os_username} ${os_password}
925 [Return] ${resp}
Prashanth Katti884ee062017-03-16 05:05:03 -0500926
927Configure Initial Settings
928 [Documentation] Restore old IP and route.
929 ... This keyword requires initial settings viz IP address,
930 ... Network Mask, default gatway and serial console IP and port
931 ... information which should be provided in command line.
932
Michael Walshb5839d02017-04-12 16:11:20 -0500933 [Arguments] ${host}=${OPENBMC_HOST} ${mask}=${NET_MASK}
934 ... ${gw_ip}=${GW_IP}
Prashanth Katti884ee062017-03-16 05:05:03 -0500935
Michael Walshb5839d02017-04-12 16:11:20 -0500936 # Open telnet connection and ignore the error, in case telnet session is
937 # already opened by the program calling this keyword.
Prashanth Katti884ee062017-03-16 05:05:03 -0500938
939 Run Keyword And Ignore Error Open Telnet Connection to BMC Serial Console
940 Telnet.write ifconfig eth0 ${host} netmask ${mask}
941 Telnet.write route add default gw ${gw_ip}
George Keishingd05b1082017-03-24 05:27:32 -0500942
943Install Debug Tarball On BMC
George Keishing55441822017-05-18 14:17:59 -0500944 [Documentation] Copy the debug tar file to BMC and install.
945 [Arguments] ${tarball_file_path}=${EXECDIR}/obmc-phosphor-debug-tarball-witherspoon.tar.xz
946 ... ${targ_tarball_dir_path}=/home/root/tarball/
George Keishingd05b1082017-03-24 05:27:32 -0500947
George Keishing55441822017-05-18 14:17:59 -0500948 # Description of arguments:
949 # tarball_file_path Path of the debug tarball file.
950 # The tar file is downloaded from the build page
951 # https://openpower.xyz/job/openbmc-build/
952 # obmc-phosphor-debug-tarball-witherspoon.tar.xz
953 #
954 # targ_tarball_dir_path The directory path where the tarball is to be
955 # installed.
956
957 OperatingSystem.File Should Exist ${tarball_file_path}
958 ... msg=${tarball_file_path} doesn't exist.
959
960 # Upload the file to BMC.
George Keishingd05b1082017-03-24 05:27:32 -0500961 Import Library SCPLibrary WITH NAME scp
962 Open Connection for SCP
George Keishing55441822017-05-18 14:17:59 -0500963 scp.Put File ${tarball_file_path} /tmp/debug-tarball.tar.xz
964
965 # Create tarball directory and install.
George Keishingd05b1082017-03-24 05:27:32 -0500966 Open Connection And Log In
George Keishing55441822017-05-18 14:17:59 -0500967 Execute Command On BMC mkdir -p ${targ_tarball_dir_path}
968 Execute Command On BMC
969 ... tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path}
970
971 # Create symlink to callout-test binary.
972 Execute Command On BMC
973 ... ln -s ${targ_tarball_dir_path}/bin/callout-test /usr/bin/callout-test
974
George Keishing4fc998b2017-05-26 05:24:12 -0500975 # Create symlink to logging-test binary.
976 Execute Command On BMC
977 ... ln -s ${targ_tarball_dir_path}/bin/logging-test /usr/bin/logging-test
978
George Keishingd05b1082017-03-24 05:27:32 -0500979 # Remove the tarball file from BMC
980 Execute Command On BMC rm /tmp/debug-tarball.tar.xz
981
George Keishing55441822017-05-18 14:17:59 -0500982
Sweta Potthuri025e0122017-02-21 00:42:48 -0600983Get BMC Boot Count
984 [Documentation] Get BMC boot count based on boot time.
985 ${cur_btime}= Get BMC Boot Time
986
987 # Set global variable BOOT_TIME to current boot time if current boot time
988 # is changed. Also increase value of global variable BOOT_COUNT by 1.
989 Run Keyword If ${cur_btime} > ${BOOT_TIME}
990 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
991 ... AND
992 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
993 [Return] ${BOOT_COUNT}
994
995Set BMC Boot Count
996 [Documentation] Set BMC boot count to given value.
997 [Arguments] ${count}
998
999 # Description of arguments:
1000 # count boot count value.
1001 ${cur_btime}= Get BMC Boot Time
1002
1003 # Set global variable BOOT_COUNT to given value.
1004 Set Global Variable ${BOOT_COUNT} ${count}
1005
1006 # Set BOOT_TIME variable to current boot time.
1007 Set Global Variable ${BOOT_COUNT} ${count}
Michael Walsh689fbbe2017-04-04 17:58:03 -05001008
Sweta Potthurie5a9fc72017-05-03 07:02:46 -05001009Get System LED State
1010 [Documentation] Return the state of given system LED.
1011 [Arguments] ${led_name}
1012
1013 # Description of argument(s):
1014 # led_name System LED name (e.g. heartbeat, identify, beep).
1015
1016 ${state}= Read Attribute ${LED_PHYSICAL_URI}${led_name} State
1017 [Return] ${state.rsplit('.', 1)[1]}
1018
Michael Walsh689fbbe2017-04-04 17:58:03 -05001019###############################################################################
George Keishingd2d90af2017-06-27 08:17:34 -05001020Delete Error Logs
Michael Walsh689fbbe2017-04-04 17:58:03 -05001021 [Documentation] Delete error logs.
1022
George Keishingd2d90af2017-06-27 08:17:34 -05001023 # Check if error logs entries exist, if not return.
George Keishing335f5362017-06-30 15:11:20 -05001024 ${resp}= OpenBMC Get Request ${BMC_LOGGING_ENTRY}${/}list quiet=${1}
George Keishingd2d90af2017-06-27 08:17:34 -05001025 Return From Keyword If ${resp.status_code} == ${HTTP_NOT_FOUND}
1026
1027 # Get the list of error logs entries and delete them all.
George Keishing335f5362017-06-30 15:11:20 -05001028 ${elog_entries}= Get URL List ${BMC_LOGGING_ENTRY}
George Keishingd2d90af2017-06-27 08:17:34 -05001029 :FOR ${entry} IN @{elog_entries}
1030 \ Delete Error Log Entry ${entry}
George Keishingdb34c2f2017-04-18 13:20:25 -05001031
1032###############################################################################
George Keishingd2d90af2017-06-27 08:17:34 -05001033Delete Error Log Entry
George Keishingdb34c2f2017-04-18 13:20:25 -05001034 [Documentation] Delete error log entry.
1035 [Arguments] ${entry_path}
1036
1037 # Description of argument(s):
1038 # entry_path Delete an error log entry.
1039 # Ex. /xyz/openbmc_project/logging/entry/1
1040
George Keishing6a8ed0f2017-07-11 22:54:42 -05001041 # Skip delete if entry URI is a callout.
1042 # Example: /xyz/openbmc_project/logging/entry/1/callout
1043 Return From Keyword If '${entry_path.rsplit('/', 1)[1]}' == 'callout'
1044
George Keishingdb34c2f2017-04-18 13:20:25 -05001045 ${data}= Create Dictionary data=@{EMPTY}
1046 ${resp}= Openbmc Delete Request ${entry_path} data=${data}
1047 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Rahul Maheshwari43be6932017-05-01 02:37:06 -05001048
1049
George Keishingad5817a2017-06-28 10:19:03 -05001050###############################################################################
Rahul Maheshwari43be6932017-05-01 02:37:06 -05001051Get LED State XYZ
1052 [Documentation] Returns state of given LED.
1053 [Arguments] ${led_name}
1054 # Description of argument(s):
1055 # led_name Name of LED
1056
1057 ${state}= Read Attribute ${LED_GROUPS_URI}${led_name} Asserted
1058 [Return] ${state}
Rahul Maheshwari13256d92017-06-15 10:05:40 -05001059
1060
George Keishingad5817a2017-06-28 10:19:03 -05001061###############################################################################
Rahul Maheshwari13256d92017-06-15 10:05:40 -05001062Get BMC Version
1063 [Documentation] Returns BMC version from /etc/os-release.
1064 ... e.g. "v1.99.6-141-ge662190"
1065
1066 Open Connection And Log In
1067 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
1068 ${output}= Execute Command On BMC ${cmd}
1069 [Return] ${output}
1070
George Keishingad5817a2017-06-28 10:19:03 -05001071
1072###############################################################################
1073Get Elog URL List
1074 [Documentation] Return error log entry list of URLs.
1075
1076 ${url_list}= Read Properties /xyz/openbmc_project/logging/entry/
1077 Sort List ${url_list}
1078 [Return] ${url_list}
1079
1080
1081###############################################################################