blob: 9951c49bd1d2990ddfab661886d57b481252f6ea [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 SRR352bc162017-02-13 22:12:29 -060027# /run/initramfs/ro associate filesystem should be 100% full always
Sivas SRRaca55712016-12-21 04:32:35 -060028${bmc_file_system_usage_cmd}=
Sivas SRR352bc162017-02-13 22:12:29 -060029... df -h | grep -v /run/initramfs/ro | 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}
Sivas SRR8254db62017-02-07 09:39:46 -060033${devicetree_base} /sys/firmware/devicetree/base/model
George Keishingcce9df22017-01-24 06:19:33 -060034
Chris Austenb29d2e82016-06-07 12:25:35 -050035*** Keywords ***
Sridevi Ramesh1699d372016-12-06 00:20:22 -060036
Sivas SRR8254db62017-02-07 09:39:46 -060037Get BMC System Model
38 [Documentation] Get the BMC model from the device tree.
39
George Keishing90ab1772017-02-24 05:40:55 -060040 ${bmc_model} ${stderr}= Execute Command
41 ... cat ${devicetree_base} | cut -d " " -f 1 return_stderr=True
Sivas SRR8254db62017-02-07 09:39:46 -060042 Should Be Empty ${stderr}
43 Should Not Be Empty ${bmc_model}
44 [Return] ${bmc_model}
45
46Verify BMC System Model
47 [Documentation] Verify the BMC model with ${OPENBMC_MODEL}.
48 [Arguments] ${bmc_model}
49
50 ${tmp_bmc_model}= Fetch From Right ${OPENBMC_MODEL} /
51 ${tmp_bmc_model}= Fetch From Left ${tmp_bmc_model} .
52 ${ret}= Run Keyword And Return Status Should Contain ${bmc_model}
53 ... ${tmp_bmc_model} ignore_case=True
54 [Return] ${ret}
55
Chris Austenb29d2e82016-06-07 12:25:35 -050056Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000057 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
58 ... ${interval}=5 sec
59
60 # host The DNS name or IP of the host to ping.
61 # timeout The amount of time after which attempts to ping cease.
62 # interval The amount of time in between attempts to ping.
63
64 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050065
66Ping Host
67 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050068 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060069 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050070 Log RC: ${RC}\nOutput:\n${output}
71 Should be equal ${RC} ${0}
72
73Get Boot Progress
Michael Walsha6723f22016-11-22 11:12:01 -060074 [Arguments] ${quiet}=${QUIET}
75
George Keishing85ca05e2016-11-30 09:47:18 -060076 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress
Michael Walsha6723f22016-11-22 11:12:01 -060077 ... value quiet=${quiet}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060078 [Return] ${state}
Chris Austenb29d2e82016-06-07 12:25:35 -050079
80Is Power On
root442f0ef2016-08-04 20:23:05 +000081 ${state}= Get Power State
82 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050083
84Is Power Off
root442f0ef2016-08-04 20:23:05 +000085 ${state}= Get Power State
86 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050087
root442f0ef2016-08-04 20:23:05 +000088Initiate Power On
89 [Documentation] Initiates the power on and waits until the Is Power On
90 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -060091 [Arguments] ${wait}=${1}
92
Chris Austenb29d2e82016-06-07 12:25:35 -050093 @{arglist}= Create List
94 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -060095 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn
Michael Walsha6723f22016-11-22 11:12:01 -060096 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050097 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -050098
Michael Walsha6723f22016-11-22 11:12:01 -060099 # Does caller want to wait for power on status?
100 Run Keyword If '${wait}' == '${0}' Return From Keyword
101 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500102
root442f0ef2016-08-04 20:23:05 +0000103Initiate Power Off
104 [Documentation] Initiates the power off and waits until the Is Power Off
105 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -0500106 @{arglist}= Create List
107 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600108 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff
Michael Walsha6723f22016-11-22 11:12:01 -0600109 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -0500110 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -0600111 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -0500112
Michael Walsh81843772017-03-02 14:44:44 -0600113Initiate OS Host Power Off
114 [Documentation] Initiate an OS reboot.
115 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
116 ... ${os_password}=${OS_PASSWORD}
117
118 # Description of arguments:
119 # os_host The DNS name or IP of the OS.
120 # os_username The username to be used to sign in to the OS.
121 # os_password The password to be used to sign in to the OS.
122
Michael Walshac275512017-03-07 11:39:28 -0600123 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600124 Login ${os_username} ${os_password}
125 ${cmd_buf} Catenate shutdown
126 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600127 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600128
129Initiate OS Host Reboot
130 [Documentation] Initiate an OS reboot.
131 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
132 ... ${os_password}=${OS_PASSWORD}
133
134 # Description of arguments:
135 # os_host The DNS name or IP of the OS.
136 # os_username The username to be used to sign in to the OS.
137 # os_password The password to be used to sign in to the OS.
138
Michael Walshac275512017-03-07 11:39:28 -0600139 SSHLibrary.Open connection ${os_host}
Michael Walsh81843772017-03-02 14:44:44 -0600140 Login ${os_username} ${os_password}
141 ${cmd_buf} Catenate reboot
142 Start Command ${cmd_buf}
Michael Walshac275512017-03-07 11:39:28 -0600143 SSHLibrary.Close Connection
Michael Walsh81843772017-03-02 14:44:44 -0600144
145Initiate Auto Reboot
146 [Documentation] Initiate an auto reboot.
147
148 # Set the auto reboot policy.
149 Set Auto Reboot yes
150
Michael Walshac275512017-03-07 11:39:28 -0600151 SSHLibrary.Open connection ${openbmc_host}
Michael Walsh81843772017-03-02 14:44:44 -0600152 Login ${openbmc_username} ${openbmc_password}
153
154 # Set the watchdog timer. Note: 5000 = milliseconds which is 5 seconds.
155 ${cmd_buf}= Catenate /usr/sbin/mapper call /org/openbmc/watchdog/host0
156 ... org.openbmc.Watchdog set i 5000
157 ${output} ${stderr} ${rc}= Execute Command ${cmd_buf}
158 ... return_stderr=True return_rc=True
159 Should Be Empty ${stderr}
160 Should be equal ${rc} ${0}
161
162 # Start the watchdog.
163 ${cmd_buf}= Catenate /usr/sbin/mapper call /org/openbmc/watchdog/host0
164 ... org.openbmc.Watchdog start
165 ${output} ${stderr} ${rc}= Execute Command ${cmd_buf}
166 ... return_stderr=True return_rc=True
167 Should Be Empty ${stderr}
168 Should be equal ${rc} ${0}
169
Chris Austenb29d2e82016-06-07 12:25:35 -0500170Trigger Warm Reset
171 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -0600172 ${data}= create dictionary data=@{EMPTY}
George Keishing85ca05e2016-11-30 09:47:18 -0600173 ${resp}= openbmc post request
174 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -0500175 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -0500176 ${session_active}= Check If warmReset is Initiated
177 Run Keyword If '${session_active}' == '${True}'
178 ... Fail msg=warm reset didn't occur
179
Chris Austenb29d2e82016-06-07 12:25:35 -0500180 Sleep ${SYSTEM_SHUTDOWN_TIME}min
Rahul Maheshwari5f253c42017-01-30 05:19:51 -0600181 Check If BMC Is Up
Michael Walsh49ab0f42016-07-20 11:44:33 -0500182
183Check OS
root442f0ef2016-08-04 20:23:05 +0000184 [Documentation] Attempts to ping the host OS and then checks that the host
185 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500186
187 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -0600188 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
189 ... ${print_string}=${EMPTY}
Michael Walshac275512017-03-07 11:39:28 -0600190 [Teardown] SSHLibrary.Close Connection
Michael Walsh49ab0f42016-07-20 11:44:33 -0500191
192 # os_host The DNS name/IP of the OS host associated with our BMC.
193 # os_username The username to be used to sign on to the OS host.
194 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600195 # quiet Indicates whether this keyword should write to console.
196 # print_string A string to be printed before checking the OS.
197
198 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500199
root442f0ef2016-08-04 20:23:05 +0000200 # Attempt to ping the OS. Store the return code to check later.
201 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
202
Michael Walshac275512017-03-07 11:39:28 -0600203 SSHLibrary.Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500204
Michael Walsha6723f22016-11-22 11:12:01 -0600205 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
206 ... ${os_password}
207 ${err_msg1}= Sprint Error ${msg}
208 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
209 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500210 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
211 ... return_rc=True
212
Michael Walsha6723f22016-11-22 11:12:01 -0600213 ${temp_msg}= Catenate Could not execute a command on the operating
214 ... system.\n
215 ${err_msg1}= Sprint Error ${temp_msg}
216 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
217
218 # If the return code returned by "Execute Command" is non-zero, this
219 # keyword will fail.
220 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500221 # We will likewise fail if there is any stderr data.
222 Should Be Empty ${stderr}
223
Michael Walsha6723f22016-11-22 11:12:01 -0600224 ${temp_msg}= Set Variable Could not ping the operating system.\n
225 ${err_msg1}= Sprint Error ${temp_msg}
226 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
227 # We will likewise fail if the OS did not ping, as we could SSH but not
228 # ping
229 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000230
Michael Walsh49ab0f42016-07-20 11:44:33 -0500231Wait for OS
232 [Documentation] Waits for the host OS to come up via calls to "Check OS".
233 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
234 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600235 ... ${quiet}=${0}
236 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500237
238 # os_host The DNS name or IP of the OS host associated with our
239 # BMC.
240 # os_username The username to be used to sign on to the OS host.
241 # os_password The password to be used to sign on to the OS host.
242 # timeout The timeout in seconds indicating how long you're
243 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600244 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500245
246 # The interval to be used between calls to "Check OS".
247 ${interval}= Set Variable 5
248
Michael Walsha6723f22016-11-22 11:12:01 -0600249 ${message}= Catenate Checking every ${interval} seconds for up to
250 ... ${timeout} seconds for the operating system to communicate.
251 rqprint_timen ${message}
252
Michael Walsh49ab0f42016-07-20 11:44:33 -0500253 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
254 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600255 ... print_string=\#
256
257 rqprintn
258
259 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000260
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600261Get BMC State Deprecated
root442f0ef2016-08-04 20:23:05 +0000262 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600263 [Arguments] ${quiet}=${QUIET}
264
root442f0ef2016-08-04 20:23:05 +0000265 @{arglist}= Create List
266 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600267 ${resp}= Call Method ${OPENBMC_BASE_URI}managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600268 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000269 Should be equal as strings ${resp.status_code} ${HTTP_OK}
270 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600271 [Return] ${content["data"]}
root442f0ef2016-08-04 20:23:05 +0000272
273Get Power State
274 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600275 [Arguments] ${quiet}=${QUIET}
276
root442f0ef2016-08-04 20:23:05 +0000277 @{arglist}= Create List
278 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600279
George Keishing85ca05e2016-11-30 09:47:18 -0600280 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600281 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000282 Should be equal as strings ${resp.status_code} ${HTTP_OK}
283 ${content}= to json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600284 [Return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500285
286Clear BMC Record Log
287 [Documentation] Clears all the event logs on the BMC. This would be
288 ... equivalent to ipmitool sel clear.
289 @{arglist}= Create List
290 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600291 ${resp}= Call Method
292 ... ${OPENBMC_BASE_URI}records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500293 should be equal as strings ${resp.status_code} ${HTTP_OK}
294
295Copy PNOR to BMC
296 Import Library SCPLibrary WITH NAME scp
297 Open Connection for SCP
298 Log Copying ${PNOR_IMAGE_PATH} to /tmp
299 scp.Put File ${PNOR_IMAGE_PATH} /tmp
300
301Flash PNOR
302 [Documentation] Calls flash bios update method to flash PNOR image
Gunnar Mills38032802016-12-12 13:43:40 -0600303 [Arguments] ${pnor_image}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500304 @{arglist}= Create List ${pnor_image}
305 ${args}= Create Dictionary data=@{arglist}
George Keishing85ca05e2016-11-30 09:47:18 -0600306 ${resp}= Call Method ${OPENBMC_BASE_URI}control/flash/bios/ update
Michael Walsha6723f22016-11-22 11:12:01 -0600307 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500308 should be equal as strings ${resp.status_code} ${HTTP_OK}
309 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
310
311Get Flash BIOS Status
312 [Documentation] Returns the status of the flash BIOS API as a string. For
313 ... example 'Flashing', 'Flash Done', etc
George Keishing85ca05e2016-11-30 09:47:18 -0600314 ${data}= Read Properties ${OPENBMC_BASE_URI}control/flash/bios
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600315 [Return] ${data['status']}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500316
317Is PNOR Flashing
318 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
319 ... flashing has started.
320 ${status}= Get Flash BIOS Status
321 should be equal as strings ${status} Flashing
322
323Is PNOR Flash Done
324 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
325 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000326 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500327 should be equal as strings ${status} Flash Done
328
329Is System State Host Booted
330 [Documentation] Checks whether system state is HOST_BOOTED.
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600331 ${state}= Get BMC State Deprecated
Jay Azurine4c52eb2016-08-16 20:51:10 -0500332 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500333
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600334Is OS Starting
335 [Documentation] Check if boot progress is OS starting.
336 ${boot_progress}= Get Boot Progress
337 Should Be Equal ${boot_progress} FW Progress, Starting OS
338
George Keishing5e870cd2016-08-24 10:05:47 -0500339Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600340 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500341 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500342 Run Keyword If '${l_ping}' == '${False}'
343 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500344
Michael Walsha6723f22016-11-22 11:12:01 -0600345 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500346 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500347 Run Keyword If '${l_rest}' == '${False}'
348 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500349
350 # Just to make sure the SSH is working for SCP
351 Open Connection And Log In
352 ${system} ${stderr}= Execute Command hostname return_stderr=True
353 Should Be Empty ${stderr}
354
George Keishingc4d3dc02016-09-19 03:45:55 -0500355Check If BMC is Up
356 [Documentation] Wait for Host to be online. Checks every X seconds
357 ... interval for Y minutes and fails if timed out.
358 ... Default MAX timedout is 10 min, interval 10 seconds.
Gunnar Mills38032802016-12-12 13:43:40 -0600359 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500360 ... ${interval}=10 sec
361
362 Wait Until Keyword Succeeds
363 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
364
George Keishingb3700812016-08-31 03:03:30 -0500365
366Check If warmReset is Initiated
367 [Documentation] Ping would be still alive, so try SSH to connect
368 ... if fails the ports are down indicating reboot
369 ... is in progress
George Keishing3c05d352016-12-13 06:54:50 -0600370
371 # Warm reset adds 3 seconds delay before forcing reboot
372 # To minimize race conditions, we wait for 7 seconds
373 Sleep 7s
George Keishingb3700812016-08-31 03:03:30 -0500374 ${alive}= Run Keyword and Return Status
375 ... Open Connection And Log In
376 Return From Keyword If '${alive}' == '${False}' ${False}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600377 [Return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500378
George Keishing06ae4aa2016-08-30 01:41:28 -0500379Flush REST Sessions
380 [Documentation] Removes all the active session objects
381 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500382
Sivas SRRe1143ae2016-08-26 22:31:02 -0500383Initialize DBUS cmd
384 [Documentation] Initialize dbus string with property string to extract
Gunnar Mills38032802016-12-12 13:43:40 -0600385 [Arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600386 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
387 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500388 Set Global Variable ${dbuscmd} ${cmd}
389
David Shawba2d2c22017-01-23 16:56:38 -0600390Create OS Console File Path
391 [Documentation] Create OS console file path name and return it.
392 [Arguments] ${log_file_path}=${EMPTY}
George Keishing30c12ff2016-09-02 10:25:29 -0500393
David Shawba2d2c22017-01-23 16:56:38 -0600394 # Description of arguements:
395 # file_path The caller's candidate value. If this value is ${EMPTY}, this
396 # keyword will compose a file path name. Otherwise, this
397 # keyword will use the caller's file_path value. In either
398 # case, the value will be returned.
Gunnar Mills9c760342016-12-08 10:12:06 -0600399
David Shawba2d2c22017-01-23 16:56:38 -0600400 ${default_file_path}= Catenate /tmp/${OPENBMC_HOST}_os_console
401 ${log_file_path}= Set Variable If '${log_file_path}' == '${EMPTY}'
402 ... ${default_file_path} ${log_file_path}
Michael Walsh01bd3682017-01-10 11:21:05 -0600403
David Shawba2d2c22017-01-23 16:56:38 -0600404 [Return] ${log_file_path}
Gunnar Mills9c760342016-12-08 10:12:06 -0600405
David Shawba2d2c22017-01-23 16:56:38 -0600406Create OS Console Command String
407 [Documentation] Return a command string to start OS console logging.
Gunnar Mills9c760342016-12-08 10:12:06 -0600408
David Shawba2d2c22017-01-23 16:56:38 -0600409 # First make sure that the ssh_pw program is available.
410 ${cmd_buf}= Catenate which ssh_pw 2>&1
411 Rdpissuing ${cmd_buf}
412 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
413 Rdpvars rc output
414 Should Be Equal ${rc} ${0} msg=${output}\n
Gunnar Mills9c760342016-12-08 10:12:06 -0600415
David Shawba2d2c22017-01-23 16:56:38 -0600416 ${cmd_buf}= Catenate ssh_pw ${OPENBMC_PASSWORD} -p 2200
417 ... ${OPENBMC_USERNAME}@${OPENBMC_HOST}
George Keishing30c12ff2016-09-02 10:25:29 -0500418
David Shawba2d2c22017-01-23 16:56:38 -0600419 [Return] ${cmd_buf}
George Keishing30c12ff2016-09-02 10:25:29 -0500420
421Stop SOL Console Logging
David Shawba2d2c22017-01-23 16:56:38 -0600422 [Documentation] Stop system console logging and return log output.
423 [Arguments] ${log_file_path}=${EMPTY} ${targ_file_path}=${EMPTY}
424
425 # If there are muliple system console processes, they will all be stopped.
426 # If there is no existing log file this keyword will return an error
427 # message to that effect (and write that message to targ_file_path, if
428 # specified).
429 # NOTE: This keyword will not fail if there is no running system console
430 # process.
Michael Walsh01bd3682017-01-10 11:21:05 -0600431
432 # Description of arguments:
David Shawba2d2c22017-01-23 16:56:38 -0600433 # log_file_path The file path that was used to call "Start SOL
434 # Console Logging". See that keyword (above) for details.
435 # targ_file_path If specified, the file path to which the source
436 # file path (i.e. "log_file_path") should be copied.
George Keishing30c12ff2016-09-02 10:25:29 -0500437
David Shawba2d2c22017-01-23 16:56:38 -0600438 ${log_file_path}= Create OS Console File Path ${log_file_path}
439 # Find the pid of the active system console logging session (if any).
440 ${search_string}= Create OS Console Command String
441 ${cmd_buf}= Catenate echo $(ps -ef | egrep '${search_string}'
442 ... | egrep -v grep | cut -c10-14)
443 Rdpissuing ${cmd_buf}
444 ${rc} ${os_con_pid}= Run And Return Rc And Output ${cmd_buf}
445 Rdpvars os_con_pid
446 # If rc is not zero it just means that there is no OS Console process
447 # running.
George Keishing30c12ff2016-09-02 10:25:29 -0500448
David Shawba2d2c22017-01-23 16:56:38 -0600449 ${cmd_buf}= Catenate kill -9 ${os_con_pid}
450 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpissuing ${cmd_buf}
451 ${rc} ${output}= Run Keyword If '${os_con_pid}' != '${EMPTY}'
452 ... Run And Return Rc And Output ${cmd_buf}
453 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpvars rc output
George Keishing30c12ff2016-09-02 10:25:29 -0500454
David Shawba2d2c22017-01-23 16:56:38 -0600455 ${cmd_buf}= Set Variable cat ${log_file_path} 2>&1
456 Rdpissuing ${cmd_buf}
457 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
458 Rdpvars rc
George Keishing30c12ff2016-09-02 10:25:29 -0500459
Michael Walsh01bd3682017-01-10 11:21:05 -0600460 Run Keyword If '${targ_file_path}' != '${EMPTY}'
David Shawba2d2c22017-01-23 16:56:38 -0600461 ... Run Keyword And Ignore Error
462 ... Copy File ${log_file_path} ${targ_file_path}
George Keishing30c12ff2016-09-02 10:25:29 -0500463
David Shawba2d2c22017-01-23 16:56:38 -0600464 [Return] ${output}
465
466Start SOL Console Logging
467 [Documentation] Start system console log to file.
468 [Arguments] ${log_file_path}=${EMPTY}
469
470 # This keyword will first call "Stop SOL Console Logging". Only then will
471 # it start SOL console logging. The data returned by "Stop SOL Console
472 # Logging" will in turn be returned by this keyword.
473
474 # Description of arguments:
475 # log_file_path The file path to which system console log data should be
476 # written. Note that this path is taken to be a location on
477 # the machine where this program is running rather than on
478 # the Open BMC system.
479
480 ${log_file_path}= Create OS Console File Path ${log_file_path}
481
482 ${log_output}= Stop SOL Console Logging ${log_file_path}
483
484 # Validate by making sure we can create the file. Problems creating the
485 # file would not be noticed by the subsequent ssh command because we fork
486 # the command.
487 Create File ${log_file_path}
488 ${sub_cmd_buf}= Create OS Console Command String
489 # Routing stderr to stdout so that any startup error text will go to the
490 # output file.
491 ${cmd_buf}= Catenate ${sub_cmd_buf} > ${log_file_path} 2>&1 &
492 Rdpissuing ${cmd_buf}
493 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
494 # Because we are forking this command, we essentially will never get a
495 # non-zero return code or any output.
496 Should Be Equal ${rc} ${0}
497
498 [Return] ${log_output}
George Keishing30c12ff2016-09-02 10:25:29 -0500499
500Get Time Stamp
501 [Documentation] Get the current time stamp data
502 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500503 [Return] ${cur_time}
George Keishing30c12ff2016-09-02 10:25:29 -0500504
George Keishing1b150202016-09-29 08:51:58 -0500505
506Verify BMC State
507 [Documentation] Get the BMC state and verify if the current
508 ... BMC state is as expected.
509 [Arguments] ${expected}
510
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600511 ${current}= Get BMC State Deprecated
George Keishing8db0e1b2016-10-20 13:46:54 -0500512 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500513
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500514Start Journal Log
515 [Documentation] Start capturing journal log to a file in /tmp using
516 ... journalctl command. By default journal log is collected
517 ... at /tmp/journal_log else user input location.
518 ... The File is appended with datetime.
519 [Arguments] ${file_path}=/tmp/journal_log
520
521 Open Connection And Log In
522
523 ${cur_time}= Get Time Stamp
524 Set Global Variable ${LOG_TIME} ${cur_time}
525 Start Command
526 ... journalctl -f > ${file_path}-${LOG_TIME}
527 Log Journal Log Started: ${file_path}-${LOG_TIME}
528
David Shawba2d2c22017-01-23 16:56:38 -0600529
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500530Stop Journal Log
531 [Documentation] Stop journalctl process if its running.
532 ... By default return log from /tmp/journal_log else
533 ... user input location.
534 [Arguments] ${file_path}=/tmp/journal_log
535
536 Open Connection And Log In
537
538 ${rc}=
539 ... Execute Command
540 ... ps ax | grep journalctl | grep -v grep
541 ... return_stdout=False return_rc=True
542
543 Return From Keyword If '${rc}' == '${1}'
544 ... No journal log process running
545
546 ${output} ${stderr}=
547 ... Execute Command killall journalctl
548 ... return_stderr=True
549 Should Be Empty ${stderr}
550
551 ${journal_log} ${stderr}=
552 ... Execute Command
553 ... cat ${file_path}-${LOG_TIME}
554 ... return_stderr=True
555 Should Be Empty ${stderr}
556
557 Log ${journal_log}
558
559 Execute Command rm ${file_path}-${LOG_TIME}
560
561 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500562
563Mac Address To Hex String
564 [Documentation] Converts MAC address into hex format.
565 ... Example
566 ... Given the following MAC: 00:01:6C:80:02:78
567 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
568 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600569 ... i_macaddress MAC address in the following format
570 ... 00:01:6C:80:02:78
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500571 [Arguments] ${i_macaddress}
572
573 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600574 [Return] ${mac_hex}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500575
576IP Address To Hex String
577 [Documentation] Converts IP address into hex format.
578 ... Example:
579 ... Given the following IP: 10.3.164.100
580 ... This keyword will return: 0xa 0x3 0xa4 0xa0
581 ... Description of arguments:
Michael Walsh01bd3682017-01-10 11:21:05 -0600582 ... i_ipaddress IP address in the following format
583 ... 10.10.10.10
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500584 [Arguments] ${i_ipaddress}
585
586 @{ip}= Split String ${i_ipaddress} .
587 ${index}= Set Variable ${0}
588
589 :FOR ${item} IN @{ip}
590 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
591 \ Set List Value ${ip} ${index} ${hex}
592 \ ${index}= Set Variable ${index + 1}
593 ${ip_hex}= Catenate @{ip}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600594 [Return] ${ip_hex}
Sivas SRRea85d1f2016-11-13 22:44:28 -0600595
596BMC CPU Performance Check
597 [Documentation] Minimal 10% of proc should be free in this instance
598
599 ${bmc_cpu_usage_output} ${stderr}= Execute Command ${bmc_cpu_usage_cmd}
600 ... return_stderr=True
601 Should be empty ${stderr}
602 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
603 Should be true ${bmc_cpu_percentage} < 90
604
605BMC Mem Performance Check
606 [Documentation] Minimal 10% of memory should be free in this instance
607
608 ${bmc_mem_free_output} ${stderr}= Execute Command ${bmc_mem_free_cmd}
609 ... return_stderr=True
610 Should be empty ${stderr}
611
612 ${bmc_mem_total_output} ${stderr}= Execute Command ${bmc_mem_total_cmd}
613 ... return_stderr=True
614 Should be empty ${stderr}
615
616 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
617 ${bmc_mem_percentage}= Evaluate
618 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
619 Should be true ${bmc_mem_percentage} > 10
620
Sivas SRRaca55712016-12-21 04:32:35 -0600621BMC File System Usage Check
622 [Documentation] Check the file system space. None should be 100% full
Sivas SRR352bc162017-02-13 22:12:29 -0600623 ... except /run/initramfs/ro
Sivas SRRaca55712016-12-21 04:32:35 -0600624 ${bmc_fs_usage_output} ${stderr}= Execute Command
625 ... ${bmc_file_system_usage_cmd} return_stderr=True
626 Should Be Empty ${stderr}
627 Should Be True ${bmc_fs_usage_output}==0
628
Sivas SRRea85d1f2016-11-13 22:44:28 -0600629Check BMC CPU Performance
630 [Documentation] Minimal 10% of proc should be free in 3 sample
631 :FOR ${var} IN Range 1 4
632 \ BMC CPU Performance check
633
634Check BMC Mem Performance
635 [Documentation] Minimal 10% of memory should be free
636
637 :FOR ${var} IN Range 1 4
638 \ BMC Mem Performance check
639
Sivas SRRaca55712016-12-21 04:32:35 -0600640Check BMC File System Performance
641 [Documentation] Check for file system usage for 4 times
642
643 :FOR ${var} IN Range 1 4
644 \ BMC File System Usage check
645
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600646Get Endpoint Paths
647 [Documentation] Returns all url paths ending with given endpoint
648 ... Example:
649 ... Given the following endpoint: cpu
Michael Walsh01bd3682017-01-10 11:21:05 -0600650 ... This keyword will return: list of all urls ending with
651 ... cpu -
Rahul Maheshwari9a8d3b12016-12-05 04:06:16 -0600652 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0,
653 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1
654 ... Description of arguments:
655 ... path URL path for enumeration
656 ... endpoint string for which url path ending
657 [Arguments] ${path} ${endpoint}
658
659 ${resp}= Read Properties ${path}/enumerate timeout=30
660 log Dictionary ${resp}
661
662 ${list}= Get Dictionary Keys ${resp}
663 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600664 [Return] ${resp}
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500665
666Check Zombie Process
667 [Documentation] Check if any defunct process exist or not on BMC
Michael Walsh01bd3682017-01-10 11:21:05 -0600668 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
Sridevi Rameshb96a0c32016-10-19 05:09:52 -0500669 ... return_stderr=True return_rc=True
670 Should Be True ${count}==0
671 Should Be Empty ${stderr}
George Keishing5327d012016-12-08 08:43:29 -0600672
673Prune Journal Log
674 [Documentation] Prune archived journal logs.
675 [Arguments] ${vacuum_size}=1M
676
677 # This keyword can be used to prevent the journal
678 # log from filling up the /run filesystem.
679 # This command will retain only the latest logs
680 # of the user specified size.
681
682 Open Connection And Log In
683 ${output} ${stderr} ${rc}=
684 ... Execute Command
685 ... journalctl --vacuum-size=${vacuum_size}
686 ... return_stderr=True return_rc=True
687
688 Should Be Equal ${rc} ${0} msg=${stderr}
689 Should Contain ${stderr} Vacuuming done
Sridevi Ramesh1699d372016-12-06 00:20:22 -0600690
691Set BMC Power Policy
692 [Documentation] Set the given BMC power policy.
693 [arguments] ${policy}
694
695 ${valueDict}= create dictionary data=${policy}
696 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
697 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
698 Should Be Equal ${currentPolicy} ${policy}
George Keishingcce9df22017-01-24 06:19:33 -0600699
George Keishing4d6f3d62017-02-06 09:50:41 -0600700Get System Power Policy
701 [Documentation] Get the BMC power policy.
702 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
703 [Return] ${currentPolicy}
George Keishingcce9df22017-01-24 06:19:33 -0600704
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600705Get Auto Reboot
706 [Documentation] Returns auto reboot setting.
Michael Walsh81843772017-03-02 14:44:44 -0600707 ${setting}= Read Attribute ${HOST_SETTING} auto_reboot
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600708 [Return] ${setting}
709
710
711Set Auto Reboot
712 [Documentation] Set the given auto reboot setting.
713 [Arguments] ${setting}
714 # setting auto reboot's setting, i.e. yes or no
715
716 ${valueDict}= Set Variable ${setting}
717 ${data}= Create Dictionary data=${valueDict}
Michael Walsh81843772017-03-02 14:44:44 -0600718 Write Attribute ${HOST_SETTING} auto_reboot data=${data}
Rahul Maheshwari1cbf0042017-02-13 05:17:37 -0600719 ${current_setting}= Get Auto Reboot
720 Should Be Equal ${current_setting} ${setting}
721
722
George Keishingcce9df22017-01-24 06:19:33 -0600723Set BMC Reset Reference Time
724 [Documentation] Set current boot time as a reference and increment
George Keishing80dd5af2017-02-08 07:01:25 -0600725 ... boot count.
George Keishingcce9df22017-01-24 06:19:33 -0600726
727 ${cur_btime}= Get BMC Boot Time
George Keishing80dd5af2017-02-08 07:01:25 -0600728 Run Keyword If ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
George Keishingcce9df22017-01-24 06:19:33 -0600729 ... Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishing80dd5af2017-02-08 07:01:25 -0600730 ... ELSE IF ${cur_btime} > ${BOOT_TIME}
731 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
George Keishingcce9df22017-01-24 06:19:33 -0600732 ... AND
733 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
734
George Keishingcce9df22017-01-24 06:19:33 -0600735Get BMC Boot Time
736 [Documentation] Get boot time from /proc/stat.
737
738 Open Connection And Log In
739 ${output} ${stderr}=
740 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' '
741 ... return_stderr=True
742 Should Be Empty ${stderr}
743 ${btime}= Convert To Integer ${output}
744 [Return] ${btime}
George Keishingede30002017-02-02 09:33:07 -0600745
George Keishingede30002017-02-02 09:33:07 -0600746Execute Command On BMC
747 [Documentation] Execute given command on BMC and return output.
748 [Arguments] ${command}
749 ${stdout} ${stderr}= Execute Command ${command} return_stderr=True
750 Should Be Empty ${stderr}
751 [Return] ${stdout}
David Shawba2d2c22017-01-23 16:56:38 -0600752
George Keishing7a520222017-02-27 09:44:30 -0600753Enable Core Dump On BMC
754 [Documentation] Enable core dump collection.
755 Open Connection And Log In
756 ${core_pattern}= Execute Command On BMC
757 ... echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
758 Should Be Equal As Strings ${core_pattern} /tmp/core_%e.%p