blob: 418f2c6ef1af8d5517e8d2295c9d1a293ce605a0 [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
Sivas SRRaca55712016-12-21 04:32:35 -060027# /dev/mtdblock5 filesystem should be 100% full always
28${bmc_file_system_usage_cmd}=
29... df -h | grep -v /dev/mtdblock5 | cut -c 52-54 | grep 100 | wc -l
Chris Austenb29d2e82016-06-07 12:25:35 -050030
George Keishingcce9df22017-01-24 06:19:33 -060031${BOOT_TIME} ${0}
32${BOOT_COUNT} ${0}
33
Chris Austenb29d2e82016-06-07 12:25:35 -050034*** Keywords ***
Sridevi Ramesh1699d372016-12-06 00:20:22 -060035
Chris Austenb29d2e82016-06-07 12:25:35 -050036Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000037 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
38 ... ${interval}=5 sec
39
40 # host The DNS name or IP of the host to ping.
41 # timeout The amount of time after which attempts to ping cease.
42 # interval The amount of time in between attempts to ping.
43
44 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050045
46Ping Host
47 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050048 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060049 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050050 Log RC: ${RC}\nOutput:\n${output}
51 Should be equal ${RC} ${0}
52
53Get Boot Progress
Michael Walsha6723f22016-11-22 11:12:01 -060054 [Arguments] ${quiet}=${QUIET}
55
George Keishing85ca05e2016-11-30 09:47:18 -060056 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress
Michael Walsha6723f22016-11-22 11:12:01 -060057 ... value quiet=${quiet}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060058 [Return] ${state}
Chris Austenb29d2e82016-06-07 12:25:35 -050059
60Is Power On
root442f0ef2016-08-04 20:23:05 +000061 ${state}= Get Power State
62 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050063
64Is Power Off
root442f0ef2016-08-04 20:23:05 +000065 ${state}= Get Power State
66 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050067
root442f0ef2016-08-04 20:23:05 +000068Initiate Power On
69 [Documentation] Initiates the power on and waits until the Is Power On
70 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -060071 [Arguments] ${wait}=${1}
72
Chris Austenb29d2e82016-06-07 12:25:35 -050073 @{arglist}= Create List
74 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -060075 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn
Michael Walsha6723f22016-11-22 11:12:01 -060076 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050077 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -050078
Michael Walsha6723f22016-11-22 11:12:01 -060079 # Does caller want to wait for power on status?
80 Run Keyword If '${wait}' == '${0}' Return From Keyword
81 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -050082
root442f0ef2016-08-04 20:23:05 +000083Initiate Power Off
84 [Documentation] Initiates the power off and waits until the Is Power Off
85 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050086 @{arglist}= Create List
87 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -060088 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff
Michael Walsha6723f22016-11-22 11:12:01 -060089 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050090 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -060091 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -050092
93Trigger Warm Reset
94 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -060095 ${data}= create dictionary data=@{EMPTY}
George Keishing85ca05e2016-11-30 09:47:18 -060096 ${resp}= openbmc post request
97 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -050098 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050099 ${session_active}= Check If warmReset is Initiated
100 Run Keyword If '${session_active}' == '${True}'
101 ... Fail msg=warm reset didn't occur
102
Chris Austenb29d2e82016-06-07 12:25:35 -0500103 Sleep ${SYSTEM_SHUTDOWN_TIME}min
104 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500105
106Check OS
root442f0ef2016-08-04 20:23:05 +0000107 [Documentation] Attempts to ping the host OS and then checks that the host
108 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500109
110 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -0600111 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
112 ... ${print_string}=${EMPTY}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500113 [Teardown] Close Connection
114
115 # os_host The DNS name/IP of the OS host associated with our BMC.
116 # os_username The username to be used to sign on to the OS host.
117 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600118 # quiet Indicates whether this keyword should write to console.
119 # print_string A string to be printed before checking the OS.
120
121 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500122
root442f0ef2016-08-04 20:23:05 +0000123 # Attempt to ping the OS. Store the return code to check later.
124 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
125
Michael Walsh49ab0f42016-07-20 11:44:33 -0500126 Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500127
Michael Walsha6723f22016-11-22 11:12:01 -0600128 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
129 ... ${os_password}
130 ${err_msg1}= Sprint Error ${msg}
131 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
132 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500133 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
134 ... return_rc=True
135
Michael Walsha6723f22016-11-22 11:12:01 -0600136 ${temp_msg}= Catenate Could not execute a command on the operating
137 ... system.\n
138 ${err_msg1}= Sprint Error ${temp_msg}
139 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
140
141 # If the return code returned by "Execute Command" is non-zero, this
142 # keyword will fail.
143 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500144 # We will likewise fail if there is any stderr data.
145 Should Be Empty ${stderr}
146
Michael Walsha6723f22016-11-22 11:12:01 -0600147 ${temp_msg}= Set Variable Could not ping the operating system.\n
148 ${err_msg1}= Sprint Error ${temp_msg}
149 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
150 # We will likewise fail if the OS did not ping, as we could SSH but not
151 # ping
152 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000153
Michael Walsh49ab0f42016-07-20 11:44:33 -0500154Wait for OS
155 [Documentation] Waits for the host OS to come up via calls to "Check OS".
156 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
157 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600158 ... ${quiet}=${0}
159 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500160
161 # os_host The DNS name or IP of the OS host associated with our
162 # BMC.
163 # os_username The username to be used to sign on to the OS host.
164 # os_password The password to be used to sign on to the OS host.
165 # timeout The timeout in seconds indicating how long you're
166 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600167 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500168
169 # The interval to be used between calls to "Check OS".
170 ${interval}= Set Variable 5
171
Michael Walsha6723f22016-11-22 11:12:01 -0600172 ${message}= Catenate Checking every ${interval} seconds for up to
173 ... ${timeout} seconds for the operating system to communicate.
174 rqprint_timen ${message}
175
Michael Walsh49ab0f42016-07-20 11:44:33 -0500176 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
177 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600178 ... print_string=\#
179
180 rqprintn
181
182 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000183
184Get BMC State
185 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600186 [Arguments] ${quiet}=${QUIET}
187
root442f0ef2016-08-04 20:23:05 +0000188 @{arglist}= Create List
189 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600190 ${resp}= Call Method ${OPENBMC_BASE_URI}managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600191 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000192 Should be equal as strings ${resp.status_code} ${HTTP_OK}
193 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600194 [Return] ${content["data"]}
root442f0ef2016-08-04 20:23:05 +0000195
196Get Power State
197 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600198 [Arguments] ${quiet}=${QUIET}
199
root442f0ef2016-08-04 20:23:05 +0000200 @{arglist}= Create List
201 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600202
George Keishing85ca05e2016-11-30 09:47:18 -0600203 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600204 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000205 Should be equal as strings ${resp.status_code} ${HTTP_OK}
206 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600207 [Return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500208
209Clear BMC Record Log
210 [Documentation] Clears all the event logs on the BMC. This would be
211 ... equivalent to ipmitool sel clear.
212 @{arglist}= Create List
213 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600214 ${resp}= Call Method
215 ... ${OPENBMC_BASE_URI}records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500216 should be equal as strings ${resp.status_code} ${HTTP_OK}
217
218Copy PNOR to BMC
219 Import Library SCPLibrary WITH NAME scp
220 Open Connection for SCP
221 Log Copying ${PNOR_IMAGE_PATH} to /tmp
222 scp.Put File ${PNOR_IMAGE_PATH} /tmp
223
224Flash PNOR
225 [Documentation] Calls flash bios update method to flash PNOR image
Gunnar Mills38032802016-12-12 13:43:40 -0600226 [Arguments] ${pnor_image}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500227 @{arglist}= Create List ${pnor_image}
228 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600229 ${resp}= Call Method ${OPENBMC_BASE_URI}control/flash/bios/ update
Michael Walsha6723f22016-11-22 11:12:01 -0600230 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500231 should be equal as strings ${resp.status_code} ${HTTP_OK}
232 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
233
234Get Flash BIOS Status
235 [Documentation] Returns the status of the flash BIOS API as a string. For
236 ... example 'Flashing', 'Flash Done', etc
George Keishing85ca05e2016-11-30 09:47:18 -0600237 ${data}= Read Properties ${OPENBMC_BASE_URI}control/flash/bios
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600238 [Return] ${data['status']}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500239
240Is PNOR Flashing
241 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
242 ... flashing has started.
243 ${status}= Get Flash BIOS Status
244 should be equal as strings ${status} Flashing
245
246Is PNOR Flash Done
247 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
248 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000249 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500250 should be equal as strings ${status} Flash Done
251
252Is System State Host Booted
253 [Documentation] Checks whether system state is HOST_BOOTED.
254 ${state}= Get BMC State
255 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500256
257Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600258 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500259 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500260 Run Keyword If '${l_ping}' == '${False}'
261 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500262
Michael Walsha6723f22016-11-22 11:12:01 -0600263 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500264 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500265 Run Keyword If '${l_rest}' == '${False}'
266 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500267
268 # Just to make sure the SSH is working for SCP
269 Open Connection And Log In
270 ${system} ${stderr}= Execute Command hostname return_stderr=True
271 Should Be Empty ${stderr}
272
George Keishingc4d3dc02016-09-19 03:45:55 -0500273Check If BMC is Up
274 [Documentation] Wait for Host to be online. Checks every X seconds
275 ... interval for Y minutes and fails if timed out.
276 ... Default MAX timedout is 10 min, interval 10 seconds.
Gunnar Mills38032802016-12-12 13:43:40 -0600277 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500278 ... ${interval}=10 sec
279
280 Wait Until Keyword Succeeds
281 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
282
George Keishingb3700812016-08-31 03:03:30 -0500283
284Check If warmReset is Initiated
285 [Documentation] Ping would be still alive, so try SSH to connect
286 ... if fails the ports are down indicating reboot
287 ... is in progress
George Keishing3c05d352016-12-13 06:54:50 -0600288
289 # Warm reset adds 3 seconds delay before forcing reboot
290 # To minimize race conditions, we wait for 7 seconds
291 Sleep 7s
George Keishingb3700812016-08-31 03:03:30 -0500292 ${alive}= Run Keyword and Return Status
293 ... Open Connection And Log In
294 Return From Keyword If '${alive}' == '${False}' ${False}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600295 [Return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500296
George Keishing06ae4aa2016-08-30 01:41:28 -0500297Flush REST Sessions
298 [Documentation] Removes all the active session objects
299 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500300
Sivas SRRe1143ae2016-08-26 22:31:02 -0500301Initialize DBUS cmd
302 [Documentation] Initialize dbus string with property string to extract
Gunnar Mills38032802016-12-12 13:43:40 -0600303 [Arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600304 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
305 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500306 Set Global Variable ${dbuscmd} ${cmd}
307
George Keishing30c12ff2016-09-02 10:25:29 -0500308
Gunnar Mills9c760342016-12-08 10:12:06 -0600309Stop OBMC Console Client
310 [Documentation] Stop any running obmc_console_client
311 ... writing to file_path.
312 [Arguments] ${file_path}=/tmp/obmc-console.log
313
Michael Walsh01bd3682017-01-10 11:21:05 -0600314 ${cmd_buf}= Catenate SEPARATOR=${SPACE}
315 ... ps ax | grep obmc-console-client | grep ${file_path} | grep -v grep
316 ... | awk '{print $1}'
317
Gunnar Mills9c760342016-12-08 10:12:06 -0600318 ${pid}=
Michael Walsh01bd3682017-01-10 11:21:05 -0600319 ... Execute Command ${cmd_buf}
Gunnar Mills9c760342016-12-08 10:12:06 -0600320
321 Run Keyword If '${pid}' != '${EMPTY}'
322 ... Execute Command kill -s KILL ${pid}
323 ... ELSE Log "No obmc-console-client process running"
324
325
George Keishing30c12ff2016-09-02 10:25:29 -0500326Start SOL Console Logging
Gunnar Mills9c760342016-12-08 10:12:06 -0600327 [Documentation] Start a new obmc_console_client process and direct
328 ... output to a file.
329 [Arguments] ${file_path}=/tmp/obmc-console.log
George Keishing30c12ff2016-09-02 10:25:29 -0500330
331 Open Connection And Log In
332
Gunnar Mills9c760342016-12-08 10:12:06 -0600333 Stop OBMC Console Client ${file_path}
334
George Keishing30c12ff2016-09-02 10:25:29 -0500335 Start Command
Gunnar Mills9c760342016-12-08 10:12:06 -0600336 ... obmc-console-client > ${file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500337
338
339Stop SOL Console Logging
Michael Walsh01bd3682017-01-10 11:21:05 -0600340 [Documentation] Stop obmc_console_client process, if any, and
341 ... return the console output as a string.
342 [Arguments] ${file_path}=/tmp/obmc-console.log ${targ_file_path}=${EMPTY}
343
344 # Description of arguments:
345 # file_path The path on the obmc system where SOL output may be
346 # found.
347 # targ_file_path If specified, the file path to which SOL data should be
348 # written.
George Keishing30c12ff2016-09-02 10:25:29 -0500349
350 Open Connection And Log In
351
Gunnar Mills9c760342016-12-08 10:12:06 -0600352 Stop OBMC Console Client ${file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500353
Michael Walsh01bd3682017-01-10 11:21:05 -0600354 ${cmd_buf}= Set Variable cat ${file_path}
355
George Keishing30c12ff2016-09-02 10:25:29 -0500356 ${console} ${stderr}=
357 ... Execute Command
Michael Walsh01bd3682017-01-10 11:21:05 -0600358 ... if [ -f ${file_path} ] ; then cat ${file_path} ; fi
George Keishing30c12ff2016-09-02 10:25:29 -0500359 ... return_stderr=True
Gunnar Mills9c760342016-12-08 10:12:06 -0600360 Should Be Empty ${stderr}
George Keishing30c12ff2016-09-02 10:25:29 -0500361
Michael Walsh01bd3682017-01-10 11:21:05 -0600362 Run Keyword If '${targ_file_path}' != '${EMPTY}'
363 ... Append To File ${targ_file_path} ${console}
George Keishing30c12ff2016-09-02 10:25:29 -0500364
Michael Walsh01bd3682017-01-10 11:21:05 -0600365 [Return] ${console}
George Keishing30c12ff2016-09-02 10:25:29 -0500366
367Get Time Stamp
368 [Documentation] Get the current time stamp data
369 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500370 [Return] ${cur_time}
George Keishing30c12ff2016-09-02 10:25:29 -0500371
George Keishing1b150202016-09-29 08:51:58 -0500372
373Verify BMC State
374 [Documentation] Get the BMC state and verify if the current
375 ... BMC state is as expected.
376 [Arguments] ${expected}
377
378 ${current}= Get BMC State
George Keishing8db0e1b2016-10-20 13:46:54 -0500379 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500380
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500381Start Journal Log
382 [Documentation] Start capturing journal log to a file in /tmp using
383 ... journalctl command. By default journal log is collected
384 ... at /tmp/journal_log else user input location.
385 ... The File is appended with datetime.
386 [Arguments] ${file_path}=/tmp/journal_log
387
388 Open Connection And Log In
389
390 ${cur_time}= Get Time Stamp
391 Set Global Variable ${LOG_TIME} ${cur_time}
392 Start Command
393 ... journalctl -f > ${file_path}-${LOG_TIME}
394 Log Journal Log Started: ${file_path}-${LOG_TIME}
395
396Stop Journal Log
397 [Documentation] Stop journalctl process if its running.
398 ... By default return log from /tmp/journal_log else
399 ... user input location.
400 [Arguments] ${file_path}=/tmp/journal_log
401
402 Open Connection And Log In
403
404 ${rc}=
405 ... Execute Command
406 ... ps ax | grep journalctl | grep -v grep
407 ... return_stdout=False return_rc=True
408
409 Return From Keyword If '${rc}' == '${1}'
410 ... No journal log process running
411
412 ${output} ${stderr}=
413 ... Execute Command killall journalctl
414 ... return_stderr=True
415 Should Be Empty ${stderr}
416
417 ${journal_log} ${stderr}=
418 ... Execute Command
419 ... cat ${file_path}-${LOG_TIME}
420 ... return_stderr=True
421 Should Be Empty ${stderr}
422
423 Log ${journal_log}
424
425 Execute Command rm ${file_path}-${LOG_TIME}
426
427 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500428
429Mac Address To Hex String
430 [Documentation] Converts MAC address into hex format.
431 ... Example
432 ... Given the following MAC: 00:01:6C:80:02:78
433 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
434 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600435 ... i_macaddress MAC address in the following format
436 ... 00:01:6C:80:02:78
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500437 [Arguments] ${i_macaddress}
438
439 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600440 [Return] ${mac_hex}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500441
442IP Address To Hex String
443 [Documentation] Converts IP address into hex format.
444 ... Example:
445 ... Given the following IP: 10.3.164.100
446 ... This keyword will return: 0xa 0x3 0xa4 0xa0
447 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600448 ... i_ipaddress IP address in the following format
449 ... 10.10.10.10
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500450 [Arguments] ${i_ipaddress}
451
452 @{ip}= Split String ${i_ipaddress} .
453 ${index}= Set Variable ${0}
454
455 :FOR ${item} IN @{ip}
456 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
457 \ Set List Value ${ip} ${index} ${hex}
458 \ ${index}= Set Variable ${index + 1}
459 ${ip_hex}= Catenate @{ip}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600460 [Return] ${ip_hex}
Sivas SRRea85d1f2016-11-13 22:44:28 -0600461
462BMC CPU Performance Check
463 [Documentation] Minimal 10% of proc should be free in this instance
464
465 ${bmc_cpu_usage_output} ${stderr}= Execute Command ${bmc_cpu_usage_cmd}
466 ... return_stderr=True
467 Should be empty ${stderr}
468 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
469 Should be true ${bmc_cpu_percentage} < 90
470
471BMC Mem Performance Check
472 [Documentation] Minimal 10% of memory should be free in this instance
473
474 ${bmc_mem_free_output} ${stderr}= Execute Command ${bmc_mem_free_cmd}
475 ... return_stderr=True
476 Should be empty ${stderr}
477
478 ${bmc_mem_total_output} ${stderr}= Execute Command ${bmc_mem_total_cmd}
479 ... return_stderr=True
480 Should be empty ${stderr}
481
482 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
483 ${bmc_mem_percentage}= Evaluate
484 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
485 Should be true ${bmc_mem_percentage} > 10
486
Sivas SRRaca55712016-12-21 04:32:35 -0600487BMC File System Usage Check
488 [Documentation] Check the file system space. None should be 100% full
489 ... except /dev/mtdblock5
490 ${bmc_fs_usage_output} ${stderr}= Execute Command
491 ... ${bmc_file_system_usage_cmd} return_stderr=True
492 Should Be Empty ${stderr}
493 Should Be True ${bmc_fs_usage_output}==0
494
Sivas SRRea85d1f2016-11-13 22:44:28 -0600495Check BMC CPU Performance
496 [Documentation] Minimal 10% of proc should be free in 3 sample
497 :FOR ${var} IN Range 1 4
498 \ BMC CPU Performance check
499
500Check BMC Mem Performance
501 [Documentation] Minimal 10% of memory should be free
502
503 :FOR ${var} IN Range 1 4
504 \ BMC Mem Performance check
505
Sivas SRRaca55712016-12-21 04:32:35 -0600506Check BMC File System Performance
507 [Documentation] Check for file system usage for 4 times
508
509 :FOR ${var} IN Range 1 4
510 \ BMC File System Usage check
511
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600512Get Endpoint Paths
513 [Documentation] Returns all url paths ending with given endpoint
514 ... Example:
515 ... Given the following endpoint: cpu
Michael Walsh01bd3682017-01-10 11:21:05 -0600516 ... This keyword will return: list of all urls ending with
517 ... cpu -
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600518 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0,
519 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1
520 ... Description of arguments:
521 ... path URL path for enumeration
522 ... endpoint string for which url path ending
523 [Arguments] ${path} ${endpoint}
524
525 ${resp}= Read Properties ${path}/enumerate timeout=30
526 log Dictionary ${resp}
527
528 ${list}= Get Dictionary Keys ${resp}
529 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600530 [Return] ${resp}
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500531
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600532
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500533Check Zombie Process
534 [Documentation] Check if any defunct process exist or not on BMC
Michael Walsh01bd3682017-01-10 11:21:05 -0600535 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500536 ... return_stderr=True return_rc=True
537 Should Be True ${count}==0
538 Should Be Empty ${stderr}
George Keishing5327d012016-12-08 08:43:29 -0600539
540Prune Journal Log
541 [Documentation] Prune archived journal logs.
542 [Arguments] ${vacuum_size}=1M
543
544 # This keyword can be used to prevent the journal
545 # log from filling up the /run filesystem.
546 # This command will retain only the latest logs
547 # of the user specified size.
548
549 Open Connection And Log In
550 ${output} ${stderr} ${rc}=
551 ... Execute Command
552 ... journalctl --vacuum-size=${vacuum_size}
553 ... return_stderr=True return_rc=True
554
555 Should Be Equal ${rc} ${0} msg=${stderr}
556 Should Contain ${stderr} Vacuuming done
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600557
558Set BMC Power Policy
559 [Documentation] Set the given BMC power policy.
560 [arguments] ${policy}
561
562 ${valueDict}= create dictionary data=${policy}
563 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
564 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
565 Should Be Equal ${currentPolicy} ${policy}
George Keishingcce9df22017-01-24 06:19:33 -0600566
567
568Set BMC Reset Reference Time
569 [Documentation] Set current boot time as a reference and increment
570 ... boot count.
571
572 ${cur_btime}= Get BMC Boot Time
573 Run Keyword If ${cur_btime} > ${BOOT_TIME}
574 ... Run Keywords
575 ... Set Global Variable ${BOOT_TIME} ${cur_btime}
576 ... AND
577 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
578
579
580Get BMC Boot Time
581 [Documentation] Get boot time from /proc/stat.
582
583 Open Connection And Log In
584 ${output} ${stderr}=
585 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' '
586 ... return_stderr=True
587 Should Be Empty ${stderr}
588 ${btime}= Convert To Integer ${output}
589 [Return] ${btime}