blob: 66b51d65f0cc9566de48945b02950a5793404556 [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
Chris Austenb29d2e82016-06-07 12:25:35 -050010
11*** Variables ***
12${SYSTEM_SHUTDOWN_TIME} ${5}
Michael Walsha6723f22016-11-22 11:12:01 -060013${dbuscmdBase}
George Keishing85ca05e2016-11-30 09:47:18 -060014... dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host
Michael Walsha6723f22016-11-22 11:12:01 -060015${dbuscmdGet}
George Keishing9485af92017-01-04 10:21:43 -060016... ${SETTINGS_URI}host0 org.freedesktop.DBus.Properties.Get
George Keishing85ca05e2016-11-30 09:47:18 -060017# Enable when ready with openbmc/openbmc-test-automation#203
18#${dbuscmdString}= string:"xyz.openbmc_project.settings.Host" string:
Michael Walsha6723f22016-11-22 11:12:01 -060019${dbuscmdString}= string:"org.openbmc.settings.Host" string:
20
21# Assign default value to QUIET for programs which may not define it.
22${QUIET} ${0}
Sivas SRRea85d1f2016-11-13 22:44:28 -060023${bmc_mem_free_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
24${bmc_mem_total_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
25${bmc_cpu_usage_cmd}= top -n 1 | grep CPU: | cut -c 7-9
Sridevi Ramesh1699d372016-12-06 00:20:22 -060026${HOST_SETTING} ${SETTINGS_URI}host0
Chris Austenb29d2e82016-06-07 12:25:35 -050027
28*** Keywords ***
Sridevi Ramesh1699d372016-12-06 00:20:22 -060029
Chris Austenb29d2e82016-06-07 12:25:35 -050030Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000031 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
32 ... ${interval}=5 sec
33
34 # host The DNS name or IP of the host to ping.
35 # timeout The amount of time after which attempts to ping cease.
36 # interval The amount of time in between attempts to ping.
37
38 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050039
40Ping Host
41 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050042 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060043 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050044 Log RC: ${RC}\nOutput:\n${output}
45 Should be equal ${RC} ${0}
46
47Get Boot Progress
Michael Walsha6723f22016-11-22 11:12:01 -060048 [Arguments] ${quiet}=${QUIET}
49
George Keishing85ca05e2016-11-30 09:47:18 -060050 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress
Michael Walsha6723f22016-11-22 11:12:01 -060051 ... value quiet=${quiet}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060052 [Return] ${state}
Chris Austenb29d2e82016-06-07 12:25:35 -050053
54Is Power On
root442f0ef2016-08-04 20:23:05 +000055 ${state}= Get Power State
56 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050057
58Is Power Off
root442f0ef2016-08-04 20:23:05 +000059 ${state}= Get Power State
60 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050061
root442f0ef2016-08-04 20:23:05 +000062Initiate Power On
63 [Documentation] Initiates the power on and waits until the Is Power On
64 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -060065 [Arguments] ${wait}=${1}
66
Chris Austenb29d2e82016-06-07 12:25:35 -050067 @{arglist}= Create List
68 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -060069 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn
Michael Walsha6723f22016-11-22 11:12:01 -060070 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050071 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -050072
Michael Walsha6723f22016-11-22 11:12:01 -060073 # Does caller want to wait for power on status?
74 Run Keyword If '${wait}' == '${0}' Return From Keyword
75 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -050076
root442f0ef2016-08-04 20:23:05 +000077Initiate Power Off
78 [Documentation] Initiates the power off and waits until the Is Power Off
79 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050080 @{arglist}= Create List
81 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -060082 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff
Michael Walsha6723f22016-11-22 11:12:01 -060083 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050084 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -060085 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -050086
87Trigger Warm Reset
88 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -060089 ${data}= create dictionary data=@{EMPTY}
George Keishing85ca05e2016-11-30 09:47:18 -060090 ${resp}= openbmc post request
91 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -050092 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050093 ${session_active}= Check If warmReset is Initiated
94 Run Keyword If '${session_active}' == '${True}'
95 ... Fail msg=warm reset didn't occur
96
Chris Austenb29d2e82016-06-07 12:25:35 -050097 Sleep ${SYSTEM_SHUTDOWN_TIME}min
98 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050099
100Check OS
root442f0ef2016-08-04 20:23:05 +0000101 [Documentation] Attempts to ping the host OS and then checks that the host
102 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500103
104 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -0600105 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
106 ... ${print_string}=${EMPTY}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500107 [Teardown] Close Connection
108
109 # os_host The DNS name/IP of the OS host associated with our BMC.
110 # os_username The username to be used to sign on to the OS host.
111 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600112 # quiet Indicates whether this keyword should write to console.
113 # print_string A string to be printed before checking the OS.
114
115 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500116
root442f0ef2016-08-04 20:23:05 +0000117 # Attempt to ping the OS. Store the return code to check later.
118 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
119
Michael Walsh49ab0f42016-07-20 11:44:33 -0500120 Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500121
Michael Walsha6723f22016-11-22 11:12:01 -0600122 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
123 ... ${os_password}
124 ${err_msg1}= Sprint Error ${msg}
125 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
126 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500127 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
128 ... return_rc=True
129
Michael Walsha6723f22016-11-22 11:12:01 -0600130 ${temp_msg}= Catenate Could not execute a command on the operating
131 ... system.\n
132 ${err_msg1}= Sprint Error ${temp_msg}
133 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
134
135 # If the return code returned by "Execute Command" is non-zero, this
136 # keyword will fail.
137 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500138 # We will likewise fail if there is any stderr data.
139 Should Be Empty ${stderr}
140
Michael Walsha6723f22016-11-22 11:12:01 -0600141 ${temp_msg}= Set Variable Could not ping the operating system.\n
142 ${err_msg1}= Sprint Error ${temp_msg}
143 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
144 # We will likewise fail if the OS did not ping, as we could SSH but not
145 # ping
146 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000147
Michael Walsh49ab0f42016-07-20 11:44:33 -0500148Wait for OS
149 [Documentation] Waits for the host OS to come up via calls to "Check OS".
150 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
151 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600152 ... ${quiet}=${0}
153 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500154
155 # os_host The DNS name or IP of the OS host associated with our
156 # BMC.
157 # os_username The username to be used to sign on to the OS host.
158 # os_password The password to be used to sign on to the OS host.
159 # timeout The timeout in seconds indicating how long you're
160 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600161 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500162
163 # The interval to be used between calls to "Check OS".
164 ${interval}= Set Variable 5
165
Michael Walsha6723f22016-11-22 11:12:01 -0600166 ${message}= Catenate Checking every ${interval} seconds for up to
167 ... ${timeout} seconds for the operating system to communicate.
168 rqprint_timen ${message}
169
Michael Walsh49ab0f42016-07-20 11:44:33 -0500170 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
171 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600172 ... print_string=\#
173
174 rqprintn
175
176 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000177
178Get BMC State
179 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600180 [Arguments] ${quiet}=${QUIET}
181
root442f0ef2016-08-04 20:23:05 +0000182 @{arglist}= Create List
183 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600184 ${resp}= Call Method ${OPENBMC_BASE_URI}managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600185 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000186 Should be equal as strings ${resp.status_code} ${HTTP_OK}
187 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600188 [Return] ${content["data"]}
root442f0ef2016-08-04 20:23:05 +0000189
190Get Power State
191 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600192 [Arguments] ${quiet}=${QUIET}
193
root442f0ef2016-08-04 20:23:05 +0000194 @{arglist}= Create List
195 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600196
George Keishing85ca05e2016-11-30 09:47:18 -0600197 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600198 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000199 Should be equal as strings ${resp.status_code} ${HTTP_OK}
200 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600201 [Return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500202
203Clear BMC Record Log
204 [Documentation] Clears all the event logs on the BMC. This would be
205 ... equivalent to ipmitool sel clear.
206 @{arglist}= Create List
207 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600208 ${resp}= Call Method
209 ... ${OPENBMC_BASE_URI}records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500210 should be equal as strings ${resp.status_code} ${HTTP_OK}
211
212Copy PNOR to BMC
213 Import Library SCPLibrary WITH NAME scp
214 Open Connection for SCP
215 Log Copying ${PNOR_IMAGE_PATH} to /tmp
216 scp.Put File ${PNOR_IMAGE_PATH} /tmp
217
218Flash PNOR
219 [Documentation] Calls flash bios update method to flash PNOR image
Gunnar Mills38032802016-12-12 13:43:40 -0600220 [Arguments] ${pnor_image}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500221 @{arglist}= Create List ${pnor_image}
222 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600223 ${resp}= Call Method ${OPENBMC_BASE_URI}control/flash/bios/ update
Michael Walsha6723f22016-11-22 11:12:01 -0600224 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500225 should be equal as strings ${resp.status_code} ${HTTP_OK}
226 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
227
228Get Flash BIOS Status
229 [Documentation] Returns the status of the flash BIOS API as a string. For
230 ... example 'Flashing', 'Flash Done', etc
George Keishing85ca05e2016-11-30 09:47:18 -0600231 ${data}= Read Properties ${OPENBMC_BASE_URI}control/flash/bios
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600232 [Return] ${data['status']}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500233
234Is PNOR Flashing
235 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
236 ... flashing has started.
237 ${status}= Get Flash BIOS Status
238 should be equal as strings ${status} Flashing
239
240Is PNOR Flash Done
241 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
242 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000243 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500244 should be equal as strings ${status} Flash Done
245
246Is System State Host Booted
247 [Documentation] Checks whether system state is HOST_BOOTED.
248 ${state}= Get BMC State
249 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500250
251Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600252 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500253 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500254 Run Keyword If '${l_ping}' == '${False}'
255 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500256
Michael Walsha6723f22016-11-22 11:12:01 -0600257 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500258 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500259 Run Keyword If '${l_rest}' == '${False}'
260 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500261
262 # Just to make sure the SSH is working for SCP
263 Open Connection And Log In
264 ${system} ${stderr}= Execute Command hostname return_stderr=True
265 Should Be Empty ${stderr}
266
George Keishingc4d3dc02016-09-19 03:45:55 -0500267Check If BMC is Up
268 [Documentation] Wait for Host to be online. Checks every X seconds
269 ... interval for Y minutes and fails if timed out.
270 ... Default MAX timedout is 10 min, interval 10 seconds.
Gunnar Mills38032802016-12-12 13:43:40 -0600271 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500272 ... ${interval}=10 sec
273
274 Wait Until Keyword Succeeds
275 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
276
George Keishingb3700812016-08-31 03:03:30 -0500277
278Check If warmReset is Initiated
279 [Documentation] Ping would be still alive, so try SSH to connect
280 ... if fails the ports are down indicating reboot
281 ... is in progress
George Keishing3c05d352016-12-13 06:54:50 -0600282
283 # Warm reset adds 3 seconds delay before forcing reboot
284 # To minimize race conditions, we wait for 7 seconds
285 Sleep 7s
George Keishingb3700812016-08-31 03:03:30 -0500286 ${alive}= Run Keyword and Return Status
287 ... Open Connection And Log In
288 Return From Keyword If '${alive}' == '${False}' ${False}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600289 [Return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500290
George Keishing06ae4aa2016-08-30 01:41:28 -0500291Flush REST Sessions
292 [Documentation] Removes all the active session objects
293 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500294
Sivas SRRe1143ae2016-08-26 22:31:02 -0500295Initialize DBUS cmd
296 [Documentation] Initialize dbus string with property string to extract
Gunnar Mills38032802016-12-12 13:43:40 -0600297 [Arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600298 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
299 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500300 Set Global Variable ${dbuscmd} ${cmd}
301
George Keishing30c12ff2016-09-02 10:25:29 -0500302
Gunnar Mills9c760342016-12-08 10:12:06 -0600303Stop OBMC Console Client
304 [Documentation] Stop any running obmc_console_client
305 ... writing to file_path.
306 [Arguments] ${file_path}=/tmp/obmc-console.log
307
Michael Walsh01bd3682017-01-10 11:21:05 -0600308 ${cmd_buf}= Catenate SEPARATOR=${SPACE}
309 ... ps ax | grep obmc-console-client | grep ${file_path} | grep -v grep
310 ... | awk '{print $1}'
311
Gunnar Mills9c760342016-12-08 10:12:06 -0600312 ${pid}=
Michael Walsh01bd3682017-01-10 11:21:05 -0600313 ... Execute Command ${cmd_buf}
Gunnar Mills9c760342016-12-08 10:12:06 -0600314
315 Run Keyword If '${pid}' != '${EMPTY}'
316 ... Execute Command kill -s KILL ${pid}
317 ... ELSE Log "No obmc-console-client process running"
318
319
George Keishing30c12ff2016-09-02 10:25:29 -0500320Start SOL Console Logging
Gunnar Mills9c760342016-12-08 10:12:06 -0600321 [Documentation] Start a new obmc_console_client process and direct
322 ... output to a file.
323 [Arguments] ${file_path}=/tmp/obmc-console.log
George Keishing30c12ff2016-09-02 10:25:29 -0500324
325 Open Connection And Log In
326
Gunnar Mills9c760342016-12-08 10:12:06 -0600327 Stop OBMC Console Client ${file_path}
328
George Keishing30c12ff2016-09-02 10:25:29 -0500329 Start Command
Gunnar Mills9c760342016-12-08 10:12:06 -0600330 ... obmc-console-client > ${file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500331
332
333Stop SOL Console Logging
Michael Walsh01bd3682017-01-10 11:21:05 -0600334 [Documentation] Stop obmc_console_client process, if any, and
335 ... return the console output as a string.
336 [Arguments] ${file_path}=/tmp/obmc-console.log ${targ_file_path}=${EMPTY}
337
338 # Description of arguments:
339 # file_path The path on the obmc system where SOL output may be
340 # found.
341 # targ_file_path If specified, the file path to which SOL data should be
342 # written.
George Keishing30c12ff2016-09-02 10:25:29 -0500343
344 Open Connection And Log In
345
Gunnar Mills9c760342016-12-08 10:12:06 -0600346 Stop OBMC Console Client ${file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500347
Michael Walsh01bd3682017-01-10 11:21:05 -0600348 ${cmd_buf}= Set Variable cat ${file_path}
349
George Keishing30c12ff2016-09-02 10:25:29 -0500350 ${console} ${stderr}=
351 ... Execute Command
Michael Walsh01bd3682017-01-10 11:21:05 -0600352 ... if [ -f ${file_path} ] ; then cat ${file_path} ; fi
George Keishing30c12ff2016-09-02 10:25:29 -0500353 ... return_stderr=True
Gunnar Mills9c760342016-12-08 10:12:06 -0600354 Should Be Empty ${stderr}
George Keishing30c12ff2016-09-02 10:25:29 -0500355
Michael Walsh01bd3682017-01-10 11:21:05 -0600356 Run Keyword If '${targ_file_path}' != '${EMPTY}'
357 ... Append To File ${targ_file_path} ${console}
George Keishing30c12ff2016-09-02 10:25:29 -0500358
Michael Walsh01bd3682017-01-10 11:21:05 -0600359 [Return] ${console}
George Keishing30c12ff2016-09-02 10:25:29 -0500360
361Get Time Stamp
362 [Documentation] Get the current time stamp data
363 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500364 [Return] ${cur_time}
George Keishing30c12ff2016-09-02 10:25:29 -0500365
George Keishing1b150202016-09-29 08:51:58 -0500366
367Verify BMC State
368 [Documentation] Get the BMC state and verify if the current
369 ... BMC state is as expected.
370 [Arguments] ${expected}
371
372 ${current}= Get BMC State
George Keishing8db0e1b2016-10-20 13:46:54 -0500373 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500374
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500375Start Journal Log
376 [Documentation] Start capturing journal log to a file in /tmp using
377 ... journalctl command. By default journal log is collected
378 ... at /tmp/journal_log else user input location.
379 ... The File is appended with datetime.
380 [Arguments] ${file_path}=/tmp/journal_log
381
382 Open Connection And Log In
383
384 ${cur_time}= Get Time Stamp
385 Set Global Variable ${LOG_TIME} ${cur_time}
386 Start Command
387 ... journalctl -f > ${file_path}-${LOG_TIME}
388 Log Journal Log Started: ${file_path}-${LOG_TIME}
389
390Stop Journal Log
391 [Documentation] Stop journalctl process if its running.
392 ... By default return log from /tmp/journal_log else
393 ... user input location.
394 [Arguments] ${file_path}=/tmp/journal_log
395
396 Open Connection And Log In
397
398 ${rc}=
399 ... Execute Command
400 ... ps ax | grep journalctl | grep -v grep
401 ... return_stdout=False return_rc=True
402
403 Return From Keyword If '${rc}' == '${1}'
404 ... No journal log process running
405
406 ${output} ${stderr}=
407 ... Execute Command killall journalctl
408 ... return_stderr=True
409 Should Be Empty ${stderr}
410
411 ${journal_log} ${stderr}=
412 ... Execute Command
413 ... cat ${file_path}-${LOG_TIME}
414 ... return_stderr=True
415 Should Be Empty ${stderr}
416
417 Log ${journal_log}
418
419 Execute Command rm ${file_path}-${LOG_TIME}
420
421 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500422
423Mac Address To Hex String
424 [Documentation] Converts MAC address into hex format.
425 ... Example
426 ... Given the following MAC: 00:01:6C:80:02:78
427 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
428 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600429 ... i_macaddress MAC address in the following format
430 ... 00:01:6C:80:02:78
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500431 [Arguments] ${i_macaddress}
432
433 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600434 [Return] ${mac_hex}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500435
436IP Address To Hex String
437 [Documentation] Converts IP address into hex format.
438 ... Example:
439 ... Given the following IP: 10.3.164.100
440 ... This keyword will return: 0xa 0x3 0xa4 0xa0
441 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600442 ... i_ipaddress IP address in the following format
443 ... 10.10.10.10
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500444 [Arguments] ${i_ipaddress}
445
446 @{ip}= Split String ${i_ipaddress} .
447 ${index}= Set Variable ${0}
448
449 :FOR ${item} IN @{ip}
450 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
451 \ Set List Value ${ip} ${index} ${hex}
452 \ ${index}= Set Variable ${index + 1}
453 ${ip_hex}= Catenate @{ip}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600454 [Return] ${ip_hex}
Sivas SRRea85d1f2016-11-13 22:44:28 -0600455
456BMC CPU Performance Check
457 [Documentation] Minimal 10% of proc should be free in this instance
458
459 ${bmc_cpu_usage_output} ${stderr}= Execute Command ${bmc_cpu_usage_cmd}
460 ... return_stderr=True
461 Should be empty ${stderr}
462 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
463 Should be true ${bmc_cpu_percentage} < 90
464
465BMC Mem Performance Check
466 [Documentation] Minimal 10% of memory should be free in this instance
467
468 ${bmc_mem_free_output} ${stderr}= Execute Command ${bmc_mem_free_cmd}
469 ... return_stderr=True
470 Should be empty ${stderr}
471
472 ${bmc_mem_total_output} ${stderr}= Execute Command ${bmc_mem_total_cmd}
473 ... return_stderr=True
474 Should be empty ${stderr}
475
476 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
477 ${bmc_mem_percentage}= Evaluate
478 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
479 Should be true ${bmc_mem_percentage} > 10
480
481Check BMC CPU Performance
482 [Documentation] Minimal 10% of proc should be free in 3 sample
483 :FOR ${var} IN Range 1 4
484 \ BMC CPU Performance check
485
486Check BMC Mem Performance
487 [Documentation] Minimal 10% of memory should be free
488
489 :FOR ${var} IN Range 1 4
490 \ BMC Mem Performance check
491
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600492Get Endpoint Paths
493 [Documentation] Returns all url paths ending with given endpoint
494 ... Example:
495 ... Given the following endpoint: cpu
Michael Walsh01bd3682017-01-10 11:21:05 -0600496 ... This keyword will return: list of all urls ending with
497 ... cpu -
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600498 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0,
499 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1
500 ... Description of arguments:
501 ... path URL path for enumeration
502 ... endpoint string for which url path ending
503 [Arguments] ${path} ${endpoint}
504
505 ${resp}= Read Properties ${path}/enumerate timeout=30
506 log Dictionary ${resp}
507
508 ${list}= Get Dictionary Keys ${resp}
509 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600510 [Return] ${resp}
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500511
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600512
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500513Check Zombie Process
514 [Documentation] Check if any defunct process exist or not on BMC
Michael Walsh01bd3682017-01-10 11:21:05 -0600515 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500516 ... return_stderr=True return_rc=True
517 Should Be True ${count}==0
518 Should Be Empty ${stderr}
George Keishing5327d012016-12-08 08:43:29 -0600519
520Prune Journal Log
521 [Documentation] Prune archived journal logs.
522 [Arguments] ${vacuum_size}=1M
523
524 # This keyword can be used to prevent the journal
525 # log from filling up the /run filesystem.
526 # This command will retain only the latest logs
527 # of the user specified size.
528
529 Open Connection And Log In
530 ${output} ${stderr} ${rc}=
531 ... Execute Command
532 ... journalctl --vacuum-size=${vacuum_size}
533 ... return_stderr=True return_rc=True
534
535 Should Be Equal ${rc} ${0} msg=${stderr}
536 Should Contain ${stderr} Vacuuming done
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600537
538Set BMC Power Policy
539 [Documentation] Set the given BMC power policy.
540 [arguments] ${policy}
541
542 ${valueDict}= create dictionary data=${policy}
543 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
544 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
545 Should Be Equal ${currentPolicy} ${policy}